resque_statsd 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +1 -1
- data/Readme.md +57 -1
- data/lib/resque/hook.rb +4 -0
- data/lib/resque/plugins/statsd.rb +25 -9
- data/lib/version.rb +1 -1
- metadata +5 -4
data/Gemfile.lock
CHANGED
data/Readme.md
CHANGED
@@ -2,5 +2,61 @@ Resque-Statsd
|
|
2
2
|
==============
|
3
3
|
|
4
4
|
|
5
|
-
A resque plugin that
|
5
|
+
A resque plugin that pushes worker statistics to statsd.
|
6
6
|
|
7
|
+
|
8
|
+
`gem install resque_statsd`
|
9
|
+
|
10
|
+
or
|
11
|
+
|
12
|
+
`gem 'resque_statsd'` in the Gemfile
|
13
|
+
|
14
|
+
|
15
|
+
add the following to your resque workers
|
16
|
+
|
17
|
+
`extend Resque::Plugins::Statsd`
|
18
|
+
|
19
|
+
By default this would send it to the statsd that has been configured.
|
20
|
+
|
21
|
+
This will by default do the following
|
22
|
+
|
23
|
+
* total_resque_failures
|
24
|
+
* total_resque_failures:<WorkerName>
|
25
|
+
* total_enqueues
|
26
|
+
* total_enqueues:<WorkerName>
|
27
|
+
* total_dequeues
|
28
|
+
* total_dequeues:<WorkerName>
|
29
|
+
* total_successful
|
30
|
+
* total_successful:<WorkerName>
|
31
|
+
* duration:<WorkerName>
|
32
|
+
|
33
|
+
Customizations.
|
34
|
+
===============
|
35
|
+
|
36
|
+
By adding something like this
|
37
|
+
|
38
|
+
`@extra_stats_key = {:duration => [:hostname, :queuename]}`
|
39
|
+
|
40
|
+
This will also add the duration:<hostname> as a stat
|
41
|
+
This will also add the duration:<queue> as a stat
|
42
|
+
|
43
|
+
Following default tasks are available
|
44
|
+
* queuename - Name of the queue on which this task was picked up
|
45
|
+
* hostname - Name of the machine on which the task was executed
|
46
|
+
* classname - The default. Name of the worker that was executed.
|
47
|
+
|
48
|
+
More Customizations
|
49
|
+
=======
|
50
|
+
|
51
|
+
`@extra_stats_key = {:failure => Proc.new {|e, args| e.to_s}}`
|
52
|
+
|
53
|
+
This will add a stat key for
|
54
|
+
|
55
|
+
total_resque_failures:<Exception>
|
56
|
+
|
57
|
+
Following hooks are available
|
58
|
+
* failure
|
59
|
+
* duration
|
60
|
+
* enqueue
|
61
|
+
* dequeue
|
62
|
+
* fork
|
data/lib/resque/hook.rb
ADDED
@@ -1,9 +1,10 @@
|
|
1
|
+
require File.expand_path('../../hook', __FILE__)
|
1
2
|
module Resque
|
2
3
|
module Plugins
|
3
4
|
module Statsd
|
4
5
|
DEFAULT_TASKS = {
|
5
6
|
:hostname => Proc.new{ @stat_hostname ||= `hostname`.strip},
|
6
|
-
:classname => Proc.new {self
|
7
|
+
:classname => Proc.new {self},
|
7
8
|
:queuename => Proc.new {|args| @queue}
|
8
9
|
}
|
9
10
|
def statsd
|
@@ -23,29 +24,44 @@ module Resque
|
|
23
24
|
statsd.timing("duration:#{self}", time_taken)
|
24
25
|
statsd.increment("total_successful:#{self}")
|
25
26
|
statsd.increment("total_successful")
|
26
|
-
|
27
|
-
Array(extra_stats_key[:around_perform]).each { |item| statsd.timing("duration:#{DEFAULT_TASKS[item].call(args)}", time_taken)}
|
28
|
-
end
|
27
|
+
run_hooks(:duration, :duration, args) {|key| statsd.timing(key, time_taken)}
|
29
28
|
end
|
30
29
|
|
31
30
|
def on_failure_stats(*args)
|
32
31
|
statsd.increment("total_resque_failures")
|
33
32
|
statsd.increment("total_resque_failures:#{self}")
|
33
|
+
run_hooks(:failure, :total_resque_failures, args){|key| statsd.increment(key)}
|
34
34
|
end
|
35
35
|
|
36
36
|
def after_enqueue_stats(*args)
|
37
|
-
statsd.increment("
|
38
|
-
statsd.increment("
|
37
|
+
statsd.increment("total_resque_enqueues")
|
38
|
+
statsd.increment("total_resque_enqueues:#{self}")
|
39
|
+
run_hooks(:enqueue, :total_enqueues, args){|key| statsd.increment(key)}
|
39
40
|
end
|
40
41
|
|
41
42
|
def after_dequeue_stats(*args)
|
42
|
-
statsd.increment("
|
43
|
-
statsd.increment("
|
43
|
+
statsd.increment("total__resque_dequeues")
|
44
|
+
statsd.increment("total__resque_dequeues:#{self}")
|
45
|
+
run_hooks(:dequeue, :total_dequeues, args) {|key| statsd.increment(key)}
|
44
46
|
end
|
45
|
-
|
47
|
+
|
46
48
|
def extra_stats_key
|
47
49
|
@extra_stats_key ||= {}
|
48
50
|
end
|
51
|
+
|
52
|
+
def run_hooks(type, key, args = nil)
|
53
|
+
Array(extra_stats_key[type]).each do |item|
|
54
|
+
begin
|
55
|
+
res = "#{key}:#{Resque::Plugins::Statsd::DEFAULT_TASKS[item].call(args)}"
|
56
|
+
puts "**********************************************"
|
57
|
+
puts res
|
58
|
+
puts "**********************************************"
|
59
|
+
rescue
|
60
|
+
puts "#{$!}" # Don't throw up if bad stuff happened, like the proc not being there.
|
61
|
+
end
|
62
|
+
yield(res) if res
|
63
|
+
end
|
64
|
+
end
|
49
65
|
end
|
50
66
|
end
|
51
67
|
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque_statsd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: statsd
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- Gemfile.lock
|
105
105
|
- Rakefile
|
106
106
|
- Readme.md
|
107
|
+
- lib/resque/hook.rb
|
107
108
|
- lib/resque/plugins/statsd.rb
|
108
109
|
- lib/resque_statsd.rb
|
109
110
|
- lib/version.rb
|
@@ -122,7 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
122
123
|
version: '0'
|
123
124
|
segments:
|
124
125
|
- 0
|
125
|
-
hash:
|
126
|
+
hash: -293280983815071814
|
126
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
128
|
none: false
|
128
129
|
requirements:
|
@@ -131,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
132
|
version: '0'
|
132
133
|
segments:
|
133
134
|
- 0
|
134
|
-
hash:
|
135
|
+
hash: -293280983815071814
|
135
136
|
requirements: []
|
136
137
|
rubyforge_project: resque_statsd
|
137
138
|
rubygems_version: 1.8.24
|