cloudwatch-metrics 0.1.12 → 0.1.14

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: acc825c244c5b16fcd792fb39fe89785710cdcc5aa08c43cf082cda2200fada4
4
- data.tar.gz: eef5bd9df19b6d13dcf8a2ec4d0b0dcbc1fab97d4822854408031aac0cb9e01b
3
+ metadata.gz: 4fea54b365db5f46b021de9a93dbe005d8c48a16a1022ad2f8ab8dc0aeb09a6d
4
+ data.tar.gz: 597a6420648417aa1a48184211bf034846e12700a7a2a0f0501d7766736f8a19
5
5
  SHA512:
6
- metadata.gz: 2bd61f9092d0619f54c5f47056372511e0735ad75b0ce936ed9b4393d2d636734d10a95a5d1774111aa1efb60029c950d0982b43e72a5d0fa2e4da9c41645510
7
- data.tar.gz: e92a0955168e84c4d5eb6cc3c586b647ef0acdf5c99457ada45312cad53ab088be05115e372bdd8e09cc178562f0194b495c7e1d8019d98edcb5b5b86a0f7a00
6
+ metadata.gz: 82270ea0dac105c309e03a3574e4a81774910ecee57f65f03068938e53dd5c693c3883851f40504b952053182c0d18deecba903924eca11eeeb8e648f64fc894
7
+ data.tar.gz: 40f2f31599f3a4882df334b176f5d78657a047344a04ef3bc994006fabc556e05258829def820ceb6e78a802ea066a14252a83c683e13e506c4a6f7d4fea1732
data/README.md CHANGED
@@ -57,6 +57,17 @@ Both reporting methods accept optional parameters, which are detailed below, alo
57
57
  * `dimensions`: An array of name/value pairs that form part of the identity of a metric. Dimensions allow you to group and filter data points within a particular metric. Default is `nil`.
58
58
  * `timestamp`: The time associated with the data point. The timestamp can be up to two weeks in the past and up to two hours into the future. Default is the current time.
59
59
 
60
+ ### AWS Credentials
61
+
62
+ See [HOWTO Assume AWS role](https://docs.google.com/document/d/1NCXtlhddpJCttBPs2V4mv3J59V0C3ShTzaoSidBAVTU/edit#heading=h.kr4pxvf3gqqt) for info about setting up AWS credential locally. You can read more about AWS SDK configuration in the [AWS docs](https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/setup-config.html).
63
+
64
+ The short version: Create a file `~/.aws/config` and add your access keys there:
65
+ ```
66
+ [default]
67
+ aws_access_key_id = $AWS_ACCESS_KEY_ID
68
+ aws_secret_access_key = $AWS_SECRET_ACCESS_KEY
69
+ ```
70
+
60
71
  ## Cloudwatch Concepts
61
72
 
62
73
  Refer to the [Cloudwatch Documentation](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html) for a general overview of custom metrics in CloudWatch.
@@ -3,10 +3,18 @@
3
3
  module CloudwatchMetrics
4
4
  class Configuration
5
5
  attr_accessor :namespace, :region
6
- attr_writer :no_cw_alias
6
+ attr_writer :no_cw_alias, :publish_environments, :logger
7
7
 
8
8
  def no_cw_alias
9
9
  @no_cw_alias ||= false
10
10
  end
11
+
12
+ def publish_environments
13
+ @publish_environments ||= %w[production]
14
+ end
15
+
16
+ def logger
17
+ @logger ||= Logger.new(STDOUT)
18
+ end
11
19
  end
12
20
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CloudwatchMetrics
4
- VERSION = '0.1.12'
4
+ VERSION = '0.1.14'
5
5
  end
@@ -7,6 +7,10 @@ module CloudwatchMetrics
7
7
  class Error < StandardError; end
8
8
 
9
9
  class << self
10
+ def configuration
11
+ @configuration ||= Configuration.new
12
+ end
13
+
10
14
  def configure
11
15
  yield(configuration)
12
16
  end
@@ -40,20 +44,26 @@ module CloudwatchMetrics
40
44
 
41
45
  private
42
46
 
43
- def configuration
44
- @configuration ||= Configuration.new
45
- end
46
-
47
- def cloudwatch_client
48
- @cloudwatch_client ||= Aws::CloudWatch::Client.new(region: configuration.region)
49
- end
50
-
51
47
  def put_data(namespace:, metric_data:)
52
48
  resp = cloudwatch_client.put_metric_data({
53
49
  namespace: namespace,
54
50
  metric_data: metric_data
55
51
  })
56
52
  end
53
+
54
+ def cloudwatch_client
55
+ return @cloudwatch_client unless @cloudwatch_client.nil?
56
+
57
+ @cloudwatch_client = if !configuration.region.nil?
58
+ Aws::CloudWatch::Client.new(region: configuration.region)
59
+ else
60
+ Aws::CloudWatch::Client.new
61
+ end
62
+ end
63
+
64
+ def environment
65
+ ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
66
+ end
57
67
  end
58
68
  end
59
69
 
@@ -6,7 +6,7 @@ module CloudwatchMetrics
6
6
  source_root File.expand_path('templates', __dir__)
7
7
 
8
8
  def copy_initializer_file
9
- copy_file "cloudwatch_metrics.rb", "config/initializers/cloudwatch_metrics.rb"
9
+ copy_file 'cloudwatch_metrics.rb', 'config/initializers/cloudwatch_metrics.rb'
10
10
  end
11
11
  end
12
12
  end
@@ -16,4 +16,15 @@ CloudwatchMetrics.configure do |config|
16
16
  # the metrics will be published to. This is useful if you want to publish
17
17
  # to a region other than the default region for your AWS credentials.
18
18
  # config.region = 'us-east-1'
19
+
20
+ # By default metrics will only be published in the production environment.
21
+ # In all other environments metrics will be logged.
22
+ # You can override this behavior by specifying an array of environments
23
+ # that you want to publish metrics in.
24
+ # config.publish_environments = %w[production staging]
25
+
26
+ # This is an optional configuration to set the logger that
27
+ # the metrics will be logged to. Defaults to `Logger.new(STDOUT)`.
28
+ # For rails applications you can set this to `Rails.logger`.
29
+ # config.logger = Rails.logger
19
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudwatch-metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Puckett