Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions newrelic_resque_agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

The New Relic Resque Plugin enables monitoring of Resque, a library for processing background jobs, reporting the following data for a specified instance:

* Dynamicly monitors all namespaces on redis server OR select only a few.
* Number of working workers
* Pending jobs number
* Total failed jobs number
Expand Down Expand Up @@ -32,6 +33,8 @@ The Resque monitoring Plugin for New Relic requires the following:

3.2. add the Redis connection string: 'hostname:port' or 'hostname:port:db' or 'redis://user:password@hostname:port:db'

3.3 If you would like the plugin to monitor all the namespaces on a particular redis server, set the agent name to "dynamic"

4. Execute

`newrelic_resque_agent run`
Expand Down
49 changes: 49 additions & 0 deletions newrelic_resque_agent/bin/newrelic_resque_agent
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,53 @@ $stdout.sync = true
$LOAD_PATH.unshift File.expand_path "../../lib", __FILE__
require "newrelic_resque_agent"
require 'optparse'
require 'resque'
require 'redis'
require 'yaml'


# Register and run the agent
NewRelic::Plugin::Config.config_file = "/etc/newrelic/newrelic_resque_agent.yml"

def make_dynamic_file
agents = NewRelic::Plugin::Config.config.agents.collect do |agent_key,agent|

if agent_key == "dynamic"

if agent['redis'].nil?
raise "Redis connection URL "
end

Resque.redis = agent['redis']

# get a list of namespaces
if agent['namespace'].nil?
resque_namespaces = Resque.redis.keys("*:queues").map { |key| key.gsub(/:queues$/, '').prepend("resque:") }
else
resque_namespaces = [agent['namespace']].flatten
end


resque_namespaces.each_with_object({}) do |rn, hsh|
clone = agent.clone
clone['namespace'] = rn
rn = rn.match(/resque:(.*):.*/)[1].downcase
hsh[rn] = clone
end

else
{agent_key => agent}
end
end

new_agents = agents.reduce({},:merge)
new_agents.delete('dynamic')
new_config = NewRelic::Plugin::Config.config.options
new_config['agents'] = new_agents
YAML.dump(new_config)
end


options = OptionParser.new do |opts|
opts.banner = <<-EOF
Usage:
Expand Down Expand Up @@ -42,6 +86,11 @@ if args.first == "run"
puts "Run 'sudo newrelic_resque_agent install' for setup config"
exit 1
end

res = make_dynamic_file.to_s
NewRelic::Plugin::Config.config_file = nil
NewRelic::Plugin::Config.config_yaml = res

NewRelicResqueAgent.run
elsif args.first == "install"
config_file = File.read(File.expand_path("../../config/newrelic_plugin.yml.example", __FILE__))
Expand Down
5 changes: 3 additions & 2 deletions newrelic_resque_agent/config/newrelic_plugin.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ newrelic:
verbose: 0
#
# Agent Configuration:
#
# setting the agent name to "dynamic" will make one agent per namespace.

agents:
my_resque_1:
my_resque_1: # <= this agent name could be dynamic
# Redis connection string: 'hostname:port' or 'hostname:port:db' or 'redis://user:password@hostname:port:db'
redis: localhost:6379
# Resque namespace
Expand Down
6 changes: 3 additions & 3 deletions newrelic_resque_agent/lib/newrelic_resque_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

module NewRelicResqueAgent

VERSION = '1.0.1'
VERSION = '1.0.2'

class Agent < NewRelic::Plugin::Agent::Base

Expand Down Expand Up @@ -42,8 +42,8 @@ def poll_cycle
report_metric "Jobs/Rate/Failed", "Jobs/Second", @total_failed.process(info[:failed])
report_metric "Queues", "Queues", info[:queues]
report_metric "Jobs/Failed", "Jobs", info[:failed] || 0



rescue Redis::TimeoutError
raise 'Redis server timeout'
Expand Down
2 changes: 1 addition & 1 deletion newrelic_resque_agent/newrelic_resque_agent.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |s|
## If your rubyforge_project name is different, then edit it and comment out
## the sub! line in the Rakefile
s.name = 'newrelic_resque_agent'
s.version = '1.0.1'
s.version = '1.0.2'
s.date = '2013-07-01'
# s.rubyforge_project = 'newrelic_resque_agent'

Expand Down