sensu-plugins-aws 11.2.0 → 11.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95656236ef931e5742bd4ebc17069882270b5ef59680175ebeaa12b12b468ac5
4
- data.tar.gz: 838795f8732303b1dcc52b754a911cfb85d018cd8d26a4740dfa635ffcad40dc
3
+ metadata.gz: 109b5702307162daa4308481bf6bd3e5499b511788b08465d8ad224f7b8891af
4
+ data.tar.gz: 6959a863fd1c6e245dd5bdb442a13e9cc944455dbb58c1a2acbd2776dd0040ba
5
5
  SHA512:
6
- metadata.gz: a3e808d291336ea960be67dd9712b27dd9b688a9a16ebb85fd04b35e45455a0080704d8c95b6744e92e32d13ed7e2f5241587f1565540a8b62c63cde3458b696
7
- data.tar.gz: fbf8e8d6b32217d8ba03d319830488482c8f9d0cc53118b2cf27f235ae7bc4abfa4a49bc37c0103e435929767b11236d00394362e7f6c6d240b091b2d44165b1
6
+ metadata.gz: 9f5e80b940aa669af45a50cf44bd5c5c4aed139c68c9418547ac01b024f5bff580c3fbafad828c202ba434a362127e058224dcb6818f87458e067a12ff4524f9
7
+ data.tar.gz: 2f8ee12d7f54b1bc4dedc841aa13da613dba7f4cb1310bd65a2401a4dd34fb62364b0a98bd0eca21864103b32f29a089c99f08cca0dc2ae2019c2e05d678a7cd
data/CHANGELOG.md CHANGED
@@ -5,7 +5,11 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
- ## [11.1.0] - 2018-11-22
8
+ ## [11.3.0] - 2018-03-22
9
+ ### Added
10
+ - Added ability to get metrics from cloudfront (@yuri-zubov sponsored by Actility, https://www.actility.com)
11
+
12
+ ## [11.2.0] - 2018-11-22
9
13
  ### Added
10
14
  - check-s3-bucket-visibility.rb: option `--exclude-regex-filter` to allow using regex to filter out undesired buckets from the results (@majormoses)
11
15
 
@@ -451,7 +455,8 @@ WARNING: This release contains major breaking changes that will impact all user
451
455
  ### Added
452
456
  - initial release
453
457
 
454
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/11.2.0...HEAD
458
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/11.3.0...HEAD
459
+ [11.3.0]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/11.2.0...11.3.0
455
460
  [11.2.0]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/11.1.0...11.2.0
456
461
  [11.1.0]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/11.0.0...11.1.0
457
462
  [11.0.0]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/10.2.0...11.0.0
@@ -0,0 +1,146 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # cloudfront-metrics
4
+ #
5
+ # DESCRIPTION:
6
+ # Gets latency metrics from CloudWatch and puts them in Graphite for longer term storage
7
+ #
8
+ # OUTPUT:
9
+ # metric-data
10
+ #
11
+ # PLATFORMS:
12
+ # Linux
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: aws-sdk
16
+ # gem: sensu-plugin
17
+ # gem: sensu-plugin-aws
18
+ # gem: time
19
+ #
20
+ # USAGE:
21
+ #
22
+ #
23
+ # NOTES:
24
+ #
25
+ # LICENSE:
26
+ # Zubov Yuri <yury.zubau@gmail.com> sponsored by Actility, https://www.actility.com
27
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
28
+ # for details.
29
+ #
30
+
31
+ require 'sensu-plugin/metric/cli'
32
+ require 'aws-sdk'
33
+ require 'sensu-plugins-aws'
34
+ require 'time'
35
+
36
+ class CloudFrontMetrics < Sensu::Plugin::Metric::CLI::Graphite
37
+ include Common
38
+ option :distribution_id,
39
+ description: 'Distribution id of Cloudfront',
40
+ short: '-d DISTRIBUTION_ID',
41
+ long: '--distribution_id DISTRIBUTION_ID'
42
+
43
+ option :scheme,
44
+ description: 'Metric naming scheme, text to prepend to metric',
45
+ short: '-s SCHEME',
46
+ long: '--scheme SCHEME',
47
+ default: 'aws.cloudfront'
48
+
49
+ option :aws_region,
50
+ short: '-r AWS_REGION',
51
+ long: '--aws-region REGION',
52
+ description: 'AWS Region (defaults to us-east-1).',
53
+ default: 'us-east-1'
54
+
55
+ option :metric,
56
+ description: 'Metric to fetch',
57
+ short: '-m METRIC',
58
+ long: '--metric',
59
+ in: %w[Requests BytesDownloaded BytesUploaded TotalErrorRate 4xxErrorRate 5xxErrorRate]
60
+
61
+ option :end_time,
62
+ short: '-t T',
63
+ long: '--end-time TIME',
64
+ default: Time.now,
65
+ proc: proc { |a| Time.parse a },
66
+ description: 'CloudWatch metric statistics end time'
67
+
68
+ option :period,
69
+ short: '-p N',
70
+ long: '--period SECONDS',
71
+ default: 60,
72
+ proc: proc(&:to_i),
73
+ description: 'CloudWatch metric statistics period'
74
+
75
+ def cloud_watch
76
+ @cloud_watch ||= Aws::CloudWatch::Client.new
77
+ end
78
+
79
+ def cloud_watch_metric(metric_name, value, distribution_id)
80
+ cloud_watch.get_metric_statistics(
81
+ namespace: 'AWS/CloudFront',
82
+ metric_name: metric_name,
83
+ dimensions: [
84
+ {
85
+ name: 'Region',
86
+ value: 'Global'
87
+ },
88
+ {
89
+ name: 'DistributionId',
90
+ value: distribution_id
91
+ }
92
+ ],
93
+ statistics: [value],
94
+ start_time: config[:end_time] - config[:period],
95
+ end_time: config[:end_time],
96
+ period: config[:period]
97
+ )
98
+ end
99
+
100
+ def distribution_list
101
+ list_metrics = cloud_watch.list_metrics(
102
+ namespace: 'AWS/CloudFront'
103
+ ).metrics
104
+
105
+ list_metrics = list_metrics.select { |e| e.metric_name == config[:metric] } unless config[:metric].nil?
106
+
107
+ list_metrics.reduce(Set.new) do |result, item|
108
+ result << item.dimensions.find { |element| element.name == 'DistributionId' }.value
109
+ end
110
+ end
111
+
112
+ def print_statistics(distribution_id, statistics)
113
+ statistics.each do |key, static|
114
+ r = cloud_watch_metric(key, static, distribution_id)
115
+ keys = [config[:scheme]]
116
+ keys.concat [distribution_id, key, static]
117
+ output(keys.join('.'), r[:datapoints].first[static.downcase]) unless r[:datapoints].first.nil?
118
+ end
119
+ end
120
+
121
+ def run
122
+ statistic = {
123
+ 'Requests' => 'Sum',
124
+ 'BytesDownloaded' => 'Sum',
125
+ 'BytesUploaded' => 'Sum',
126
+ 'TotalErrorRate' => 'Average',
127
+ '4xxErrorRate' => 'Average',
128
+ '5xxErrorRate' => 'Average'
129
+ }
130
+
131
+ unless config[:metric].nil?
132
+ statistic.select! { |key, _| key == config[:metric] }
133
+ end
134
+
135
+ begin
136
+ if config[:distribution_id].nil?
137
+ distribution_list.each do |distribution|
138
+ print_statistics(distribution, statistic)
139
+ end
140
+ else
141
+ print_statistics(config[:distribution_id], statistic)
142
+ end
143
+ ok
144
+ end
145
+ end
146
+ end
@@ -1,4 +1,3 @@
1
-
2
1
  module CloudwatchCommon
3
2
  include Common
4
3
 
@@ -1,7 +1,7 @@
1
1
  module SensuPluginsAWS
2
2
  module Version
3
3
  MAJOR = 11
4
- MINOR = 2
4
+ MINOR = 3
5
5
  PATCH = 0
6
6
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 11.2.0
4
+ version: 11.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu-Plugins and contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-22 00:00:00.000000000 Z
11
+ date: 2018-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-plugin
@@ -323,6 +323,7 @@ executables:
323
323
  - metrics-asg.rb
324
324
  - metrics-autoscaling-instance-count.rb
325
325
  - metrics-billing.rb
326
+ - metrics-cloudfront.rb
326
327
  - metrics-ec2-count.rb
327
328
  - metrics-ec2-filter.rb
328
329
  - metrics-elasticache.rb
@@ -405,6 +406,7 @@ files:
405
406
  - bin/metrics-asg.rb
406
407
  - bin/metrics-autoscaling-instance-count.rb
407
408
  - bin/metrics-billing.rb
409
+ - bin/metrics-cloudfront.rb
408
410
  - bin/metrics-ec2-count.rb
409
411
  - bin/metrics-ec2-filter.rb
410
412
  - bin/metrics-elasticache.rb