resque-metrics 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
@@ -76,9 +76,9 @@ module Resque
76
76
  increment_metric "fork_count:queue:#{queue}"
77
77
  increment_metric "fork_count:job:#{job_class}"
78
78
  end
79
- set_metric "avg_fork_time", total_fork_time / total_fork_count
80
- set_metric "avg_fork_time:queue:#{queue}", total_fork_time_by_queue(queue) / total_fork_count_by_queue(queue)
81
- set_metric "avg_fork_time:job:#{job_class}", total_fork_time_by_job(job_class) / total_fork_count_by_job(job_class)
79
+ set_avg "avg_fork_time", total_fork_time , total_fork_count
80
+ set_avg "avg_fork_time:queue:#{queue}", total_fork_time_by_queue(queue) , total_fork_count_by_queue(queue)
81
+ set_avg "avg_fork_time:job:#{job_class}", total_fork_time_by_job(job_class) , total_fork_count_by_job(job_class)
82
82
  run_callback(:on_job_fork, job_class, queue, time)
83
83
  end
84
84
 
@@ -94,9 +94,9 @@ module Resque
94
94
  increment_metric "payload_size:queue:#{queue}", size
95
95
  increment_metric "payload_size:job:#{job_class}", size
96
96
  end
97
- set_metric "avg_payload_size", total_payload_size / total_enqueue_count
98
- set_metric "avg_payload_size:queue:#{queue}", total_payload_size_by_queue(queue) / total_enqueue_count_by_queue(queue)
99
- set_metric "avg_payload_size:job:#{job_class}", total_payload_size_by_job(job_class) / total_enqueue_count_by_job(job_class)
97
+ set_avg "avg_payload_size", total_payload_size , total_enqueue_count
98
+ set_avg "avg_payload_size:queue:#{queue}", total_payload_size_by_queue(queue) , total_enqueue_count_by_queue(queue)
99
+ set_avg "avg_payload_size:job:#{job_class}", total_payload_size_by_job(job_class) , total_enqueue_count_by_job(job_class)
100
100
  run_callback(:on_job_enqueue, job_class, queue, size)
101
101
  true
102
102
  end
@@ -111,9 +111,9 @@ module Resque
111
111
  increment_metric "job_count:queue:#{queue}"
112
112
  increment_metric "job_count:job:#{job_class}"
113
113
  end
114
- set_metric "avg_job_time", total_job_time / total_job_count
115
- set_metric "avg_job_time:queue:#{queue}", total_job_time_by_queue(queue) / total_job_count_by_queue(queue)
116
- set_metric "avg_job_time:job:#{job_class}", total_job_time_by_job(job_class) / total_job_count_by_job(job_class)
114
+ set_avg "avg_job_time", total_job_time, total_job_count
115
+ set_avg "avg_job_time:queue:#{queue}", total_job_time_by_queue(queue) , total_job_count_by_queue(queue)
116
+ set_avg "avg_job_time:job:#{job_class}", total_job_time_by_job(job_class) , total_job_count_by_job(job_class)
117
117
  run_callback(:on_job_complete, job_class, queue, time)
118
118
  end
119
119
 
@@ -125,6 +125,11 @@ module Resque
125
125
  redis.set("_metrics_:#{metric}", val)
126
126
  end
127
127
 
128
+ def self.set_avg(metric, num, total)
129
+ val = total < 1 ? 0 : num / total
130
+ set_metric(metric, val)
131
+ end
132
+
128
133
  def self.get_metric(metric)
129
134
  redis.get("_metrics_:#{metric}").to_i
130
135
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "resque-metrics"
8
- s.version = "0.0.4"
8
+ s.version = "0.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Aaron Quint"]
12
- s.date = "2012-11-15"
12
+ s.date = "2012-11-28"
13
13
  s.description = "A simple Resque plugin that times and saves some simple metrics for Resque jobs back into redis. Based on this system\nyou could build some simple auto-scaling mechanism based on the speed and ETA of queues. Also includes a hook/callback\nmechanism for recording/sending the metrics to your favorite tool (AKA statsd/graphite).\n"
14
14
  s.email = "aaron@quirkey.com"
15
15
  s.extra_rdoc_files = [
data/test/helper.rb CHANGED
@@ -42,8 +42,8 @@ at_exit do
42
42
 
43
43
  pid = `ps -e -o pid,command | grep [r]edis-test`.split(" ")[0]
44
44
  puts "Killing test redis server..."
45
- `rm -f #{dir}/dump.rdb`
46
45
  Process.kill("KILL", pid.to_i)
46
+ FileUtils.rm_rf("#{dir}/dump.rdb")
47
47
  exit exit_code
48
48
  end
49
49
 
@@ -71,20 +71,6 @@ class TestResqueMetrics < MiniTest::Unit::TestCase
71
71
  assert_equal 2, recorded_count
72
72
  end
73
73
 
74
- def test_should_record_fork_times
75
- Resque::Metrics.watch_fork
76
- Resque.after_fork do |job|
77
- sleep 0.1
78
- Resque::Metrics.after_fork.call(job)
79
- end
80
- work_job
81
- work_job
82
- assert_equal 2, Resque::Metrics.total_fork_count
83
- assert Resque::Metrics.avg_fork_time > 0
84
- assert Resque::Metrics.avg_fork_time_by_queue(:jobs) > 0
85
- assert Resque::Metrics.avg_fork_time_by_job(SomeJob) > 0
86
- end
87
-
88
74
  private
89
75
  def work_job
90
76
  Resque.enqueue(SomeJob, 20, '/tmp')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
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: 2012-11-15 00:00:00.000000000 Z
12
+ date: 2012-11-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: resque
@@ -135,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
135
  version: '0'
136
136
  segments:
137
137
  - 0
138
- hash: 2293482959919047765
138
+ hash: -517852637179208795
139
139
  required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  none: false
141
141
  requirements: