Created
January 12, 2012 03:20
-
-
Save auxesis/1598357 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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