puma-cloudwatch 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd707d05af913eccd60a30e1a17fde3c458c4fe89edb102ff7a29b483d65ac9d
4
- data.tar.gz: 58f7896483eec60cde81ea9615d80fccf3dd63e001f80c63968f016fb0c10081
3
+ metadata.gz: a921bab00785245aefb2570d27d05402679d20fc8a7e27d37c4d2d3f201bf487
4
+ data.tar.gz: 22659775c4c299d935a76e9d1ba9f770d973d359e85f68bf0c813663157a9693
5
5
  SHA512:
6
- metadata.gz: '08add2c6446a55ce039e8dfe8d0e86f01fd05b61b63cbc3e71830757034fd9ae220ad79a6a79536b416137c48adf92eafb74eb0c455e81f1f286830c1dc1c24a'
7
- data.tar.gz: d30b0f1d6e88f6923aec9067c3731ff7610d48a51d450320195612998dc476456119e5be861de4d58c1e6522f1f0bc6459616810d1f2af90d03b79818eac2fcd
6
+ metadata.gz: 5f4dd10d03c089fb82417b6bbc883eef15042f07f58b714fc651cf3a4495a5c4afc86275bed3e480487d66c980a41487c7bb80fec12404e760ba2a5f45886f68
7
+ data.tar.gz: e1b87394b4f173ccabed12fffeddac6c4296aa56117181ff1297f4ded6d3e4374c9e3dd1d1b45f4ffed1a8fc1cf0cd99c3ca1b941d1bab173d1f684c4edc13ef
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/).
5
+
6
+ ## [0.1.0]
7
+ - add PUMA\_CLOUDWATCH\_DEBUG flag
8
+ - fixes for ruby 2.3
9
+ - Update looper.rb puts
10
+
11
+ ## [0.1.0]
12
+ - Initial release
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Puma Cloudwatch Puma
1
+ # Puma Cloudwatch Plugin
2
2
 
