resque-cloudwatch-monitor 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTVhYWZhNWY0OGRhOWU5NTZiMzczNGI3ZWVlOGE0YjM5NzhjM2VhMQ==
4
+ ODdlZThhMDU0YmZiY2RiZjhjNjgzOTQ5NzhjYzJkNzcxM2Y3NDZjOQ==
5
5
  data.tar.gz: !binary |-
6
- ZWU3Njc2MjBlNTJhOTY5NGI5MDU4NzVmNmEwNDVlN2I2NTM5NGJjYg==
6
+ NzVmNmM2MDQ3ZGE0YzYwZDc4NWQ3ZWZiZjRmMzIxYWM0Y2EyMjJiNw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NjY3MDgzM2RkYTNjMjQ1NGI5M2Q5NDRjZjBiNmEzM2M5MTA2NTNhOGNiYjZi
10
- NTc2Mzc4ODJjNDRiYzMwOTUxMDJkMGFhOGY2Zjk0NzEzNjNkYzBlNGIxMzdj
11
- NDBiNWYzZTg3OGM3M2FiMThiZjk5MThhMzRkZWY3ZmY3N2FlYTE=
9
+ MTg1MjNhNTM4NGFmNjdkNmU2ODg4NmE2NmE0ZjM4OGViYmJhOTllY2VjYzEx
10
+ ODZkYTVlYTY0Zjc3MTA5MDEwYzllZDdjYzQxYTMxNzQwNGZmZGE2MmUyZTA2
11
+ MDEyNmM5NDA1Zjk4ODI2MTc4ODZiMjY1ZWY0ZGEwZmNmMWQ4MjY=
12
12
  data.tar.gz: !binary |-
13
- NzM2OTAzNGNkNTIzYTA2MDFhMWQzYTVjYmRhMjI5NGQ1ZjlkMzI5NDA3ZGQx
14
- ODc2NTlhNjg1YTFhODYxY2EyMWI4OGEzNzA3YTVmMjliN2UwMjA2NmMzNzA1
15
- ZTE0ZDQ4OWZlYmEyYzU4MDgwNGFhODc4ZjZhZWFlNDllNjU3Y2Q=
13
+ MGJhNzg0Y2YxMDgxNGFjZmEwMzk0ZDU3MTgwNmJkMjgzYjU2YzBmN2MwZWZj
14
+ ZWVhMmVlZDc3ZTNkM2Q0ZmIyZGI1Y2VjMjM5YWU4YmViODZiMGM4Njk3MTdh
15
+ Zjg0NGI2ZWI2Yjk5Zjg0M2FhYzI2MGMxMTdiMWZjM2NjMDZjNzc=
@@ -1,5 +1,5 @@
1
1
  require 'resque'
2
2
 
3
- require 'resque/plugins/cloudwatch-monitor/cloudwatch-monitor'
4
3
  require 'resque/plugins/cloudwatch-monitor/configuration'
5
- require 'resque/plugins/cloudwatch-monitor/version'
4
+ require 'resque/plugins/cloudwatch-monitor/version'
5
+ require 'resque/plugins/cloudwatch-monitor'
@@ -3,19 +3,12 @@ module Resque
3
3
 
4
4
  module CloudwatchMonitor
5
5
 
6
- #Cloudwatch Custom Metric Namespace
7
- def namespace
8
- Configuration.namespace
6
+ def get_namespace(type)
7
+ Configuration.get_namespace_for(type)
9
8
  end
10
9
 
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
10
+ def should_report?(type)
11
+ Configuration.should_report?(type)
19
12
  end
20
13
 
21
14
  #Cloudwatch metric name
@@ -43,19 +36,16 @@ module Resque
43
36
  1
44
37
  end
45
38
 
46
- #Job on failure hook. receives the job arguments and the exception
47
- def on_failure_report_cw(e, *args)
48
- report_dimensions = dimensions(*args)
49
- report(fail_namespace, metric_name, report_dimensions)
50
- end
51
-
52
- def before_perform_report_cw(*args)
53
- report_dimensions = dimensions(*args)
54
- report(perform_namespace, metric_name, report_dimensions)
39
+ Configuration.event_list.each do |type|
40
+ define_method("#{type}_report_cw") do |e, *args|
41
+ report(type, *args)
42
+ end
55
43
  end
56
44
 
57
45
  private
