sensu-plugins-aws 3.2.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,135 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # rds-metrics
4
+ #
5
+ # DESCRIPTION:
6
+ # Gets RDS 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: sensu-plugin
16
+ #
17
+ # USAGE:
18
+ # rds-metrics --aws-region eu-west-1
19
+ # rds-metrics --aws-region eu-west-1 --name sr2x8pbti0eon1
20
+ #
21
+ # NOTES:
22
+ # Returns all RDS statistics for all RDS instances in this account unless you specify --name
23
+ #
24
+ # LICENSE:
25
+ # Peter Hoppe <peter.hoppe.extern@bertelsmann.de>
26
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
27
+ # for details.
28
+ #
29
+
30
+ require 'sensu-plugins-aws'
31
+ require 'sensu-plugin/metric/cli'
32
+ require 'aws-sdk'
33
+ require 'time'
34
+
35
+ class RDSMetrics < Sensu::Plugin::Metric::CLI::Graphite
36
+ include Common
37
+ option :aws_region,
38
+ short: '-r AWS_REGION',
39
+ long: '--aws-region REGION',
40
+ description: 'AWS Region (defaults to us-east-1).',
41
+ default: ENV['AWS_REGION']
42
+
43
+ option :db_instance_id,
44
+ short: '-i N',
45
+ long: '--db-instance-id NAME',
46
+ description: 'DB instance identifier'
47
+
48
+ option :end_time,
49
+ short: '-t T',
50
+ long: '--end-time TIME',
51
+ default: Time.now,
52
+ proc: proc { |a| Time.parse a },
53
+ description: 'CloudWatch metric statistics end time'
54
+
55
+ option :period,
56
+ short: '-p N',
57
+ long: '--period SECONDS',
58
+ default: 60,
59
+ proc: proc(&:to_i),
60
+ description: 'CloudWatch metric statistics period'
61
+
62
+ option :statistics,
63
+ short: '-S N',
64
+ long: '--statistics NAME',
65
+ default: :average,
66
+ proc: proc { |a| a.downcase.intern },
67
+ description: 'CloudWatch statistics method'
68
+
69
+ def rds
70
+ @rds = Aws::RDS::Client.new
71
+ end
72
+
73
+ def cloud_watch
74
+ @cloud_watch = Aws::CloudWatch::Client.new
75
+ end
76
+
77
+ def find_db_instance(id)
78
+ db = rds.describe_db_instances.db_instances.detect { |db_instance| db_instance.db_instance_identifier == id }
79
+ unknown 'DB instance not found.' if db.nil?
80
+ db
81
+ end
82
+
83
+ def cloud_watch_metric(metric_name, value)
84
+ cloud_watch.get_metric_statistics(
85
+ namespace: 'AWS/RDS',
86
+ metric_name: metric_name,
87
+ dimensions: [
88
+ {
89
+ name: 'DBInstanceIdentifier',
90
+ value: value
91
+ }
92
+ ],
93
+ start_time: config[:end_time] - config[:period],
94
+ end_time: config[:end_time],
95
+ statistics: [config[:statistics].to_s.capitalize],
96
+ period: config[:period]
97
+ )
98
+ end
99
+
100
+ def run
101
+ statistic_type = {
102
+ 'CPUUtilization' => 'Average',
103
+ 'DatabaseConnections' => 'Average',
104
+ 'FreeStorageSpace' => 'Average',
105
+ 'ReadIOPS' => 'Average',
106
+ 'ReadLatency' => 'Average',
107
+ 'ReadThroughput' => 'Average',
108
+ 'WriteIOPS' => 'Average',
109
+ 'WriteLatency' => 'Average',
110
+ 'WriteThroughput' => 'Average',
111
+ 'ReplicaLag' => 'Average',
112
+ 'SwapUsage' => 'Average',
113
+ 'BinLogDiskUsage' => 'Average',
114
+ 'DiskQueueDepth' => 'Average'
115
+ }
116
+
117
+ @db_instance = find_db_instance config[:db_instance_id]
118
+ @message = "#{config[:db_instance_id]}: "
119
+
120
+ result = {}
121
+
122
+ rdsname = @db_instance.db_instance_identifier
123
+
124
+ statistic_type.each do |key, _value|
125
+ r = cloud_watch_metric key, rdsname
126
+ result[rdsname + '.' + key] = r[:datapoints][0] unless r[:datapoints][0].nil?
127
+ end
128
+ unless result.nil?
129
+ result.each do |key, value|
130
+ output key.downcase.to_s, value.average, value[:timestamp].to_i
131
+ end
132
+ end
133
+ exit
134
+ end
135
+ end
data/bin/metrics-s3.rb ADDED
@@ -0,0 +1,105 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # s3-metrics
4
+ #
5
+ # DESCRIPTION:
6
+ # Gets S3 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-plugins-aws
18
+ #
19
+ # USAGE:
20
+ # metrics-s3.rb -r us-west-2
21
+ #
22
+ # NOTES:
23
+ #
24
+ # LICENSE:
25
+ # Copyright (c) 2015, Olivier Bazoud, olivier.bazoud@gmail.com
26
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
27
+ # for details.
28
+ #
29
+
30
+ require 'sensu-plugin/metric/cli'
31
+ require 'aws-sdk'
32
+ require 'sensu-plugins-aws'
33
+
34
+ class S3Metrics < Sensu::Plugin::Metric::CLI::Graphite
35
+ include Common
36
+
37
+ option :aws_region,
38
+ short: '-r AWS_REGION',
39
+ long: '--aws-region REGION',
40
+ description: 'AWS Region (defaults to us-east-1).',
41
+ default: 'us-east-1'
42
+
43
+ option :scheme,
44
+ description: 'Metric naming scheme, text to prepend to metric',
45
+ short: '-s SCHEME',
46
+ long: '--scheme SCHEME',
47
+ default: 'sensu.aws.s3.buckets'
48
+
49
+ def run
50
+ begin
51
+ s3 = Aws::S3::Client.new(aws_config)
52
+ list_buckets = s3.list_buckets
53
+
54
+ cw = Aws::CloudWatch::Client.new(aws_config)
55
+
56
+ now = Time.now
57
+ list_buckets.buckets.each do |bucket|
58
+ bucket_name = bucket.name.tr('.', '_')
59
+ bucket_size_bytes = cw.get_metric_statistics(
60
+ namespace: 'AWS/S3',
61
+ metric_name: 'BucketSizeBytes',
62
+ dimensions: [
63
+ {
64
+ name: 'BucketName',
65
+ value: bucket.name
66
+ }, {
67
+ name: 'StorageType',
68
+ value: 'StandardStorage'
69
+ }
70
+ ],
71
+ start_time: (now.utc - 24 * 60 * 60).iso8601,
72
+ end_time: now.utc.iso8601,
73
+ period: 24 * 60 * 60,
74
+ statistics: ['Average'],
75
+ unit: 'Bytes'
76
+ )
77
+ output "#{config[:scheme]}.#{bucket_name}.bucket_size_bytes", bucket_size_bytes[:datapoints][0].average, now.to_i unless bucket_size_bytes[:datapoints][0].nil?
78
+
79
+ number_of_objects = cw.get_metric_statistics(
80
+ namespace: 'AWS/S3',
81
+ metric_name: 'NumberOfObjects',
82
+ dimensions: [
83
+ {
84
+ name: 'BucketName',
85
+ value: bucket.name
86
+ }, {
87
+ name: 'StorageType',
88
+ value: 'AllStorageTypes'
89
+ }
90
+ ],
91
+ start_time: (now.utc - 24 * 60 * 60).iso8601,
92
+ end_time: now.utc.iso8601,
93
+ period: 24 * 60 * 60,
94
+ statistics: ['Average'],
95
+ unit: 'Count'
96
+ )
97
+ output "#{config[:scheme]}.#{bucket_name}.number_of_objects", number_of_objects[:datapoints][0].average, now.to_i unless number_of_objects[:datapoints][0].nil?
98
+ end
99
+
100
+ rescue => e
101
+ critical "Error: exception: #{e}"
102
+ end
103
+ ok
104
+ end
105
+ end
@@ -1,3 +1,4 @@
1
1
  require 'sensu-plugins-aws/version'
