Class: PumaCloudwatch::Metrics::Sender
- Inherits:
-
Object
- Object
- PumaCloudwatch::Metrics::Sender
- Defined in:
- lib/puma_cloudwatch/metrics/sender.rb
Instance Method Summary collapse
- #call ⇒ Object
- #dimensions ⇒ Object
-
#initialize(metrics) ⇒ Sender
constructor
A new instance of Sender.
-
#metric_data ⇒ Object
Input @metrics example:.
Constructor Details
#initialize(metrics) ⇒ Sender
Returns a new instance of Sender.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/puma_cloudwatch/metrics/sender.rb', line 14 def initialize(metrics) @metrics = metrics @namespace = ENV['PUMA_CLOUDWATCH_NAMESPACE'] || "WebServer" @dimension_name = ENV['PUMA_CLOUDWATCH_DIMENSION_NAME'] || "App" @dimension_value = ENV['PUMA_CLOUDWATCH_DIMENSION_VALUE'] || "puma" @frequency = Integer(ENV['PUMA_CLOUDWATCH_FREQUENCY'] || 60) @enabled = ENV['PUMA_CLOUDWATCH_ENABLED'] || false @region = ENV['PUMA_CLOUDWATCH_AWS_REGION'] @access_key_id = ENV['PUMA_CLOUDWATCH_AWS_ACCESS_KEY_ID'] @secret_access_key = ENV['PUMA_CLOUDWATCH_AWS_SECRET_ACCESS_KEY'] end |
Instance Method Details
#call ⇒ Object
26 27 28 29 30 31 |
# File 'lib/puma_cloudwatch/metrics/sender.rb', line 26 def call put_metric_data( namespace: @namespace, metric_data: metric_data, ) end |
#dimensions ⇒ Object
75 76 77 78 79 80 |
# File 'lib/puma_cloudwatch/metrics/sender.rb', line 75 def dimensions [ name: @dimension_name, value: @dimension_value ] end |
#metric_data ⇒ Object
Input @metrics example:
[{:backlog=>[0, 0],
:running=>[0, 0],
:pool_capacity=>[16, 16],
:max_threads=>[16, 16]}]
Output example:
[{:metric_name=>"backlog",
:statistic_values=>{:sample_count=>2, :sum=>0, :minimum=>0, :maximum=>0}},
{:metric_name=>"running",
:statistic_values=>{:sample_count=>2, :sum=>0, :minimum=>0, :maximum=>0}},
{:metric_name=>"pool_capacity",
:statistic_values=>{:sample_count=>2, :sum=>32, :minimum=>16, :maximum=>16}},
{:metric_name=>"max_threads",
:statistic_values=>{:sample_count=>2, :sum=>32, :minimum=>16, :maximum=>16}}]
Resources: pool_capcity and max_threads are the important metrics dev.to/amplifr/monitoring-puma-web-server-with-prometheus-and-grafana-5b5o
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/puma_cloudwatch/metrics/sender.rb', line 55 def metric_data data = [] @metrics.each do |metric| metric.each do |name, values| data << { metric_name: name.to_s, dimensions: dimensions, storage_resolution: @frequency < 60 ? 1 : 60, statistic_values: { sample_count: values.length, sum: values.inject(0) { |sum, el| sum += el }, minimum: values.min, maximum: values.max } } end end data end |