Sha256: 051e0d3e19fd4c522512652e00f8e2333e38caa65a69a9588c4a349b3856d7a2

Contents?: true

Size: 1.04 KB

Versions: 7

Compression:

Stored size: 1.04 KB

Contents

#!/usr/bin/env ruby

lib = File.expand_path('../../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

require 'hallmonitor'
require 'hallmonitor/outputters/iooutputter'
require 'hallmonitor/outputters/statsd_outputter'
require 'pry'

Hallmonitor.add_outputter Hallmonitor::Outputters::IOOutputter.new("STDOUT", STDOUT)
Hallmonitor.add_outputter Hallmonitor::Outputters::StatsdOutputter.new("example", "localhost")

class Foo
  include Hallmonitor::Monitored

  def do_something
    sleep_time_ms = ((Random.rand * 100).floor) * 2
    puts "Sleeping for #{sleep_time_ms} milliseconds"
    sleep(sleep_time_ms / 1000.0)
  end
  timer_for :do_something
  count_for :do_something

  def emit_events(count=30)
    # Emit 100 events
    count.times do
      emit("event")
      sleep(1)
    end
  end

  def time_me
    watch("timed") do |x|
      sleep(5)
    end
  end
end

f = Foo.new

puts 'Calling method with timer_for and count_for...'
f.do_something

puts 'Emitting some events'
f.emit_events(5)

puts 'Timing a 5 second block'
f.time_me

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hallmonitor-4.2.0 bin/example.rb
hallmonitor-4.1.0 bin/example.rb
hallmonitor-4.0.0 bin/example.rb
hallmonitor-3.0.0 bin/example.rb
hallmonitor-2.0.0 bin/example.rb
hallmonitor-1.1.0 bin/example.rb
hallmonitor-1.0.0 bin/example.rb