resque-cloudwatch-metrics 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/docker/Gemfile.lock +2 -2
- data/lib/resque/cloudwatch/metrics.rb +41 -5
- data/lib/resque/cloudwatch/metrics/metric.rb +28 -12
- data/lib/resque/cloudwatch/metrics/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c911ab4ce8fdc6e886d16ba91e7e73ff850ef69
|
4
|
+
data.tar.gz: 6532bffdca221cdf3bb2657a3544263ee35b8792
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5169a01442cfa8948a710ccc2c8ad8e34ec91f14c233d2180752fd7a238a45e5e0cb4ac97abdc5c73ab72505a21fec18140a1e4e20ddc1839c4bf4b918d70c18
|
7
|
+
data.tar.gz: 0de3324587cee5b870e5c53246b45f74d7bdc08af51ac70f28d9e388e047f1b04a6a5f74ca4ded85a6bb51543826cf01a8dc9796cf6648eda79f72e3049df61c
|
data/README.md
CHANGED
@@ -39,6 +39,16 @@ Usage: resque-cloudwatch-metrics [options]
|
|
39
39
|
--redis-namespace <namespace>
|
40
40
|
--cw-namespace <namespace>
|
41
41
|
-i, --interval <interval>
|
42
|
+
--skip-pending
|
43
|
+
--skip-processed
|
44
|
+
--skip-failed
|
45
|
+
--skip-queues
|
46
|
+
--skip-workers
|
47
|
+
--skip-working
|
48
|
+
--skip-pending-per-queue
|
49
|
+
--not-working
|
50
|
+
--processing
|
51
|
+
--dryrun
|
42
52
|
```
|
43
53
|
|
44
54
|
## Development
|
data/docker/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
GEM
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
|
-
aws-sdk-core (2.6.
|
4
|
+
aws-sdk-core (2.6.44)
|
5
5
|
aws-sigv4 (~> 1.0)
|
6
6
|
jmespath (~> 1.0)
|
7
7
|
aws-sigv4 (1.0.0)
|
@@ -20,7 +20,7 @@ GEM
|
|
20
20
|
redis-namespace (~> 1.3)
|
21
21
|
sinatra (>= 0.9.2)
|
22
22
|
vegas (~> 0.1.2)
|
23
|
-
resque-cloudwatch-metrics (0.
|
23
|
+
resque-cloudwatch-metrics (0.4.0)
|
24
24
|
aws-sdk-core (~> 2)
|
25
25
|
resque (~> 1)
|
26
26
|
sinatra (1.4.7)
|
@@ -22,6 +22,8 @@ module Resque
|
|
22
22
|
def parse_arguments(args)
|
23
23
|
options = {}
|
24
24
|
redis = {}
|
25
|
+
skip = []
|
26
|
+
extra = []
|
25
27
|
|
26
28
|
opt = OptionParser.new
|
27
29
|
opt.on('-h', '--host <host>') { |v| redis[:host] = v }
|
@@ -33,21 +35,41 @@ module Resque
|
|
33
35
|
opt.on('--redis-namespace <namespace>') { |v| options[:redis_namespace] = v }
|
34
36
|
opt.on('--cw-namespace <namespace>') { |v| options[:cw_namespace] = v }
|
35
37
|
opt.on('-i', '--interval <interval>') { |v| options[:interval] = v.to_f }
|
38
|
+
opt.on('--skip-pending') { skip << :pending }
|
39
|
+
opt.on('--skip-processed') { skip << :processed }
|
40
|
+
opt.on('--skip-failed') { skip << :failed }
|
41
|
+
opt.on('--skip-queues') { skip << :queues }
|
42
|
+
opt.on('--skip-workers') { skip << :workers }
|
43
|
+
opt.on('--skip-working') { skip << :working }
|
44
|
+
opt.on('--skip-pending-per-queue') { skip << :pending_per_queue }
|
45
|
+
opt.on('--not-working') { extra << :not_working }
|
46
|
+
opt.on('--processing') { extra << :processing }
|
47
|
+
opt.on('--dryrun') { options[:dryrun] = true }
|
36
48
|
opt.parse(args)
|
37
49
|
|
38
50
|
options[:redis] ||= redis unless redis.empty?
|
51
|
+
|
52
|
+
metric = {}
|
53
|
+
metric[:skip] = skip unless skip.empty?
|
54
|
+
metric[:extra] = extra unless extra.empty?
|
55
|
+
options[:metric] = metric unless metric.empty?
|
56
|
+
|
39
57
|
options
|
40
58
|
end
|
41
59
|
end
|
42
60
|
|
43
61
|
def initialize(redis: nil,
|
44
62
|
redis_namespace: nil,
|
63
|
+
cw_namespace: DEFAULT_CW_NAMESPACE,
|
45
64
|
interval: nil,
|
46
|
-
|
65
|
+
metric: {},
|
66
|
+
dryrun: false)
|
47
67
|
Resque.redis = redis if redis
|
48
68
|
@redis_namespace = redis_namespace
|
49
69
|
@interval = interval
|
50
70
|
@cw_namespace = cw_namespace
|
71
|
+
@metric_options = metric
|
72
|
+
@dryrun = dryrun
|
51
73
|
end
|
52
74
|
|
53
75
|
def run
|
@@ -67,7 +89,7 @@ module Resque
|
|
67
89
|
def run_once
|
68
90
|
put_metric_data(
|
69
91
|
redis_namespaces
|
70
|
-
.map { |redis_namespace| Metric.create(redis_namespace) }
|
92
|
+
.map { |redis_namespace| Metric.create(redis_namespace, @metric_options) }
|
71
93
|
.flat_map(&:to_cloudwatch_metric_data)
|
72
94
|
)
|
73
95
|
end
|
@@ -88,16 +110,30 @@ module Resque
|
|
88
110
|
end
|
89
111
|
|
90
112
|
def put_metric_data(metric_data)
|
113
|
+
if @dryrun
|
114
|
+
dump_metric_data(metric_data)
|
115
|
+
return
|
116
|
+
end
|
117
|
+
|
91
118
|
metric_data.each_slice(MAX_METRIC_DATA_PER_PUT).map do |data|
|
92
|
-
Thread.start(data) do |
|
93
|
-
|
119
|
+
Thread.start(data, cloudwatch) do |data_, cloudwatch_|
|
120
|
+
cloudwatch_.put_metric_data(
|
94
121
|
namespace: @cw_namespace,
|
95
|
-
metric_data:
|
122
|
+
metric_data: data_,
|
96
123
|
)
|
97
124
|
end
|
98
125
|
end.each(&:join)
|
99
126
|
end
|
100
127
|
|
128
|
+
def dump_metric_data(metric_data)
|
129
|
+
puts metric_data.to_json(
|
130
|
+
indent: ' ' * 2,
|
131
|
+
space: ' ',
|
132
|
+
object_nl: "\n",
|
133
|
+
array_nl: "\n",
|
134
|
+
)
|
135
|
+
end
|
136
|
+
|
101
137
|
def cloudwatch
|
102
138
|
@_cloudwatch ||= Aws::CloudWatch::Client.new
|
103
139
|
end
|
@@ -6,18 +6,21 @@ module Resque
|
|
6
6
|
module CloudWatch
|
7
7
|
class Metrics
|
8
8
|
class Metric
|
9
|
+
DEFAULT_METRIC_NAMES = %i(pending processed failed queues workers working).freeze
|
10
|
+
|
9
11
|
class << self
|
10
12
|
@@mutex = Mutex.new
|
11
13
|
|
12
|
-
def create(namespace)
|
14
|
+
def create(namespace, skip: [], extra: [])
|
13
15
|
@@mutex.synchronize do
|
14
16
|
Resque.redis.namespace = namespace
|
15
17
|
new(
|
16
18
|
Time.now,
|
17
19
|
namespace,
|
18
20
|
Resque.info,
|
19
|
-
current_queue_sizes,
|
21
|
+
!skip.include?(:pending_per_queue) && current_queue_sizes,
|
20
22
|
get_previous_processed(namespace),
|
23
|
+
skip: skip, extra: extra,
|
21
24
|
).tap do |metric|
|
22
25
|
set_previous_processed(namespace, metric.processed)
|
23
26
|
end
|
@@ -31,22 +34,24 @@ module Resque
|
|
31
34
|
end
|
32
35
|
|
33
36
|
def get_previous_processed(namespace)
|
34
|
-
@
|
35
|
-
@
|
37
|
+
@previous_processed ||= {}
|
38
|
+
@previous_processed[namespace]
|
36
39
|
end
|
37
40
|
|
38
41
|
def set_previous_processed(namespace, previous_processed)
|
39
|
-
@
|
40
|
-
@
|
42
|
+
@previous_processed ||= {}
|
43
|
+
@previous_processed[namespace] = previous_processed
|
41
44
|
end
|
42
45
|
end
|
43
46
|
|
44
|
-
def initialize(time, namespace, info, queue_sizes, previous_processed)
|
47
|
+
def initialize(time, namespace, info, queue_sizes, previous_processed, skip: [], extra: [])
|
45
48
|
@time = time
|
46
49
|
@namespace = namespace
|
47
50
|
@info = info
|
48
51
|
@queue_sizes = queue_sizes
|
49
52
|
@previous_processed = previous_processed
|
53
|
+
@skip = skip
|
54
|
+
@extra = extra
|
50
55
|
end
|
51
56
|
|
52
57
|
def pending; @info[:pending]; end
|
@@ -65,16 +70,27 @@ module Resque
|
|
65
70
|
end
|
66
71
|
|
67
72
|
def to_cloudwatch_metric_data
|
68
|
-
|
73
|
+
metric_data = metric_names.map do |key|
|
69
74
|
build_cloudwatch_metric_datum(camelize(key.to_s), public_send(key))
|
70
|
-
end +
|
71
|
-
@queue_sizes.map do |name, size|
|
72
|
-
build_cloudwatch_metric_datum('Pending', size, queue: name)
|
73
75
|
end
|
76
|
+
|
77
|
+
if @queue_sizes
|
78
|
+
metric_data.concat(
|
79
|
+
@queue_sizes.map do |name, size|
|
80
|
+
build_cloudwatch_metric_datum('Pending', size, Queue: name)
|
81
|
+
end
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
metric_data
|
74
86
|
end
|
75
87
|
|
76
88
|
private
|
77
89
|
|
90
|
+
def metric_names
|
91
|
+
DEFAULT_METRIC_NAMES - @skip + @extra
|
92
|
+
end
|
93
|
+
|
78
94
|
def build_cloudwatch_metric_datum(metric_name, value, dimensions = {})
|
79
95
|
{
|
80
96
|
metric_name: metric_name,
|
@@ -86,7 +102,7 @@ module Resque
|
|
86
102
|
end
|
87
103
|
|
88
104
|
def default_dimensions
|
89
|
-
|
105
|
+
Dimensions.new(Namespace: @namespace.to_s)
|
90
106
|
end
|
91
107
|
|
92
108
|
def incremental_size_of_processed
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-cloudwatch-metrics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masaki Takeuchi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-core
|