58
- def report(report_namespace, metric_name, report_dimensions)
46
+ def report(type, *args)
47
+ return unless should_report?(type)
48
+ report_dimensions = dimensions(*args)
59
49
  report_dimensions ||= []
60
50
  report_dimensions.delete_if{|key| key[:value].nil? || key[:name].nil? }
61
51
  metric_data = {
@@ -65,7 +55,7 @@ module Resque
65
55
  value: value,
66
56
  unit: unit.to_s
67
57
  }
68
- report_namespace ||= namespace
58
+ report_namespace = get_namespace(type)
69
59
  #Send to metrics. One general of the queue and another one with dimensions if custom dimensions
70
60
  metrics_to_send = report_dimensions.empty? ? [metric_data] : [metric_data, metric_data.merge(dimensions: [])]
71
61
 
@@ -4,11 +4,54 @@ module Resque
4
4
  module Configuration
5
5
  class << self
6
6
 
7
- attr_accessor :namespace, :cloudwatch_client, :fail_namespace, :perform_namespace
7
+ attr_accessor :cloudwatch_client
8
8
 
9
+ @@report_on = {
10
+ before_perform: false,
11
+ after_perform: false,
12
+ on_failure: false,
13
+ after_enqueue: false,
14
+ before_enqueue: false,
15
+ after_dequeue: false,
16
+ before_dequeue: false
17
+ }
18
+
19
+ @@report_namespace = {
20
+ before_perform: 'Resque before_perform',
21
+ after_perform: 'Resque after_perform',
22
+ on_failure: 'Resque on_failure',
23
+ after_enqueue: 'Resque after_enqueue',
24
+ before_enqueue: 'Resque before_enqueue',
25
+ after_dequeue: 'Resque after_dequeue',
26
+ before_dequeue: 'Resque before_dequeue'
27
+ }
9
28
  def configure
10
29
  yield self
11
30
  end
31
+
32
+ def should_report?(type)
33
+ @@report_on[type]
34
+ end
35
+
36
+ def do_not_report_on(type)
37
+ @@report_on[type] = false
38
+ end
39
+
40
+ def report_on(type)
41
+ @@report_on[type] = true
42
+ end
43
+
44
+ def get_namespace_for(type)
45
+ @@report_namespace[type]
46
+ end
47
+
48
+ def set_namespace_for(type, namespace)
49
+ @@report_namespace[type] = namespace
50
+ end
51
+
52
+ def event_list
53
+ @@report_on.keys
54
+ end
12
55
  end
13
56
  end
14
57
  end
@@ -1,7 +1,7 @@
1
1
  module Resque
2
2
  module Plugins
3
3
  module CloudwatchMonitor
4
- VERSION = '0.0.3'
4
+ VERSION = '0.1.0'
5
5
  end
6
6
  end
7
- end
7
+ end
@@ -17,9 +17,13 @@ class CloudWatchMonitorTest
17
17
  end
18
18
 
19
19
  Resque::Plugins::CloudwatchMonitor::Configuration.configure do |config|
20
- config.namespace = 'Resque Monitor'
21
- config.fail_namespace = 'Resque Failures'
22
- config.perform_namespace = 'Resque Perform'
20
+ config.set_namespace_for(:on_failure, 'Resque Failures')
21
+ config.set_namespace_for(:after_perform, 'Resque Success')
22
+ config.set_namespace_for(:before_perform, 'Resque Perform')
23
+ config.report_on(:on_failure)
24
+ config.report_on(:after_perform)
25
+ config.report_on(:before_perform)
26
+
23
27
  config.cloudwatch_client = AWS::CloudWatch::Client.new
24
28
  end
25
29
 
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.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yotpo/avichay@yotpo, Yotpo/vlad@yotpo.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-01 00:00:00.000000000 Z
11
+ date: 2015-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: resque
@@ -89,7 +89,7 @@ files:
89
89
  - LICENSE
90
90
  - README.md
91
91
  - lib/resque-cloudwatch-monitor.rb
92
- - lib/resque/plugins/cloudwatch-monitor/cloudwatch-monitor.rb
92
+ - lib/resque/plugins/cloudwatch-monitor.rb
93
93
  - lib/resque/plugins/cloudwatch-monitor/configuration.rb
94
94
  - lib/resque/plugins/cloudwatch-monitor/version.rb
95
95
  - resque-cloudwatch-monitor.gemspec