cloudwatch-metrics 0.1.15 → 0.1.17

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: 1dff409be424bcafe2081ebe6583808b9577f957db434dcf6d0101f4e61c8eb9
4
- data.tar.gz: bc45bed975955dc25846b8a427f8ed28b62f26f4910a8fef8262374ccd21eede
3
+ metadata.gz: dfe7fbdd2e3121c9144df74e1e620277b0d9c1d019eefcbc62592e979d575cf2
4
+ data.tar.gz: e4c052ef871bd758454ebbd52d931eb2af554c0cf3e13ca2aad612cf533c39e4
5
5
  SHA512:
6
- metadata.gz: c63953bc1565b6aa922d8521067193d25c680667a09a1361dd5ef8dfaacdbbf31acf50ea0b11f552355372146a27dad2df59b6314f3cb70d330e538c084c8740
7
- data.tar.gz: 4c93c5b6b9a38d6a570e86c271d0855bea2321b6c3474a9231119bfa3798a6e8af3a4158604738fc6e0cfc7c6cf681c1bdcd26ab7fe62494def64beeb639eea0
6
+ metadata.gz: 4ac092df3e27dc27438a72d8e1962fd35a5ea623074c0853f29874c31f90518090555389a9e4d63e8ea88491b40643e2f80d8e531ce9d66b8438ce0826cf90d2
7
+ data.tar.gz: 8fe6aa51871bef6c68df7d00c22a421834a057c722c819fb7efd58a588f3a8bc03710fb22a445906a01b16d5e7aa61edb84f647100b73aeb8415eab9c11fc220
data/README.md CHANGED
@@ -31,21 +31,21 @@ Metrics are reported using `CW.report` for single data points, or `CW.report_all
31
31
 
32
32
  ### CW.report Required Parameters
33
33
 
34
- * `metric_name`: The name of the metric.
34
+ * `name`: The name of the metric.
35
35
  * `value`: The value for the single data point being reported.
36
36
 
37
- E.g. `CW.report(metric_name: 'search_result_count', value: 25)`
37
+ E.g. `CW.report(name: 'search_result_count', value: 25)`
38
38
 
39
39
 
40
40
  `CW.report_all` has a similar method signature, but takes an array of values, and a corresponding array indicating how many times each value occurred during the period.
41
41
 
42
42
  ### CW.report_all Required Parameters
43
43
 
44
- * `metric_name`: The name of the metric.
44
+ * `name`: The name of the metric.
45
45
  * `values`: Array of values for the data points being reported.
46
46
  * `counts`: Array of numbers indicating the number of times each value occurred during the period. The length of this array should match the length of the `values` array.
47
47
 
48
- E.g. `CW.report_all(metric_name: 'search_result_count', values: [25, 50, 65], counts: [1, 2, 1])`
48
+ E.g. `CW.report_all(name: 'search_result_count', values: [25, 50, 65], counts: [1, 2, 1])`
49
49
 
50
50
  ### Optional Parameters
51
51
 
@@ -53,9 +53,11 @@ Both reporting methods accept optional parameters, which are detailed below, alo
53
53
 
54
54
  * `unit`: The unit of measure for this data point. Units help provide conceptual meaning to your data, but CloudWatch attaches no significance to a unit internally. Common values are `Seconds`, `Kilobytes`, `Percent`, `Count`, `Kilobytes/Second`. Default value is `None`. A full list of available units is available at `CloudwatchMetrics.Units`.
55
55
  * `namespace`: Override the namespace set in the initializer. Default is `nil`
56
- * `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`.
56
+ * `dimensions`: A hash 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`.
57
57
  * `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.
58
58
 
59
+ E.g. `CW.report(name: 'search_result_count', value: 25, unit: CW.COUNT, namespace: 'custom_namespace', dimensions: { group: 'A', subgroup: 'B' }, timeStamp: Time.current - 1.day)`
60
+
59
61
  ### Local development
60
62
 
61
63
  By default, `CloudWatchMetrics` only publishes to Cloudwatch in the production environment. In other environments it will write to the configured logger. These settings can be changed in the initializer.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CloudwatchMetrics
4
- VERSION = '0.1.15'
4
+ VERSION = '0.1.17'
5
5
  end
@@ -16,27 +16,27 @@ module CloudwatchMetrics
16
16
  end
17
17
 
18
18
  def record(
19
- metric_name:, value:, unit: nil, namespace: configuration.namespace, dimensions: [], timestamp: nil
19
+ name:, value:, unit: nil, namespace: configuration.namespace, dimensions: [], timestamp: nil
20
20
  )
21
21
  metric_data = [{
22
- metric_name: metric_name,
22
+ metric_name: name,
23
23
  value: value,
24
24
  unit: unit,
25
- dimensions: dimensions,
25
+ dimensions: map_dimensions(dimensions),
26
26
  timestamp: timestamp
27
27
  }]
28
28
  put_data(namespace: namespace, metric_data: metric_data)
29
29
  end
30
30
 
31
31
  def record_all(
32
- metric_name:, values:, counts:, unit: nil, namespace: configuration.namespace, dimensions: [], timestamp: nil
32
+ name:, values:, counts:, unit: nil, namespace: configuration.namespace, dimensions: [], timestamp: nil
33
33
  )
34
34
  metric_data = [{
35
- metric_name: metric_name,
35
+ metric_name: name,
36
36
  values: values,
37
37
  counts: counts,
38
38
  unit: unit,
39
- dimensions: dimensions,
39
+ dimensions: map_dimensions(dimensions),
40
40
  timestamp: timestamp
41
41
  }]
42
42
  put_data(namespace: namespace, metric_data: metric_data)
@@ -70,6 +70,21 @@ module CloudwatchMetrics
70
70
  def environment
71
71
  ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
72
72
  end
73
+
74
+ # convert key/value hash to format expected by AWS SDK
75
+ def map_dimensions(dimensions)
76
+ return [] if dimensions.nil?
77
+
78
+ mapped_values = []
79
+ dimensions.keys.each do |key|
80
+ mapped_values << {
81
+ name: key,
82
+ value: dimensions[key]
83
+ }
84
+ end
85
+
86
+ mapped_values
87
+ end
73
88
  end
74
89
  end
75
90
 
@@ -14,14 +14,14 @@ CloudwatchMetrics.configure do |config|
14
14
 
15
15
  # This is an optional configuration to set the region that
16
16
  # the metrics will be published to. This is useful if you want to publish
17
- # to a region other than the default region for your AWS credentials.
17
+ # to a region other than the default region for your AWS configuration.
18
18
  # config.region = 'us-east-1'
19
19
 
20
20
  # By default metrics will only be published in the production environment.
21
21
  # In all other environments metrics will be logged.
22
22
  # You can override this behavior by specifying an array of environments
23
23
  # that you want to publish metrics in.
24
- # config.publish_environments = %w[production staging]
24
+ # config.publish_environments = %w[production development]
25
25
 
26
26
  # This is an optional configuration to set the logger that
27
27
  # the metrics will be logged to. Defaults to `Logger.new(STDOUT)`.
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.15
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Puckett