class Riemann::Tools::Bench
Attributes
client[RW]
hosts[RW]
services[RW]
states[RW]
Public Class Methods
new()
click to toggle source
# File lib/riemann/tools/bench.rb, line 13 def initialize @hosts = [nil] + (0...10).map { |i| "host#{i}" } @hosts = %w[a b c d e f g h i j] @services = %w[test1 test2 test3 foo bar baz xyzzy attack cat treat] @states = {} @client = Riemann::Client.new(host: (ARGV.first || 'localhost')) end
Public Instance Methods
evolve(state)
click to toggle source
# File lib/riemann/tools/bench.rb, line 21 def evolve(state) m = state[:metric] + (rand - 0.5) * 0.1 m = [[0, m].max, 1].min s = case m when 0...0.75 'ok' when 0.75...0.9 'warning' when 0.9..1.0 'critical' end { metric: m, state: s, host: state[:host], service: state[:service], description: "at #{Time.now}", } end
run()
click to toggle source
# File lib/riemann/tools/bench.rb, line 50 def run start loop do sleep 0.05 tick end end
start()
click to toggle source
# File lib/riemann/tools/bench.rb, line 58 def start hosts.product(services).each do |host, service| states[[host, service]] = { metric: 0.5, state: 'ok', description: 'Starting up', host: host, service: service, } end end
tick()
click to toggle source
# File lib/riemann/tools/bench.rb, line 43 def tick # pp @states hosts.product(services).each do |id| client << (states[id] = evolve(states[id])) end end