Class: Riemann::Tools::Bench
- Inherits:
-
Object
- Object
- Riemann::Tools::Bench
- Defined in:
- lib/riemann/tools/bench.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#hosts ⇒ Object
Returns the value of attribute hosts.
-
#services ⇒ Object
Returns the value of attribute services.
-
#states ⇒ Object
Returns the value of attribute states.
Instance Method Summary collapse
- #evolve(state) ⇒ Object
-
#initialize ⇒ Bench
constructor
A new instance of Bench.
- #run ⇒ Object
- #start ⇒ Object
- #tick ⇒ Object
Constructor Details
#initialize ⇒ Bench
Returns a new instance of Bench.
13 14 15 16 17 18 19 20 21 |
# File 'lib/riemann/tools/bench.rb', line 13 def initialize super @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 |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
11 12 13 |
# File 'lib/riemann/tools/bench.rb', line 11 def client @client end |
#hosts ⇒ Object
Returns the value of attribute hosts.
11 12 13 |
# File 'lib/riemann/tools/bench.rb', line 11 def hosts @hosts end |
#services ⇒ Object
Returns the value of attribute services.
11 12 13 |
# File 'lib/riemann/tools/bench.rb', line 11 def services @services end |
#states ⇒ Object
Returns the value of attribute states.
11 12 13 |
# File 'lib/riemann/tools/bench.rb', line 11 def states @states end |
Instance Method Details
#evolve(state) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/riemann/tools/bench.rb', line 23 def evolve(state) m = state[:metric] + ((rand - 0.5) * 0.1) m = m.clamp(0, 1) 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 ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/riemann/tools/bench.rb', line 52 def run start loop do sleep 0.05 tick end end |
#start ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/riemann/tools/bench.rb', line 60 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 ⇒ Object
45 46 47 48 49 50 |
# File 'lib/riemann/tools/bench.rb', line 45 def tick # pp @states hosts.product(services).each do |id| client << (states[id] = evolve(states[id])) end end |