2
2
  require 'sensu-plugins-aws/common'
3
3
  require 'sensu-plugins-aws/filter'
4
+ require 'sensu-plugins-aws/cloudwatch-common'
@@ -1,6 +1,7 @@
1
- require 'aws-sdk'
2
1
 
3
2
  module CloudwatchCommon
3
+ include Common
4
+
4
5
  def client
5
6
  Aws::CloudWatch::Client.new
6
7
  end
@@ -1,8 +1,8 @@
1
1
  module SensuPluginsAWS
2
2
  module Version
3
- MAJOR = 3
4
- MINOR = 2
5
- PATCH = 1
3
+ MAJOR = 4
4
+ MINOR = 0
5
+ PATCH = 0
6
6
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
7
7
  end
8
8
  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: 3.2.1
4
+ version: 4.0.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: 2016-08-11 00:00:00.000000000 Z
11
+ date: 2016-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0.10'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rainbow
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "<"
172
+ - !ruby/object:Gem::Version
173
+ version: 2.2.0
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "<"
179
+ - !ruby/object:Gem::Version
180
+ version: 2.2.0
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: rake
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -242,15 +256,19 @@ description: |-
242
256
  for EC2, SES, and SNS.
243
257
  email: "<sensu-users@googlegroups.com>"
244
258
  executables:
259
+ - check-asg-instances-created.rb
260
+ - check-asg-instances-inservice.rb
245
261
  - check-autoscaling-cpucredits.rb
246
262
  - check-beanstalk-elb-metric.rb
247
263
  - check-beanstalk-health.rb
248
264
  - check-certificate-expiry.rb
265
+ - check-cloudfront-tag.rb
249
266
  - check-cloudwatch-alarm.rb
250
267
  - check-cloudwatch-metric.rb
251
268
  - check-configservice-rules.rb
252
269
  - check-dynamodb-capacity.rb
253
270
  - check-dynamodb-throttle.rb