3
3
  A [puma](https://puma.io) plugin that sends puma stats to CloudWatch.
4
4
 
@@ -36,7 +36,7 @@ If you leave the `PUMA_CLOUDWATCH_FREQUENCY` at its default of 60 seconds and gr
36
36
 
37
37
  **Important**: If you change the CloudWatch send frequency, then Sum statistic must be normalized. 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. To normalize the Sum, set the time period resolution to match the frequency. In this case: 30 seconds.
38
38
 
39
- If you use the Average statistic, then you don't have to worry about normalizing. Average already inherently normalized.
39
+ If you use the Average statistic, then you don't have to worry about normalizing. Average is inherently normalized.
40
40
 
41
41
  ## Installation
42
42
 
@@ -61,6 +61,14 @@ plugin :cloudwatch
61
61
 
62
62
  It activates the puma control rack application, and enables the puma-cloudwatch plugin to send metrics.
63
63
 
64
+ ### More Setup Notes
65
+
66
+ Make sure that EC2 instance running the puma server has IAM permission to publish to CloudWatch. If you are using ECS, the default permissions for the ECS task should work.
67
+
68
+ If are you using ECS awsvpc, make sure you have the task running on private subnets with a NAT. From the AWS docs: [Task Networking with the awsvpc Network Mode](https://docs.aws.amazon.com/en_pv/AmazonECS/latest/developerguide/task-networking.html)
69
+
70
+ > The awsvpc network mode does not provide task ENIs with public IP addresses for tasks that use the EC2 launch type. To access the internet, tasks that use the EC2 launch type must be launched in a private subnet that is configured to use a NAT gateway.
71
+
64
72
  ## Contributing
65
73
 
66
74
  Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/puma_cloudwatch.
@@ -0,0 +1,7 @@
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
@@ -0,0 +1,18 @@
1
+ # Hack makes sure exceptions in Threads like the one in looper.rb that reports to CloudWatch gets reported
2
+ # instead of silently being swallowed.
3
+ # https://bugs.ruby-lang.org/issues/6647
4
+ class << Thread
5
+ alias old_new new
6
+
7
+ def new(*args, &block)
8
+ old_new(*args) do |*bargs|
9
+ begin
10
+ block.call(*bargs)
11
+ rescue Exception => e
12
+ raise if Thread.abort_on_exception || Thread.current.abort_on_exception
13
+ puts "Thread for block #{block.inspect} terminated with exception: #{e.message}"
14
+ puts e.backtrace.reverse.map {|line| " #{line}"}
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ # Only apply this monkeypatches to ruby 2.3 because a specific project uses 2.3 still.
2
+ major, minor, _ = RUBY_VERSION.split('.')
3
+ if major == '2' && minor == '3'
4
+ require "puma_cloudwatch/core_ext/thread"
5
+ require "puma_cloudwatch/core_ext/array"
6
+ require "pp"
7
+ end
@@ -13,14 +13,13 @@ class PumaCloudwatch::Metrics
13
13
 
14
14
  def run
15
15
  raise StandardError, "Puma control app is not activated" if @control_url == nil
16
- puts "Sending metrics to CloudWatch..."
16
+ puts "puma-cloudwatch plugin: Will send data every #{@frequency} seconds."
17
17
  Thread.new do
18
18
  perform
19
19
  end
20
20
  end
21
21
 
22
22
  def perform
23
- puts "puma-cloudwatch plugin: Will send data every #{@frequency} seconds."
24
23
  loop do
25
24
  stats = Fetcher.new(@options).call
26
25
  results = Parser.new(stats).call
@@ -75,10 +75,14 @@ class PumaCloudwatch::Metrics
75
75
 
76
76
  private
77
77
  def put_metric_data(params)
78
- if noop?
79
- puts "NOOP: sending data to cloudwatch:"
78
+ if noop? or ENV['PUMA_CLOUDWATCH_DEBUG']
79
+ message = "sending data to cloudwatch:"
80
+ message = "NOOP: #{message}" if noop?
81
+ puts message
80
82
  pp params
81
- else
83
+ end
84
+
85
+ unless noop?
82
86
  cloudwatch.put_metric_data(params)
83
87
  end
84
88
  end
@@ -1,3 +1,3 @@
1
1
  module PumaCloudwatch
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require "puma_cloudwatch/version"
2
+ require "puma_cloudwatch/core_ext"
2
3
 
3
4
  module PumaCloudwatch
4
5
  class Error < StandardError; end
@@ -12,8 +12,6 @@ Gem::Specification.new do |spec|
12
12
  spec.homepage = "https://github.com/tongueroo/puma-cloudwatch"
13
13
  spec.license = "MIT"
14
14
 
15
- spec.metadata["homepage_uri"] = spec.homepage
16
-
17
15
  # Specify which files should be added to the gem when it is released.
18
16
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
17
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puma-cloudwatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
@@ -76,6 +76,7 @@ files:
76
76
  - ".gitignore"
77
77
  - ".rspec"
78
78
  - ".travis.yml"
79
+ - CHANGELOG.md
79
80
  - Gemfile
80
81
  - LICENSE.txt
81
82
  - README.md
@@ -85,6 +86,9 @@ files:
85
86
  - lib/puma-cloudwatch.rb
86
87
  - lib/puma/plugin/cloudwatch.rb
87
88
  - lib/puma_cloudwatch.rb
89
+ - lib/puma_cloudwatch/core_ext.rb
90
+ - lib/puma_cloudwatch/core_ext/array.rb
91
+ - lib/puma_cloudwatch/core_ext/thread.rb
88
92
  - lib/puma_cloudwatch/metrics.rb
89
93
  - lib/puma_cloudwatch/metrics/fetcher.rb
90
94
  - lib/puma_cloudwatch/metrics/looper.rb
@@ -95,8 +99,7 @@ files:
95
99
  homepage: https://github.com/tongueroo/puma-cloudwatch
96
100
  licenses:
97
101
  - MIT
98
- metadata:
99
- homepage_uri: https://github.com/tongueroo/puma-cloudwatch
102
+ metadata: {}
100
103
  post_install_message:
101
104
  rdoc_options: []
102
105
  require_paths: