puma-cloudwatch 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +18 -11
- data/lib/puma_cloudwatch/metrics/looper.rb +16 -1
- data/lib/puma_cloudwatch/metrics/sender.rb +7 -6
- data/lib/puma_cloudwatch/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30c13a9edd19ef80be39c8595fff1bcd873fcb73142f22ddc4411b46ca422e34
|
4
|
+
data.tar.gz: 87ac141ad365b30c9b1dd9faedb7a5e796741f6cbfe9aa1aeac7cb8bd61c72cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d735125967e0129352dd4952bec95452ae9cc7b971a56016e2970e10558c73bd12d5b8b9ca9222f998f8e423040b75c86408d5c323602b64b92006e68e8928ea
|
7
|
+
data.tar.gz: 16af951c663bb2e20585842ade8c0a9fac670ecbb818f5c0decfc35a7ae83bbc6eca01fdca709b9e93ae66cf61a4a8d51e0755578b1d87c79cf00eccf9698700
|
data/CHANGELOG.md
CHANGED
@@ -3,7 +3,11 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/).
|
5
5
|
|
6
|
-
## [0.
|
6
|
+
## [0.3.0]
|
7
|
+
- add PUMA\_CLOUDWATCH\_ENABLED env var check
|
8
|
+
- improve puma-cloudwatch plugin message
|
9
|
+
|
10
|
+
## [0.2.0]
|
7
11
|
- add PUMA\_CLOUDWATCH\_DEBUG flag
|
8
12
|
- fixes for ruby 2.3
|
9
13
|
- Update looper.rb puts
|
data/README.md
CHANGED
@@ -1,22 +1,27 @@
|
|
1
1
|
# Puma Cloudwatch Plugin
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/puma-cloudwatch)
|
4
|
+
|
3
5
|
A [puma](https://puma.io) plugin that sends puma stats to CloudWatch.
|
4
6
|
|
5
7
|
## Usage
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
+
**Important**: To enable the plugin to send metrics to CloudWatch you must set the `PUMA_CLOUDWATCH_ENABLED` env variable. This allows you to send only metrics on configured servers and not unintentionally send them locally.
|
10
|
+
|
11
|
+
It also strongly encourage to sent the `PUMA_CLOUDWATCH_DIMENSION_VALUE` env variable to include your application name. For example, if your application is named "demo-web", this would be a good value to use:
|
9
12
|
|
10
|
-
PUMA_CLOUDWATCH_DIMENSION_VALUE=
|
13
|
+
PUMA_CLOUDWATCH_DIMENSION_VALUE=demo-web-puma
|
11
14
|
|
12
|
-
Then you can get metrics for your `
|
15
|
+
Then you can get metrics for your `demo-web-puma` app. List of metrics:
|
13
16
|
|
14
17
|
* pool_capacity: the number of requests that the server is capable of taking right now.
|
15
18
|
* max_threads: preconfigured maximum number of worker threads.
|
16
19
|
* running: the number of running threads (spawned threads) for any Puma worker.
|
17
20
|
* backlog: the number of connections in that worker's "todo" set waiting for a worker thread.
|
18
21
|
|
19
|
-
The `pool_capacity` metric is important. It
|
22
|
+
The `pool_capacity` metric is important. It can be used to show how busy the server is getting before it reaches capacity. The formula is:
|
23
|
+
|
24
|
+
busy_percent = ( 1 - pool_capacity / max_threads ) * 100
|
20
25
|
|
21
26
|
### Environment Variables
|
22
27
|
|
@@ -24,17 +29,19 @@ The plugin's settings can be controlled with environmental variables:
|
|
24
29
|
|
25
30
|
Env Var | Description | Default Value
|
26
31
|
--- | --- | ---
|
27
|
-
PUMA\_CLOUDWATCH\
|
32
|
+
PUMA\_CLOUDWATCH\_DEBUG | When set, the plugin prints out the metrics that get sent to CloudWatch. | (unset)
|
28
33
|
PUMA\_CLOUDWATCH\_DIMENSION\_NAME | CloudWatch metric dimension name | App
|
29
34
|
PUMA\_CLOUDWATCH\_DIMENSION\_VALUE | CloudWatch metric dimension value | puma
|
35
|
+
PUMA\_CLOUDWATCH\_ENABLED | Enables sending of the data to CloudWatch. | (unset)
|
30
36
|
PUMA\_CLOUDWATCH\_FREQUENCY | How often to send data to CloudWatch in seconds. | 60
|
31
|
-
PUMA\_CLOUDWATCH\
|
37
|
+
PUMA\_CLOUDWATCH\_NAMESPACE | CloudWatch metric namespace | WebServer
|
38
|
+
PUMA\_CLOUDWATCH\_MUTE\_START\_MESSAGE | Mutes the "puma-cloudwatch plugin" startup message | (unset)
|
32
39
|
|
33
|
-
### Sum and Frequency
|
40
|
+
### Sum and Frequency Normalization
|
34
41
|
|
35
|
-
If you leave the `PUMA_CLOUDWATCH_FREQUENCY` at its default of 60 seconds and graph out the `pool_capacity` capacity with a 1-minute period resolution, then the CloudWatch Sum statistic is useful. It shows
|
42
|
+
If you leave the `PUMA_CLOUDWATCH_FREQUENCY` at its default of 60 seconds and graph out the `pool_capacity` capacity with a 1-minute period resolution, then the CloudWatch Sum statistic is "normalized" and useful. It shows the overall capacity total of the `demo-web-puma` servers. Particularly, the `pool_capacity` shows available capacity, and `pool_threads` shows the total threads configured.
|
36
43
|
|
37
|
-
|
44
|
+
If you change the CloudWatch send frequency, then Sum statistic must be normalized by changing the period on the chart. For example, let's say you use `PUMA_CLOUDWATCH_FREQUENCY=30`. Then puma-cloudwatch will send data every 30s. However, if the chart is still using a 1-minute period, then the Sum statistic would "double". Capacity has not doubled, puma-cloudwatch is just sending twice as much data for that period. To normalize the Sum, set the time period resolution to match the frequency. In this case: 30 seconds.
|
38
45
|
|
39
46
|
If you use the Average statistic, then you don't have to worry about normalizing. Average is inherently normalized.
|
40
47
|
|
@@ -71,4 +78,4 @@ If are you using ECS awsvpc, make sure you have the task running on private subn
|
|
71
78
|
|
72
79
|
## Contributing
|
73
80
|
|
74
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
81
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/tongueroo/puma-cloudwatch
|
@@ -9,16 +9,27 @@ class PumaCloudwatch::Metrics
|
|
9
9
|
@control_url = options[:control_url]
|
10
10
|
@control_auth_token = options[:control_auth_token]
|
11
11
|
@frequency = Integer(ENV['PUMA_CLOUDWATCH_FREQUENCY'] || 60)
|
12
|
+
@enabled = ENV['PUMA_CLOUDWATCH_ENABLED'] || false
|
12
13
|
end
|
13
14
|
|
14
15
|
def run
|
15
16
|
raise StandardError, "Puma control app is not activated" if @control_url == nil
|
16
|
-
puts
|
17
|
+
puts(message) unless ENV['PUMA_CLOUDWATCH_MUTE']
|
17
18
|
Thread.new do
|
18
19
|
perform
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
23
|
+
def message
|
24
|
+
message = "puma-cloudwatch plugin: Will send data every #{@frequency} seconds."
|
25
|
+
unless @enabled
|
26
|
+
to_enable = "To enable set the environment variable PUMA_CLOUDWATCH_ENABLED=1"
|
27
|
+
message = "Disabled: #{message}\n#{to_enable}"
|
28
|
+
end
|
29
|
+
message
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
22
33
|
def perform
|
23
34
|
loop do
|
24
35
|
stats = Fetcher.new(@options).call
|
@@ -27,5 +38,9 @@ class PumaCloudwatch::Metrics
|
|
27
38
|
sleep @frequency
|
28
39
|
end
|
29
40
|
end
|
41
|
+
|
42
|
+
def enabled?
|
43
|
+
!!@enabled
|
44
|
+
end
|
30
45
|
end
|
31
46
|
end
|
@@ -15,7 +15,8 @@ class PumaCloudwatch::Metrics
|
|
15
15
|
@metrics = metrics
|
16
16
|
@namespace = ENV['PUMA_CLOUDWATCH_NAMESPACE'] || "WebServer"
|
17
17
|
@dimension_name = ENV['PUMA_CLOUDWATCH_DIMENSION_NAME'] || "App"
|
18
|
-
@dimension_value = ENV['PUMA_CLOUDWATCH_DIMENSION_VALUE'] || "puma"
|
18
|
+
@dimension_value = ENV['PUMA_CLOUDWATCH_DIMENSION_VALUE'] || "puma"
|
19
|
+
@enabled = ENV['PUMA_CLOUDWATCH_ENABLED'] || false
|
19
20
|
end
|
20
21
|
|
21
22
|
def call
|
@@ -75,20 +76,20 @@ class PumaCloudwatch::Metrics
|
|
75
76
|
|
76
77
|
private
|
77
78
|
def put_metric_data(params)
|
78
|
-
if
|
79
|
+
if ENV['PUMA_CLOUDWATCH_DEBUG']
|
79
80
|
message = "sending data to cloudwatch:"
|
80
|
-
message = "NOOP: #{message}"
|
81
|
+
message = "NOOP: #{message}" unless enabled?
|
81
82
|
puts message
|
82
83
|
pp params
|
83
84
|
end
|
84
85
|
|
85
|
-
|
86
|
+
if enabled?
|
86
87
|
cloudwatch.put_metric_data(params)
|
87
88
|
end
|
88
89
|
end
|
89
90
|
|
90
|
-
def
|
91
|
-
|
91
|
+
def enabled?
|
92
|
+
!!@enabled
|
92
93
|
end
|
93
94
|
|
94
95
|
def cloudwatch
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puma-cloudwatch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-cloudwatch
|