public
Created

  • Download Gist
Gemfile
Ruby
1 2 3 4 5
#!/usr/bin/env ruby
 
source :rubygems
 
gem "newrelic_rpm"
check.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
#!/usr/bin/env ruby
#
# Usage: check.rb <time>
#
 
require 'rubygems'
require 'bundler/setup'
require 'newrelic_rpm'
 
class Check
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
 
attr_reader :opts
 
def initialize(opts={})
@opts = opts
end
 
def model(opts={})
i = opts[:time]
sleep(i)
raise [Exception, RuntimeError, StandardError][rand(2)] if rand(i) == 1
return i
end
 
def view(data)
i = data
sleep(rand(i) / 5)
raise [Exception, RuntimeError, ArgumentError][rand(2)] if rand(i) == 2
 
puts "OK: we made it!"
end
 
def run
data = model(@opts)
view(data)
end
 
add_transaction_tracer :run, :name => 'run', :class_name => '#{self.class}', :params => 'self.opts'
add_method_tracer :model, 'Nagios/#{self.class.name}/model'
add_method_tracer :view, 'Nagios/#{self.class.name}/view'
newrelic_ignore_apdex
end
 
at_exit do
puts "Saving New Relic data"
NewRelic::Agent.save_data
end
 
NewRelic::Agent.manual_start
Check.new(:time => ARGV[0].to_i).run
collector.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#!/usr/bin/env ruby
#
# Usage: collector.rb
#
 
require 'rubygems'
require 'bundler/setup'
require 'newrelic_rpm'
 
module NewRelic
module Agent
def self.connected?
agent.connected?
end
end
end
 
$stdout.sync = true
NewRelic::Agent.manual_start
 
print "Waiting to connect to NewRelic Service"
until NewRelic::Agent.connected? do
print '.'
sleep 1
end
puts
 
NewRelic::Agent.load_data
NewRelic::Agent.shutdown(:force_send => true)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.