271
+ - check-ebs-burst-limit.rb
254
272
  - check-ebs-snapshots.rb
255
273
  - check-ec2-cpu_balance.rb
256
274
  - check-ec2-filter.rb
@@ -262,6 +280,7 @@ executables:
262
280
  - check-elb-health-fog.rb
263
281
  - check-elb-health-sdk.rb
264
282
  - check-elb-health.rb
283
+ - check-elb-instances-inservice.rb
265
284
  - check-elb-latency.rb
266
285
  - check-elb-nodes.rb
267
286
  - check-elb-sum-requests.rb
@@ -278,8 +297,10 @@ executables:
278
297
  - check-redshift-events.rb
279
298
  - check-reserved-instances.rb
280
299
  - check-route.rb
300
+ - check-route53-domain-expiration.rb
281
301
  - check-s3-bucket.rb
282
302
  - check-s3-object.rb
303
+ - check-s3-tag.rb
283
304
  - check-sensu-client.rb
284
305
  - check-ses-limit.rb
285
306
  - check-ses-statistics.rb
@@ -294,13 +315,17 @@ executables:
294
315
  - handler-scale-asg-up.rb
295
316
  - handler-ses.rb
296
317
  - handler-sns.rb
318
+ - metrics-asg.rb
297
319
  - metrics-autoscaling-instance-count.rb
320
+ - metrics-billing.rb
298
321
  - metrics-ec2-count.rb
299
322
  - metrics-ec2-filter.rb
300
323
  - metrics-elasticache.rb
301
324
  - metrics-elb-full.rb
302
325
  - metrics-elb.rb
303
326
  - metrics-emr-steps.rb
327
+ - metrics-rds.rb
328
+ - metrics-s3.rb
304
329
  - metrics-ses.rb
305
330
  - metrics-sqs.rb
306
331
  extensions: []
@@ -309,15 +334,19 @@ files:
309
334
  - CHANGELOG.md
310
335
  - LICENSE
311
336
  - README.md
337
+ - bin/check-asg-instances-created.rb
338
+ - bin/check-asg-instances-inservice.rb
312
339
  - bin/check-autoscaling-cpucredits.rb
313
340
  - bin/check-beanstalk-elb-metric.rb
314
341
  - bin/check-beanstalk-health.rb
315
342
  - bin/check-certificate-expiry.rb
343
+ - bin/check-cloudfront-tag.rb
316
344
  - bin/check-cloudwatch-alarm.rb
317
345
  - bin/check-cloudwatch-metric.rb
318
346
  - bin/check-configservice-rules.rb
319
347
  - bin/check-dynamodb-capacity.rb
320
348
  - bin/check-dynamodb-throttle.rb
349
+ - bin/check-ebs-burst-limit.rb
321
350
  - bin/check-ebs-snapshots.rb
322
351
  - bin/check-ec2-cpu_balance.rb
323
352
  - bin/check-ec2-filter.rb
@@ -329,6 +358,7 @@ files:
329
358
  - bin/check-elb-health-fog.rb
330
359
  - bin/check-elb-health-sdk.rb
331
360
  - bin/check-elb-health.rb
361
+ - bin/check-elb-instances-inservice.rb
332
362
  - bin/check-elb-latency.rb
333
363
  - bin/check-elb-nodes.rb
334
364
  - bin/check-elb-sum-requests.rb
@@ -345,8 +375,10 @@ files:
345
375
  - bin/check-redshift-events.rb
346
376
  - bin/check-reserved-instances.rb
347
377
  - bin/check-route.rb
378
+ - bin/check-route53-domain-expiration.rb
348
379
  - bin/check-s3-bucket.rb
349
380
  - bin/check-s3-object.rb
381
+ - bin/check-s3-tag.rb
350
382
  - bin/check-sensu-client.rb
351
383
  - bin/check-ses-limit.rb
352
384
  - bin/check-ses-statistics.rb
@@ -362,13 +394,17 @@ files:
362
394
  - bin/handler-scale-asg-up.rb
363
395
  - bin/handler-ses.rb
364
396
  - bin/handler-sns.rb
397
+ - bin/metrics-asg.rb
365
398
  - bin/metrics-autoscaling-instance-count.rb
399
+ - bin/metrics-billing.rb
366
400
  - bin/metrics-ec2-count.rb
367
401
  - bin/metrics-ec2-filter.rb
368
402
  - bin/metrics-elasticache.rb
369
403
  - bin/metrics-elb-full.rb
370
404
  - bin/metrics-elb.rb
371
405
  - bin/metrics-emr-steps.rb
406
+ - bin/metrics-rds.rb
407
+ - bin/metrics-s3.rb
372
408
  - bin/metrics-ses.rb
373
409
  - bin/metrics-sqs.rb
374
410
  - lib/sensu-plugins-aws.rb
@@ -402,7 +438,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
402
438
  version: '0'
403
439
  requirements: []
404
440
  rubyforge_project:
405
- rubygems_version: 2.5.1
441
+ rubygems_version: 2.4.5
406
442
  signing_key:
407
443
  specification_version: 4
408
444
  summary: Sensu plugins for working with an AWS environment