Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/pkg/
/spec/reports/
/tmp/
/.idea/

# rspec failure tracking
.rspec_status
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ PUMA\_CLOUDWATCH\_AWS\_REGION | CloudWatch metric AWS region | (unset)
PUMA\_CLOUDWATCH\_AWS\_ACCESS_KEY_ID | AWS access key ID | (unset)
PUMA\_CLOUDWATCH\_AWS\_SECRET_ACCESS_KEY | AWS secret access key | (unset)
PUMA\_CLOUDWATCH\_MUTE\_START\_MESSAGE | Mutes the "puma-cloudwatch plugin" startup message | (unset)
PUMA\_CLOUDWATCH\_ENVIRONMENT | CloudWatch environment dimension value | (Puma servers environment)

### Sum and Frequency Normalization

Expand Down
2 changes: 1 addition & 1 deletion lib/puma_cloudwatch/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ def start_sending
Looper.run(@launcher.options)
end
end
end
end
2 changes: 1 addition & 1 deletion lib/puma_cloudwatch/metrics/looper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def perform
stats = Fetcher.new(@options).call
@fetched = true
results = Parser.new(stats).call
Sender.new(results).call unless results.empty?
Sender.new(results, @options[:environment]).call unless results.empty?
sleep @frequency
rescue Exception => e
if @fetched
Expand Down
7 changes: 4 additions & 3 deletions lib/puma_cloudwatch/metrics/sender.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
class PumaCloudwatch::Metrics
class Sender
def initialize(metrics)
def initialize(metrics, environment)
@metrics = metrics
@namespace = ENV['PUMA_CLOUDWATCH_NAMESPACE'] || "WebServer"
@dimension_name = ENV['PUMA_CLOUDWATCH_DIMENSION_NAME'] || "App"
Expand All @@ -21,6 +21,7 @@ def initialize(metrics)
@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']
@environment = ENV['PUMA_CLOUDWATCH_ENVIRONMENT'] || environment
end

def call
Expand Down Expand Up @@ -74,8 +75,8 @@ def metric_data

def dimensions
[
name: @dimension_name,
value: @dimension_value
{ name: @dimension_name, value: @dimension_value },
{ name: 'environment', value: @environment }
]
end

Expand Down
2 changes: 1 addition & 1 deletion spec/puma_cloudwatch/metrics/fetcher_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RSpec.describe PumaCloudwatch::Metrics::Fetcher do
subject(:fetcher) { described_class.new(control_url: '', control_auth_token: '') }
subject(:fetcher) { described_class.new(control_url: 'unix://', control_auth_token: '') }

describe "fetcher" do
it "call" do
Expand Down
42 changes: 25 additions & 17 deletions spec/puma_cloudwatch/metrics/sender_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RSpec.describe PumaCloudwatch::Metrics::Sender do
subject(:sender) { described_class.new(metrics) }
subject(:sender) { described_class.new(metrics, 'development') }

context "single mode" do
context "metrics filled out" do
Expand All @@ -14,17 +14,21 @@
data = sender.metric_data
expect(data).to eq(
[{:metric_name=>"backlog",
:dimensions=>[{:name=>"App", :value=>"demo-puma"}],
:statistic_values=>{:sample_count=>1, :sum=>0, :minimum=>0, :maximum=>0}},
:dimensions=>[{:name=>"App", :value=>"puma"}, {:name=>"environment", :value=>"development"}],
:statistic_values=>{:sample_count=>1, :sum=>0, :minimum=>0, :maximum=>0},
:storage_resolution=>60},
{:metric_name=>"running",
:dimensions=>[{:name=>"App", :value=>"demo-puma"}],
:statistic_values=>{:sample_count=>1, :sum=>16, :minimum=>16, :maximum=>16}},
:dimensions=>[{:name=>"App", :value=>"puma"}, {:name=>"environment", :value=>"development"}],
:statistic_values=>{:sample_count=>1, :sum=>16, :minimum=>16, :maximum=>16},
:storage_resolution=>60},
{:metric_name=>"pool_capacity",
:dimensions=>[{:name=>"App", :value=>"demo-puma"}],
:statistic_values=>{:sample_count=>1, :sum=>8, :minimum=>8, :maximum=>8}},
:dimensions=>[{:name=>"App", :value=>"puma"}, {:name=>"environment", :value=>"development"}],
:statistic_values=>{:sample_count=>1, :sum=>8, :minimum=>8, :maximum=>8},
:storage_resolution=>60},
{:metric_name=>"max_threads",
:dimensions=>[{:name=>"App", :value=>"demo-puma"}],
:statistic_values=>{:sample_count=>1, :sum=>16, :minimum=>16, :maximum=>16}}]
:dimensions=>[{:name=>"App", :value=>"puma"}, {:name=>"environment", :value=>"development"}],
:statistic_values=>{:sample_count=>1, :sum=>16, :minimum=>16, :maximum=>16},
:storage_resolution=>60}]
)
end

Expand All @@ -49,17 +53,21 @@
data = sender.metric_data
expect(data).to eq(
[{:metric_name=>"backlog",
:dimensions=>[{:name=>"App", :value=>"demo-puma"}],
:statistic_values=>{:sample_count=>2, :sum=>0, :minimum=>0, :maximum=>0}},
:dimensions=>[{:name=>"App", :value=>"puma"}, {:name=>"environment", :value=>"development"}],
:statistic_values=>{:sample_count=>2, :sum=>0, :minimum=>0, :maximum=>0},
:storage_resolution=>60},
{:metric_name=>"running",
:dimensions=>[{:name=>"App", :value=>"demo-puma"}],
:statistic_values=>{:sample_count=>2, :sum=>0, :minimum=>0, :maximum=>0}},
:dimensions=>[{:name=>"App", :value=>"puma"}, {:name=>"environment", :value=>"development"}],
:statistic_values=>{:sample_count=>2, :sum=>0, :minimum=>0, :maximum=>0},
:storage_resolution=>60},
{:metric_name=>"pool_capacity",
:dimensions=>[{:name=>"App", :value=>"demo-puma"}],
:statistic_values=>{:sample_count=>2, :sum=>32, :minimum=>16, :maximum=>16}},
:dimensions=>[{:name=>"App", :value=>"puma"}, {:name=>"environment", :value=>"development"}],
:statistic_values=>{:sample_count=>2, :sum=>32, :minimum=>16, :maximum=>16},
:storage_resolution=>60},
{:metric_name=>"max_threads",
:dimensions=>[{:name=>"App", :value=>"demo-puma"}],
:statistic_values=>{:sample_count=>2, :sum=>32, :minimum=>16, :maximum=>16}}]
:dimensions=>[{:name=>"App", :value=>"puma"}, {:name=>"environment", :value=>"development"}],
:statistic_values=>{:sample_count=>2, :sum=>32, :minimum=>16, :maximum=>16},
:storage_resolution=>60}]
)
end

Expand Down