resque-cloudwatch-metrics 0.1.0 → 0.2.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 +8 -0
- data/docker/.gitignore +1 -0
- data/docker/Dockerfile +19 -0
- data/docker/Gemfile +3 -0
- data/docker/Gemfile.lock +41 -0
- data/lib/resque/cloudwatch/metrics/metric.rb +111 -0
- data/lib/resque/cloudwatch/metrics/version.rb +1 -1
- data/lib/resque/cloudwatch/metrics.rb +6 -38
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35f370eb016eaf0a9b1393edb97933e50ad328c6
|
4
|
+
data.tar.gz: ca1e50cac0cbe1a44c193604f1df6d76eb368247
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adeaa94b383ce7a2ca7a3627d51adaebfaf80acdd56e50d8301b12ee7a99bc163bb6789606d6266fb42b1f5fc8ea4d1e5be53d918b5f171043c99266e76ff4a1
|
7
|
+
data.tar.gz: bc5251942a12c395e55f824129e945ebcc98a1cac05c3946ce4fbacc8bb737d2646a80bb43c090ae9cd8d32ad6cfb7b69c2fc58b9709ad49a0763c2f820177a5
|
data/README.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
Send Resque.info to CloudWatch Metrics
|
4
4
|
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/resque-cloudwatch-metrics.svg)](https://badge.fury.io/rb/resque-cloudwatch-metrics)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/m4i/resque-cloudwatch-metrics/badges/gpa.svg)](https://codeclimate.com/github/m4i/resque-cloudwatch-metrics)
|
7
|
+
[![Dependency Status](https://gemnasium.com/badges/github.com/m4i/resque-cloudwatch-metrics.svg)](https://gemnasium.com/github.com/m4i/resque-cloudwatch-metrics)
|
8
|
+
|
5
9
|
## Installation
|
6
10
|
|
7
11
|
Add this line to your application's Gemfile:
|
@@ -18,6 +22,10 @@ Or install it yourself as:
|
|
18
22
|
|
19
23
|
$ gem install resque-cloudwatch-metrics
|
20
24
|
|
25
|
+
Or use Docker:
|
26
|
+
|
27
|
+
$ docker run --rm m4i0/resque-cloudwatch-metrics --help
|
28
|
+
|
21
29
|
## Usage
|
22
30
|
|
23
31
|
```
|
data/docker/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
/.bundle/
|
data/docker/Dockerfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
FROM alpine
|
2
|
+
|
3
|
+
RUN set -eux \
|
4
|
+
&& apk add --no-cache \
|
5
|
+
ca-certificates \
|
6
|
+
openssl \
|
7
|
+
ruby \
|
8
|
+
ruby-bundler \
|
9
|
+
ruby-json \
|
10
|
+
# dumb-init
|
11
|
+
&& VERSION=1.2.0 \
|
12
|
+
&& wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v$VERSION/dumb-init_${VERSION}_amd64 \
|
13
|
+
&& chmod +x /usr/local/bin/dumb-init
|
14
|
+
|
15
|
+
ENTRYPOINT ["dumb-init", "resque-cloudwatch-metrics"]
|
16
|
+
WORKDIR /app
|
17
|
+
|
18
|
+
COPY Gemfile Gemfile.lock /app/
|
19
|
+
RUN bundle install -j4 --frozen
|
data/docker/Gemfile
ADDED
data/docker/Gemfile.lock
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
aws-sdk-core (2.6.41)
|
5
|
+
aws-sigv4 (~> 1.0)
|
6
|
+
jmespath (~> 1.0)
|
7
|
+
aws-sigv4 (1.0.0)
|
8
|
+
jmespath (1.3.1)
|
9
|
+
mono_logger (1.1.0)
|
10
|
+
multi_json (1.12.1)
|
11
|
+
rack (1.6.5)
|
12
|
+
rack-protection (1.5.3)
|
13
|
+
rack
|
14
|
+
redis (3.3.2)
|
15
|
+
redis-namespace (1.5.2)
|
16
|
+
redis (~> 3.0, >= 3.0.4)
|
17
|
+
resque (1.26.0)
|
18
|
+
mono_logger (~> 1.0)
|
19
|
+
multi_json (~> 1.0)
|
20
|
+
redis-namespace (~> 1.3)
|
21
|
+
sinatra (>= 0.9.2)
|
22
|
+
vegas (~> 0.1.2)
|
23
|
+
resque-cloudwatch-metrics (0.2.0)
|
24
|
+
aws-sdk-core (~> 2)
|
25
|
+
resque (~> 1)
|
26
|
+
sinatra (1.4.7)
|
27
|
+
rack (~> 1.5)
|
28
|
+
rack-protection (~> 1.4)
|
29
|
+
tilt (>= 1.3, < 3)
|
30
|
+
tilt (2.0.5)
|
31
|
+
vegas (0.1.11)
|
32
|
+
rack (>= 1.0.0)
|
33
|
+
|
34
|
+
PLATFORMS
|
35
|
+
ruby
|
36
|
+
|
37
|
+
DEPENDENCIES
|
38
|
+
resque-cloudwatch-metrics
|
39
|
+
|
40
|
+
BUNDLED WITH
|
41
|
+
1.13.6
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'resque'
|
4
|
+
|
5
|
+
module Resque
|
6
|
+
module CloudWatch
|
7
|
+
class Metrics
|
8
|
+
class Metric
|
9
|
+
class << self
|
10
|
+
@@mutex = Mutex.new
|
11
|
+
|
12
|
+
def create(namespace)
|
13
|
+
@@mutex.synchronize do
|
14
|
+
Resque.redis.namespace = namespace
|
15
|
+
new(
|
16
|
+
Time.now,
|
17
|
+
namespace,
|
18
|
+
Resque.info,
|
19
|
+
current_queue_sizes,
|
20
|
+
get_previous_processed(namespace),
|
21
|
+
).tap do |metric|
|
22
|
+
set_previous_processed(namespace, metric.processed)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def current_queue_sizes
|
30
|
+
Resque.queues.map { |name| [name, Resque.size(name)] }
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_previous_processed(namespace)
|
34
|
+
@_previous_processed ||= {}
|
35
|
+
@_previous_processed[namespace]
|
36
|
+
end
|
37
|
+
|
38
|
+
def set_previous_processed(namespace, previous_processed)
|
39
|
+
@_previous_processed ||= {}
|
40
|
+
@_previous_processed[namespace] = previous_processed
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def initialize(time, namespace, info, queue_sizes, previous_processed)
|
45
|
+
@time = time
|
46
|
+
@namespace = namespace
|
47
|
+
@info = info
|
48
|
+
@queue_sizes = queue_sizes
|
49
|
+
@previous_processed = previous_processed
|
50
|
+
end
|
51
|
+
|
52
|
+
def pending; @info[:pending]; end
|
53
|
+
def processed; @info[:processed]; end
|
54
|
+
def failed; @info[:failed]; end
|
55
|
+
def queues; @info[:queues]; end
|
56
|
+
def workers; @info[:workers]; end
|
57
|
+
def working; @info[:working]; end
|
58
|
+
|
59
|
+
def processing
|
60
|
+
incremental_size_of_processed + working
|
61
|
+
end
|
62
|
+
|
63
|
+
def to_cloudwatch_metric_data
|
64
|
+
dimensions = [{ name: 'namespace', value: @namespace.to_s }]
|
65
|
+
|
66
|
+
%i(pending processed failed queues workers working processing).map do |key|
|
67
|
+
build_cloudwatch_metric_datum(key.to_s.capitalize, public_send(key))
|
68
|
+
end +
|
69
|
+
@queue_sizes.map do |name, size|
|
70
|
+
build_cloudwatch_metric_datum('Pending', size, queue: name)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def build_cloudwatch_metric_datum(metric_name, value, dimensions = {})
|
77
|
+
{
|
78
|
+
metric_name: metric_name,
|
79
|
+
dimensions: default_dimensions.merge(dimensions).to_cloudwatch,
|
80
|
+
timestamp: @time,
|
81
|
+
value: value,
|
82
|
+
unit: 'Count',
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
def default_dimensions
|
87
|
+
@_default_dimensions = Dimensions.new(namespace: @namespace.to_s)
|
88
|
+
end
|
89
|
+
|
90
|
+
def incremental_size_of_processed
|
91
|
+
if @previous_processed.nil?
|
92
|
+
0
|
93
|
+
else
|
94
|
+
[0, processed - @previous_processed].max
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
class Dimensions < Hash
|
100
|
+
def initialize(hash)
|
101
|
+
super()
|
102
|
+
update(hash)
|
103
|
+
end
|
104
|
+
|
105
|
+
def to_cloudwatch
|
106
|
+
map { |name, value| { name: name, value: value } }
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -4,6 +4,7 @@ require 'resque/cloudwatch/metrics/version'
|
|
4
4
|
require 'optparse'
|
5
5
|
require 'aws-sdk-core'
|
6
6
|
require 'resque'
|
7
|
+
require 'resque/cloudwatch/metrics/metric'
|
7
8
|
|
8
9
|
module Resque
|
9
10
|
module CloudWatch
|
@@ -47,8 +48,6 @@ module Resque
|
|
47
48
|
@redis_namespace = redis_namespace
|
48
49
|
@interval = interval
|
49
50
|
@cw_namespace = cw_namespace
|
50
|
-
|
51
|
-
@mutex = Mutex.new
|
52
51
|
end
|
53
52
|
|
54
53
|
def run
|
@@ -66,19 +65,11 @@ module Resque
|
|
66
65
|
private
|
67
66
|
|
68
67
|
def run_once
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
redis_namespaces.map do |redis_namespace|
|
75
|
-
Resque.redis.namespace = redis_namespace
|
76
|
-
[
|
77
|
-
redis_namespace,
|
78
|
-
Resque.info,
|
79
|
-
Resque.queues.map { |name| [name, Resque.size(name)] },
|
80
|
-
]
|
81
|
-
end
|
68
|
+
put_metric_data(
|
69
|
+
redis_namespaces
|
70
|
+
.map { |redis_namespace| Metric.create(redis_namespace) }
|
71
|
+
.flat_map(&:to_cloudwatch_metric_data)
|
72
|
+
)
|
82
73
|
end
|
83
74
|
|
84
75
|
def redis_namespaces
|
@@ -96,29 +87,6 @@ module Resque
|
|
96
87
|
end
|
97
88
|
end
|
98
89
|
|
99
|
-
def build_metric_data(timestamp, redis_namespace, info, queue_sizes)
|
100
|
-
dimensions = [{ name: 'namespace', value: redis_namespace.to_s }]
|
101
|
-
|
102
|
-
%i(pending processed failed queues workers working).map do |key|
|
103
|
-
{
|
104
|
-
metric_name: key.to_s.capitalize,
|
105
|
-
dimensions: dimensions,
|
106
|
-
timestamp: timestamp,
|
107
|
-
value: info[key],
|
108
|
-
unit: 'Count',
|
109
|
-
}
|
110
|
-
end +
|
111
|
-
queue_sizes.map do |name, size|
|
112
|
-
{
|
113
|
-
metric_name: 'Pending',
|
114
|
-
dimensions: dimensions + [{ name: 'queue', value: name }],
|
115
|
-
timestamp: timestamp,
|
116
|
-
value: size,
|
117
|
-
unit: 'Count',
|
118
|
-
}
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
90
|
def put_metric_data(metric_data)
|
123
91
|
metric_data.each_slice(MAX_METRIC_DATA_PER_PUT).map do |data|
|
124
92
|
Thread.start(data) do |data|
|
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.2.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: 2016-12-
|
11
|
+
date: 2016-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-core
|
@@ -82,8 +82,13 @@ files:
|
|
82
82
|
- Rakefile
|
83
83
|
- bin/console
|
84
84
|
- bin/setup
|
85
|
+
- docker/.gitignore
|
86
|
+
- docker/Dockerfile
|
87
|
+
- docker/Gemfile
|
88
|
+
- docker/Gemfile.lock
|
85
89
|
- exe/resque-cloudwatch-metrics
|
86
90
|
- lib/resque/cloudwatch/metrics.rb
|
91
|
+
- lib/resque/cloudwatch/metrics/metric.rb
|
87
92
|
- lib/resque/cloudwatch/metrics/version.rb
|
88
93
|
- resque-cloudwatch-metrics.gemspec
|
89
94
|
homepage: https://github.com/m4i/resque-cloudwatch-metrics
|