resque-cloudwatch-monitor 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +3 -0
- data/lib/resque/plugins/cloudwatch-monitor/cloudwatch-monitor.rb +27 -9
- data/lib/resque/plugins/cloudwatch-monitor/configuration.rb +12 -12
- data/lib/resque/plugins/cloudwatch-monitor/version.rb +5 -5
- data/resque-cloudwatch-monitor.gemspec +2 -2
- data/spec/cloudwatch_monitor_spec.rb +8 -2
- data/spec/spec_helper.rb +7 -3
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODQ4YjM3MGE0ZTNhNDgwYTY3YzRiYjExNmU2NWIxZDE3YTZiMTkzZg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MzIzOTE1ODVlN2VhYTJhY2VkNzIyNWI4YTE3ZTZhZWI4YWU1Mzg4MA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Y2IwNzBmMGQ5NGZmMTNiZjg1NDFkODgwZTdlZTNlYzI0MzdmZmM3ZjY1MGVl
|
10
|
+
OTNjNGVjMzM5NjczMmQ5NzFjYTQ4YWRjM2M1ZDViMjNkNTVlMDFlN2JhYmQy
|
11
|
+
YTU4Y2ZjNDBkNjgyODZhYzc0NTFiY2I0ZjhlZWIzZTE2M2RiOTg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTg0NTU3ZTUxYzU4MmVlNDdlMDdlMzQ5MzNiMmQ2YjQ5NTg5MDg2ZDBlYzc1
|
14
|
+
ODk1MjgzZGUwODZlNGEwMGVjYzQ0ZmQzZmQwYzZiYjQ1NDM3MDNmZjVmNzZi
|
15
|
+
MDUwNjQ1ZmZkOWM0N2I1OTBiNWFkMjg1MTdlYmMyM2E0ZTRkNjA=
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
resque-cloudwatch-monitor
|
2
2
|
============
|
3
|
+
[![Build Status](https://travis-ci.org/YotpoLtd/resque-cloudwatch-monitor.svg)](https://travis-ci.org/YotpoLtd/resque-cloudwatch-monitor)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/YotpoLtd/resque-cloudwatch-monitor/badges/gpa.svg)](https://codeclimate.com/github/YotpoLtd/resque-cloudwatch-monitor)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/YotpoLtd/resque-cloudwatch-monitor/badges/coverage.svg)](https://codeclimate.com/github/YotpoLtd/resque-cloudwatch-monitor/coverage)
|
3
6
|
|
4
7
|
A [Resque][rq] plugin. Requires Resque ~> 1.25
|
5
8
|
|
@@ -8,6 +8,16 @@ module Resque
|
|
8
8
|
Configuration.namespace
|
9
9
|
end
|
10
10
|
|
11
|
+
#Cloudwatch Custom Metric Namespace For Failed Jobs
|
12
|
+
def fail_namespace
|
13
|
+
Configuration.fail_namespace
|
14
|
+
end
|
15
|
+
|
16
|
+
#Cloudwatch Custom Metric Namespace For Before Performed Jobs
|
17
|
+
def perform_namespace
|
18
|
+
Configuration.perform_namespace
|
19
|
+
end
|
20
|
+
|
11
21
|
#Cloudwatch metric name
|
12
22
|
def metric_name
|
13
23
|
@queue || queue
|
@@ -34,22 +44,30 @@ module Resque
|
|
34
44
|
end
|
35
45
|
|
36
46
|
#Job on failure hook. receives the job arguments and the exception
|
37
|
-
def
|
47
|
+
def on_failure_report_cw(e, *args)
|
48
|
+
report_dimensions = dimensions(*args)
|
49
|
+
report(fail_namespace, metric_name, report_dimensions)
|
50
|
+
end
|
38
51
|
|
39
|
-
|
52
|
+
def before_perform_report_cw(*args)
|
53
|
+
report_dimensions = dimensions(*args)
|
54
|
+
report(perform_namespace, metric_name, report_dimensions)
|
55
|
+
end
|
40
56
|
|
57
|
+
private
|
58
|
+
def report(report_namespace, metric_name, dimensions)
|
41
59
|
metric_data = {
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
60
|
+
metric_name: metric_name.to_s,
|
61
|
+
dimensions: dimensions,
|
62
|
+
timestamp: timestamp,
|
63
|
+
value: value,
|
64
|
+
unit: unit.to_s
|
47
65
|
}
|
48
|
-
|
66
|
+
report_namespace ||= namespace
|
49
67
|
#Send to metrics. One general of the queue and another one with dimensions if custom dimensions
|
50
68
|
metrics_to_send = dimensions.empty? ? [metric_data] : [metric_data, metric_data.merge(dimensions: [])]
|
51
69
|
|
52
|
-
Configuration.cloudwatch_client.put_metric_data(namespace:
|
70
|
+
Configuration.cloudwatch_client.put_metric_data(namespace: report_namespace, metric_data: metrics_to_send)
|
53
71
|
end
|
54
72
|
end
|
55
73
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
module Resque
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
module Plugins
|
3
|
+
module CloudwatchMonitor
|
4
|
+
module Configuration
|
5
|
+
class << self
|
6
6
|
|
7
|
-
|
7
|
+
attr_accessor :namespace, :cloudwatch_client, :fail_namespace, :perform_namespace
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
def configure
|
10
|
+
yield self
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
16
|
end
|
@@ -18,6 +18,6 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.add_dependency 'resque', '~> 1.25'
|
19
19
|
s.add_development_dependency 'rake', '~> 10.3'
|
20
20
|
s.add_development_dependency 'aws-sdk', '~> 1.11.1'
|
21
|
-
s.add_development_dependency 'rspec'
|
22
|
-
s.add_development_dependency 'timecop'
|
21
|
+
s.add_development_dependency 'rspec'
|
22
|
+
s.add_development_dependency 'timecop'
|
23
23
|
end
|
@@ -9,7 +9,7 @@ describe Resque::Plugins::CloudwatchMonitor do
|
|
9
9
|
Timecop.freeze(Time.now)
|
10
10
|
|
11
11
|
@metric_data = {
|
12
|
-
metric_name: '
|
12
|
+
metric_name: 'FailingQueue',
|
13
13
|
dimensions: [],
|
14
14
|
timestamp: Time.now.iso8601,
|
15
15
|
value: 1,
|
@@ -51,7 +51,13 @@ describe Resque::Plugins::CloudwatchMonitor do
|
|
51
51
|
it 'successful job does not send a metric to cloudwatch' do
|
52
52
|
expect(Resque::Plugins::CloudwatchMonitor::Configuration.cloudwatch_client).
|
53
53
|
to receive(:put_metric_data).
|
54
|
-
|
54
|
+
with(namespace: 'Resque Perform', metric_data: [{
|
55
|
+
metric_name: 'SuccessfulQueue',
|
56
|
+
dimensions: [],
|
57
|
+
timestamp: Time.now.iso8601,
|
58
|
+
value: 1,
|
59
|
+
unit: 'Count'
|
60
|
+
}])
|
55
61
|
|
56
62
|
Resque.enqueue(SuccessJobTest, :success)
|
57
63
|
CloudWatchMonitorTest.perform_enqueued_job(@worker)
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "codeclimate-test-reporter"
|
2
|
+
CodeClimate::TestReporter.start
|
1
3
|
require 'aws'
|
2
4
|
require 'timecop'
|
3
5
|
require 'resque-cloudwatch-monitor'
|
@@ -15,13 +17,15 @@ class CloudWatchMonitorTest
|
|
15
17
|
end
|
16
18
|
|
17
19
|
Resque::Plugins::CloudwatchMonitor::Configuration.configure do |config|
|
18
|
-
config.namespace = 'Resque
|
20
|
+
config.namespace = 'Resque Monitor'
|
21
|
+
config.fail_namespace = 'Resque Failures'
|
22
|
+
config.perform_namespace = 'Resque Perform'
|
19
23
|
config.cloudwatch_client = AWS::CloudWatch::Client.new
|
20
24
|
end
|
21
25
|
|
22
26
|
class FailureJobTest
|
23
27
|
extend Resque::Plugins::CloudwatchMonitor
|
24
|
-
@queue = '
|
28
|
+
@queue = 'FailingQueue'
|
25
29
|
|
26
30
|
def self.perform(*args)
|
27
31
|
raise Exception.new('Test Error')
|
@@ -30,7 +34,7 @@ end
|
|
30
34
|
|
31
35
|
class SuccessJobTest
|
32
36
|
extend Resque::Plugins::CloudwatchMonitor
|
33
|
-
@queue = '
|
37
|
+
@queue = 'SuccessfulQueue'
|
34
38
|
|
35
39
|
def self.perform(*args)
|
36
40
|
1 + 1
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-cloudwatch-monitor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yotpo/avichay@yotpo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: resque
|
@@ -56,30 +56,30 @@ dependencies:
|
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ! '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: timecop
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ! '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ! '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0
|
82
|
+
version: '0'
|
83
83
|
description: Allows reporting failures of resque jobs to Amazon CloudWatch
|
84
84
|
email: avichay@yotpo.com
|
85
85
|
executables: []
|
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
115
|
version: '0'
|
116
116
|
requirements: []
|
117
117
|
rubyforge_project:
|
118
|
-
rubygems_version: 2.4.
|
118
|
+
rubygems_version: 2.4.5
|
119
119
|
signing_key:
|
120
120
|
specification_version: 4
|
121
121
|
summary: Send Resque Failures To AWS CloudWatch
|