puma-cloudwatch 0.3.1 → 0.4.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 597cac59de90ceaab9f7824dc362138439fff16affcd0166fcfac7d286c0c53e
4
- data.tar.gz: 714fe4f86113cdf8bdb5ff55e52aea97477edf0880ef72a2ba0d51d159c2cf69
3
+ metadata.gz: 8e2897967164e24f709d8c976d1fd9a5b741a01d020c2da8dcb191a9d4fe43ab
4
+ data.tar.gz: bdb6f674505cd71c8423dd343c77a8521715425de02c2a6b418c1b9575e10d9e
5
5
  SHA512:
6
- metadata.gz: c298cd269d1e8aa81f204c9cb8afea0576c36775ccb4117ee7e967ba06913387bbc1d958d21c30fbf637eab6564e217ed276d6c6256872bc20ad30e29b0bd14d
7
- data.tar.gz: '09cd67be3c688102cedca2d80bd0b13d8184340ed16a22388b6f8c5f7a0d7e0c99cad9fb0f9db889e8229e2987819c9c9863e662811edab687d0f33fea8f231e'
6
+ metadata.gz: '0658266b02fa7ffa618b94bdc956c12b6536cb2eea17dcf2b7a4c39452b7adf1d96bc2e83544568739bc998ee9c76cf90416b9db3d2b174bcf9d759a0b07266a'
7
+ data.tar.gz: de176da8000aec589ed539b3f0f6538a602344aab633c5dc7216307e21662f31405361525de134f0169288312af414c79b5065b14ff16a71bf257047ab9bc69d
@@ -3,6 +3,21 @@
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.4.4]
7
+ - #4 fix syntax error in older versions of ruby
8
+
9
+ ## [0.4.3]
10
+ - #3 Eliminate the need to add Array#sum
11
+
12
+ ## [0.4.2]
13
+ - #2 keep looper running on adversities
14
+
15
+ ## [0.4.1]
16
+ - #1 empty results breaks cloudwatch put_metric_data
17
+
18
+ ## [0.4.0]
19
+ - improve AWS IAM setup and permission errors so Thread loop doesnt stop
20
+
6
21
  ## [0.3.1]
7
22
  - fix PUMA_CLOUDWATCH_MUTE_START_MESSAGE var
8
23
 
data/README.md CHANGED
@@ -2,13 +2,15 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/puma-cloudwatch.svg)](https://badge.fury.io/rb/puma-cloudwatch)
4
4
 
5
+ [![BoltOps Badge](https://img.boltops.com/boltops/badges/boltops-badge.png)](https://www.boltops.com)
6
+
5
7
  A [puma](https://puma.io) plugin that sends puma stats to CloudWatch.
6
8
 
7
9
  ## Usage
8
10
 
9
11
  **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
12
 
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:
13
+ It also strongly encourage to set 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:
12
14
 
13
15
  PUMA_CLOUDWATCH_DIMENSION_VALUE=demo-web-puma
14
16
 
@@ -2,6 +2,5 @@
2
2
  major, minor, _ = RUBY_VERSION.split('.')
3
3
  if major == '2' && minor == '3'
4
4
  require "puma_cloudwatch/core_ext/thread"
5
- require "puma_cloudwatch/core_ext/array"
6
5
  require "pp"
7
6
  end
@@ -32,10 +32,14 @@ class PumaCloudwatch::Metrics
32
32
  private
33
33
  def perform
34
34
  loop do
35
- stats = Fetcher.new(@options).call
36
- results = Parser.new(stats).call
37
- Sender.new(results).call
38
- sleep @frequency
35
+ begin
36
+ stats = Fetcher.new(@options).call
37
+ results = Parser.new(stats).call
38
+ Sender.new(results).call unless results.empty?
39
+ sleep @frequency
40
+ rescue Exception => e
41
+ puts "Error reached top of looper: #{e.message} (#{e.class})"
42
+ end
39
43
  end
40
44
  end
41
45
 
@@ -57,7 +57,7 @@ class PumaCloudwatch::Metrics
57
57
  dimensions: dimensions,
58
58
  statistic_values: {
59
59
  sample_count: values.length,
60
- sum: values.sum,
60
+ sum: values.inject(0) { |sum, el| sum += el },
61
61
  minimum: values.min,
62
62
  maximum: values.max
63
63
  }
@@ -84,7 +84,15 @@ class PumaCloudwatch::Metrics
84
84
  end
85
85
 
86
86
  if enabled?
87
- cloudwatch.put_metric_data(params)
87
+ begin
88
+ cloudwatch.put_metric_data(params)
89
+ rescue Aws::CloudWatch::Errors::AccessDenied => e
90
+ puts "WARN: #{e.class} #{e.message}"
91
+ puts "Unable to send metrics to CloudWatch"
92
+ rescue PumaCloudwatch::Error => e
93
+ puts "WARN: #{e.class} #{e.message}"
94
+ puts "Unable to send metrics to CloudWatch"
95
+ end
88
96
  end
89
97
  end
90
98
 
@@ -94,6 +102,12 @@ class PumaCloudwatch::Metrics
94
102
 
95
103
  def cloudwatch
96
104
  @cloudwatch ||= Aws::CloudWatch::Client.new
105
+ rescue Aws::Errors::MissingRegionError => e
106
+ # Happens when:
107
+ # 1. ~/.aws/config is not also setup locally
108
+ # 2. On EC2 instance when AWS_REGION not set
109
+ puts "WARN: #{e.class} #{e.message}"
110
+ raise PumaCloudwatch::Error.new(e.message)
97
111
  end
98
112
  end
99
113
  end
@@ -1,3 +1,3 @@
1
1
  module PumaCloudwatch
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.4"
3
3
  end
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.3.1
4
+ version: 0.4.4
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-18 00:00:00.000000000 Z
11
+ date: 2020-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-cloudwatch
@@ -87,7 +87,6 @@ files:
87
87
  - lib/puma/plugin/cloudwatch.rb
88
88
  - lib/puma_cloudwatch.rb
89
89
  - lib/puma_cloudwatch/core_ext.rb
90
- - lib/puma_cloudwatch/core_ext/array.rb
91
90
  - lib/puma_cloudwatch/core_ext/thread.rb
92
91
  - lib/puma_cloudwatch/metrics.rb
93
92
  - lib/puma_cloudwatch/metrics/fetcher.rb
@@ -115,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
114
  - !ruby/object:Gem::Version
116
115
  version: '0'
117
116
  requirements: []
118
- rubygems_version: 3.0.6
117
+ rubygems_version: 3.1.2
119
118
  signing_key:
120
119
  specification_version: 4
121
120
  summary: Puma plugin sends puma stats to CloudWatch
@@ -1,7 +0,0 @@
1
- class Array
2
- # Note: Array#sum only available in ruby 2.4+
3
- # Thanks: http://www.viarails.net/q/How-to-sum-an-array-of-numbers-in-Ruby
4
- def sum
5
- inject(0) {|sum, i| sum + i }
6
- end
7
- end