Skip to content

Instantly share code, notes, and snippets.

@auxesis
Created January 12, 2012 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save auxesis/1598357 to your computer and use it in GitHub Desktop.
Save auxesis/1598357 to your computer and use it in GitHub Desktop.
#!/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
#!/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)
#!/usr/bin/env ruby
source :rubygems
gem "newrelic_rpm"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment