Sha256: fb3e9d83c23156a513b788b4fa9426c5627e2db3c05a67006869cb33ffc39481

Contents?: true

Size: 1.37 KB

Versions: 27

Compression:

Stored size: 1.37 KB

Contents

#!/usr/bin/env ruby

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

require 'rubygems'
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 = %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

  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
      tick
    end
  end

  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
end

Riemann::Bench.new.run

Version data entries

27 entries across 27 versions & 4 rubygems

Version Path
riemann-tools-0.2.14 bin/riemann-bench
riemann-tools-0.2.13 bin/riemann-bench
riemann-tools-0.2.11 bin/riemann-bench
riemann-tools-0.2.10 bin/riemann-bench
riemann-tools-0.2.9 bin/riemann-bench
riemann-tools-0.2.8 bin/riemann-bench
riemann-tools-0.2.7 bin/riemann-bench
riemann-tools-0.2.6 bin/riemann-bench
riemann-tools-0.2.5 bin/riemann-bench
riemann-tools-0.2.4 bin/riemann-bench
riemann-tools-fb-0.3.0 bin/riemann-bench
riemann-tools-0.2.3 bin/riemann-bench
riemann-tools-dgvz-0.2.2.3 bin/riemann-bench
riemann-tools-dgvz-0.2.2.2 bin/riemann-bench
riemann-tools-dgvz-0.2.2.1 bin/riemann-bench
riemann-tools-0.2.2 bin/riemann-bench
riemann-tools-0.2.1 bin/riemann-bench
riemann-tools-0.2.0 bin/riemann-bench
riemann-tools-0.1.9 bin/riemann-bench
riemann-tools.haf-0.1.9 bin/riemann-bench