Created
February 2, 2014 08:16
-
-
Save l1x/8764658 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Riemann::Bench | |
attr_accessor :client, :hosts, :services, :states | |
def initialize | |
@hosts = [nil] + (0...100).map { |i| "host#{i}" } | |
@services = %w(test1 test2 test3 foo bar baz xyzzy attack cat treat) | |
@states = {} | |
@client = Riemann::Client.new(:host => (ARGV.first || 'localhost')) | |
end | |
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 | |
def tick | |
# pp @states | |
hosts.product(services).each do |id| | |
client << (states[id] = evolve(states[id])) | |
end | |
end | |
def run | |
start | |
loop do | |
sleep 0.05 | |
puts "tick" | |
tick | |
end | |
end | |
def start | |
hosts.product(services).each do |host, service| | |
puts host | |
puts service | |
states[[host, service]] = { | |
:metric => 0.5, | |
:state => 'ok', | |
:description => "Starting up", | |
:host => host, | |
:service => service | |
} | |
end | |
end | |
end | |
Riemann::Bench.new.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment