Sha256: 4eb2fda655f0592ee47229ce3cdb43f6eef9bd070b90549cc492293837a803b8

Contents?: true

Size: 1.2 KB

Versions: 8

Compression:

Stored size: 1.2 KB

Contents

#!/usr/bin/env ruby

# Connects to a server (first arg) and populates it with a constant stream of
# events for testing.

require 'riemann/client'
require 'pp'

class Riemann::Bench
  attr_accessor :client, :hosts, :services, :states
  def initialize
    @hosts = [nil] + (0...10).map { |i| "host#{i}" }
    @hosts = ['test']
    @services = %w(per)
    @states = {}
    @client = Riemann::Client.new(host: (ARGV.first || 'localhost'))
  end

  def evolve(state)
    m = rand
    s = case m
    when 0...0.75
      'ok'
    when 0.75...0.9
      'warning'
    when 0.9..1.0
      'critical'
    end

    {
      metric_f: 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.01
      tick
    end
  end

  def start
    hosts.product(services).each do |host, service|
      states[[host, service]] = {
        metric_f: 0.5,
        state: 'ok',
        description: "Starting up",
        host: host,
        service: service
      }
    end
  end
end

Riemann::Bench.new.run

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
riemann-tools-0.0.8 bin/riemann-bench
riemann-tools-0.0.7 bin/riemann-bench
riemann-tools-0.0.6 bin/riemann-bench
riemann-tools-0.0.5 bin/riemann-bench
riemann-tools-0.0.4 bin/riemann-bench
riemann-tools-0.0.3 bin/riemann-bench
riemann-tools-0.0.2 bin/riemann-bench
riemann-tools-0.0.1 bin/riemann-bench