sensu-plugins-aws-boutetnico 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/LICENSE +22 -0
- data/README.md +333 -0
- data/bin/check-alb-target-group-health.rb +100 -0
- data/bin/check-asg-instances-created.rb +129 -0
- data/bin/check-asg-instances-inservice.rb +109 -0
- data/bin/check-autoscaling-cpucredits.rb +160 -0
- data/bin/check-beanstalk-elb-metric.rb +123 -0
- data/bin/check-beanstalk-health.rb +123 -0
- data/bin/check-certificate-expiry.rb +123 -0
- data/bin/check-cloudfront-tag.rb +70 -0
- data/bin/check-cloudwatch-alarm.rb +102 -0
- data/bin/check-cloudwatch-alarms.rb +89 -0
- data/bin/check-cloudwatch-composite-metric.rb +199 -0
- data/bin/check-cloudwatch-metric.rb +123 -0
- data/bin/check-configservice-rules.rb +76 -0
- data/bin/check-direct-connect-virtual-interfaces.rb +84 -0
- data/bin/check-dynamodb-capacity.rb +194 -0
- data/bin/check-dynamodb-throttle.rb +188 -0
- data/bin/check-ebs-burst-limit.rb +143 -0
- data/bin/check-ebs-snapshots.rb +104 -0
- data/bin/check-ec2-cpu_balance.rb +139 -0
- data/bin/check-ec2-filter.rb +190 -0
- data/bin/check-ec2-network.rb +133 -0
- data/bin/check-ecs-service-health.rb +155 -0
- data/bin/check-efs-metric.rb +145 -0
- data/bin/check-eip-allocation.rb +64 -0
- data/bin/check-elasticache-failover.rb +113 -0
- data/bin/check-elb-certs.rb +132 -0
- data/bin/check-elb-health-fog.rb +114 -0
- data/bin/check-elb-health-sdk.rb +176 -0
- data/bin/check-elb-health.rb +116 -0
- data/bin/check-elb-instances-inservice.rb +103 -0
- data/bin/check-elb-latency.rb +166 -0
- data/bin/check-elb-nodes.rb +133 -0
- data/bin/check-elb-sum-requests.rb +157 -0
- data/bin/check-emr-cluster.rb +144 -0
- data/bin/check-emr-steps.rb +90 -0
- data/bin/check-eni-status.rb +110 -0
- data/bin/check-expiring-reservations.rb +117 -0
- data/bin/check-instance-events.rb +154 -0
- data/bin/check-instance-health.rb +108 -0
- data/bin/check-instance-reachability.rb +107 -0
- data/bin/check-instances-count.rb +94 -0
- data/bin/check-kms-key.rb +73 -0
- data/bin/check-rds-events.rb +141 -0
- data/bin/check-rds-pending.rb +91 -0
- data/bin/check-rds.rb +382 -0
- data/bin/check-redshift-events.rb +108 -0
- data/bin/check-reserved-instances.rb +80 -0
- data/bin/check-route.rb +122 -0
- data/bin/check-route53-domain-expiration.rb +78 -0
- data/bin/check-s3-bucket-visibility.rb +176 -0
- data/bin/check-s3-bucket.rb +86 -0
- data/bin/check-s3-object.rb +205 -0
- data/bin/check-s3-tag.rb +70 -0
- data/bin/check-sensu-client.rb +184 -0
- data/bin/check-ses-limit.rb +89 -0
- data/bin/check-ses-statistics.rb +149 -0
- data/bin/check-sns-subscriptions.rb +52 -0
- data/bin/check-sqs-messages.rb +168 -0
- data/bin/check-subnet-ip-consumption.rb +234 -0
- data/bin/check-trustedadvisor-service-limits.rb +90 -0
- data/bin/check-vpc-nameservers.rb +87 -0
- data/bin/check-vpc-vpn.rb +98 -0
- data/bin/handler-ec2_node.rb +241 -0
- data/bin/handler-scale-asg-down.rb +131 -0
- data/bin/handler-scale-asg-up.rb +131 -0
- data/bin/handler-ses.rb +107 -0
- data/bin/handler-sns.rb +64 -0
- data/bin/metrics-asg.rb +156 -0
- data/bin/metrics-autoscaling-instance-count.rb +101 -0
- data/bin/metrics-billing.rb +97 -0
- data/bin/metrics-cloudfront.rb +159 -0
- data/bin/metrics-ec2-count.rb +137 -0
- data/bin/metrics-ec2-filter.rb +97 -0
- data/bin/metrics-elasticache.rb +166 -0
- data/bin/metrics-elb.rb +169 -0
- data/bin/metrics-emr-steps.rb +82 -0
- data/bin/metrics-rds.rb +153 -0
- data/bin/metrics-reservation-utilization.rb +84 -0
- data/bin/metrics-s3.rb +107 -0
- data/bin/metrics-ses.rb +62 -0
- data/bin/metrics-sqs.rb +98 -0
- data/bin/metrics-waf.rb +111 -0
- data/lib/sensu-plugins-aws.rb +4 -0
- data/lib/sensu-plugins-aws/cloudwatch-common.rb +92 -0
- data/lib/sensu-plugins-aws/common.rb +35 -0
- data/lib/sensu-plugins-aws/filter.rb +47 -0
- data/lib/sensu-plugins-aws/version.rb +8 -0
- metadata +456 -0
data/bin/metrics-s3.rb
ADDED
@@ -0,0 +1,107 @@
|
|
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 bucket_size(size_size = 'bytes'); end
|
50
|
+
|
51
|
+
def run
|
52
|
+
begin
|
53
|
+
s3 = Aws::S3::Client.new(aws_config)
|
54
|
+
list_buckets = s3.list_buckets
|
55
|
+
|
56
|
+
cw = Aws::CloudWatch::Client.new(aws_config)
|
57
|
+
|
58
|
+
now = Time.now
|
59
|
+
# TODO: come back and refactor this
|
60
|
+
list_buckets.buckets.each do |bucket| # rubocop:disable Metrics/BlockLength)
|
61
|
+
bucket_name = bucket.name.tr('.', '_')
|
62
|
+
bucket_size_bytes = cw.get_metric_statistics(
|
63
|
+
namespace: 'AWS/S3',
|
64
|
+
metric_name: 'BucketSizeBytes',
|
65
|
+
dimensions: [
|
66
|
+
{
|
67
|
+
name: 'BucketName',
|
68
|
+
value: bucket.name
|
69
|
+
}, {
|
70
|
+
name: 'StorageType',
|
71
|
+
value: 'StandardStorage'
|
72
|
+
}
|
73
|
+
],
|
74
|
+
start_time: (now.utc - 24 * 60 * 60).iso8601,
|
75
|
+
end_time: now.utc.iso8601,
|
76
|
+
period: 24 * 60 * 60,
|
77
|
+
statistics: ['Average'],
|
78
|
+
unit: 'Bytes'
|
79
|
+
)
|
80
|
+
output "#{config[:scheme]}.#{bucket_name}.bucket_size_bytes", bucket_size_bytes[:datapoints][0].average, now.to_i unless bucket_size_bytes[:datapoints][0].nil?
|
81
|
+
|
82
|
+
number_of_objects = cw.get_metric_statistics(
|
83
|
+
namespace: 'AWS/S3',
|
84
|
+
metric_name: 'NumberOfObjects',
|
85
|
+
dimensions: [
|
86
|
+
{
|
87
|
+
name: 'BucketName',
|
88
|
+
value: bucket.name
|
89
|
+
}, {
|
90
|
+
name: 'StorageType',
|
91
|
+
value: 'AllStorageTypes'
|
92
|
+
}
|
93
|
+
],
|
94
|
+
start_time: (now.utc - 24 * 60 * 60).iso8601,
|
95
|
+
end_time: now.utc.iso8601,
|
96
|
+
period: 24 * 60 * 60,
|
97
|
+
statistics: ['Average'],
|
98
|
+
unit: 'Count'
|
99
|
+
)
|
100
|
+
output "#{config[:scheme]}.#{bucket_name}.number_of_objects", number_of_objects[:datapoints][0].average, now.to_i unless number_of_objects[:datapoints][0].nil?
|
101
|
+
end
|
102
|
+
rescue StandardError => e
|
103
|
+
critical "Error: exception: #{e}"
|
104
|
+
end
|
105
|
+
ok
|
106
|
+
end
|
107
|
+
end
|
data/bin/metrics-ses.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# metrics-ses
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# Lists SES send statistics
|
7
|
+
#
|
8
|
+
# OUTPUT:
|
9
|
+
# metric data
|
10
|
+
#
|
11
|
+
# DEPENDENCIES:
|
12
|
+
# gem: aws-sdk
|
13
|
+
# gem: sensu-plugin
|
14
|
+
#
|
15
|
+
# USAGE:
|
16
|
+
# metrics-ses.rb -r us-west-2
|
17
|
+
#
|
18
|
+
# This will list out the statistics for the most recent 15 minutes from SES
|
19
|
+
#
|
20
|
+
# NOTES:
|
21
|
+
#
|
22
|
+
# LICENSE:
|
23
|
+
# Brandon Smith <freedom@reardencode.com>
|
24
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
25
|
+
# for details.
|
26
|
+
|
27
|
+
require 'sensu-plugins-aws'
|
28
|
+
require 'sensu-plugin/metric/cli'
|
29
|
+
require 'aws-sdk'
|
30
|
+
|
31
|
+
class SesMetrics < Sensu::Plugin::Metric::CLI::Graphite
|
32
|
+
include Common
|
33
|
+
|
34
|
+
option :scheme,
|
35
|
+
description: 'Metric naming scheme, text to prepend to metric',
|
36
|
+
short: '-s SCHEME',
|
37
|
+
long: '--scheme SCHEME',
|
38
|
+
default: 'sensu.aws.ses'
|
39
|
+
|
40
|
+
option :aws_region,
|
41
|
+
short: '-r AWS_REGION',
|
42
|
+
long: '--aws-region REGION',
|
43
|
+
description: 'AWS Region (defaults to us-east-1).',
|
44
|
+
default: 'us-east-1'
|
45
|
+
|
46
|
+
def run
|
47
|
+
ses = Aws::SES::Client.new(aws_config)
|
48
|
+
begin
|
49
|
+
response = ses.get_send_statistics
|
50
|
+
|
51
|
+
unknown 'Empty response from AWS SES API' if response.empty? # Can this happen?
|
52
|
+
unknown 'No data points from AWS SES API' if response.send_data_points.empty?
|
53
|
+
|
54
|
+
data_point = response.send_data_points.sort_by(&:timestamp).last
|
55
|
+
output config[:scheme] + '.bounces', data_point.bounces
|
56
|
+
output config[:scheme] + '.rejects', data_point.rejects
|
57
|
+
output config[:scheme] + '.complaints', data_point.complaints
|
58
|
+
output config[:scheme] + '.delivery_attempts', data_point.delivery_attempts
|
59
|
+
end
|
60
|
+
ok
|
61
|
+
end
|
62
|
+
end
|
data/bin/metrics-sqs.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# metrics-sqs
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# Fetch SQS metrics
|
7
|
+
#
|
8
|
+
# OUTPUT:
|
9
|
+
# metric-data
|
10
|
+
#
|
11
|
+
# PLATFORMS:
|
12
|
+
# Linux
|
13
|
+
#
|
14
|
+
# DEPENDENCIES:
|
15
|
+
# gem: aws-sdk
|
16
|
+
# gem: sensu-plugin
|
17
|
+
#
|
18
|
+
# USAGE:
|
19
|
+
# metrics-sqs -q my_queue
|
20
|
+
# metrics-sqs -p queue_prefix_
|
21
|
+
#
|
22
|
+
# NOTES:
|
23
|
+
#
|
24
|
+
# LICENSE:
|
25
|
+
# Copyright 2015 Eric Heydrick <eheydrick@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 'sensu-plugins-aws'
|
32
|
+
require 'aws-sdk'
|
33
|
+
|
34
|
+
class SQSMetrics < Sensu::Plugin::Metric::CLI::Graphite
|
35
|
+
include Common
|
36
|
+
|
37
|
+
option :queue,
|
38
|
+
description: 'Name of the queue',
|
39
|
+
short: '-q QUEUE',
|
40
|
+
long: '--queue QUEUE',
|
41
|
+
default: ''
|
42
|
+
|
43
|
+
option :prefix,
|
44
|
+
description: 'Queue name prefix',
|
45
|
+
short: '-p PREFIX',
|
46
|
+
long: '--prefix PREFIX',
|
47
|
+
default: ''
|
48
|
+
|
49
|
+
option :scheme,
|
50
|
+
description: 'Metric naming scheme, text to prepend to metric',
|
51
|
+
short: '-s SCHEME',
|
52
|
+
long: '--scheme SCHEME',
|
53
|
+
default: ''
|
54
|
+
|
55
|
+
option :aws_region,
|
56
|
+
description: 'AWS Region (defaults to us-east-1).',
|
57
|
+
short: '-r AWS_REGION',
|
58
|
+
long: '--aws-region AWS_REGION',
|
59
|
+
default: 'us-east-1'
|
60
|
+
|
61
|
+
def aws_config
|
62
|
+
{ access_key_id: config[:aws_access_key],
|
63
|
+
secret_access_key: config[:aws_secret_access_key],
|
64
|
+
region: config[:aws_region] }
|
65
|
+
end
|
66
|
+
|
67
|
+
def scheme(queue_name)
|
68
|
+
scheme = config[:scheme].empty? ? 'aws.sqs.queue' : config[:scheme]
|
69
|
+
"#{scheme}.#{queue_name.tr('-', '_')}.message_count"
|
70
|
+
end
|
71
|
+
|
72
|
+
def record_queue_metrics(q_name, q)
|
73
|
+
output scheme(q_name), q.attributes['ApproximateNumberOfMessages'].to_i
|
74
|
+
output "#{scheme(q_name)}.delayed", q.attributes['ApproximateNumberOfMessagesDelayed'].to_i
|
75
|
+
output "#{scheme(q_name)}.not_visible", q.attributes['ApproximateNumberOfMessagesNotVisible'].to_i
|
76
|
+
end
|
77
|
+
|
78
|
+
def run
|
79
|
+
begin
|
80
|
+
sqs = Aws::SQS::Resource.new(aws_config)
|
81
|
+
|
82
|
+
if config[:prefix] == ''
|
83
|
+
if config[:queue] == ''
|
84
|
+
critical 'Error, either QUEUE or PREFIX must be specified'
|
85
|
+
end
|
86
|
+
|
87
|
+
record_queue_metrics(config[:queue], sqs.get_queue_by_name(queue_name: config[:queue]))
|
88
|
+
else
|
89
|
+
sqs.queues(queue_name_prefix: config[:prefix]).each do |q|
|
90
|
+
record_queue_metrics(q.attributes['QueueArn'].split(':').last, q)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
rescue StandardError => e
|
94
|
+
critical "Error fetching SQS queue metrics: #{e.message}"
|
95
|
+
end
|
96
|
+
ok
|
97
|
+
end
|
98
|
+
end
|
data/bin/metrics-waf.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# metrics-waf
|
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 WafMetrics < Sensu::Plugin::Metric::CLI::Generic
|
37
|
+
include CloudwatchCommon
|
38
|
+
|
39
|
+
option :scheme,
|
40
|
+
description: 'Metric naming scheme, text to prepend to metric',
|
41
|
+
short: '-s SCHEME',
|
42
|
+
long: '--scheme SCHEME',
|
43
|
+
default: 'aws.waf'
|
44
|
+
|
45
|
+
option :aws_region,
|
46
|
+
short: '-r AWS_REGION',
|
47
|
+
long: '--aws-region REGION',
|
48
|
+
description: 'AWS Region (defaults to us-east-1).',
|
49
|
+
default: 'us-east-1'
|
50
|
+
|
51
|
+
option :metric,
|
52
|
+
description: 'Metric to fetch',
|
53
|
+
short: '-m METRIC',
|
54
|
+
long: '--metric',
|
55
|
+
required: false,
|
56
|
+
in: %w[AllowedRequests BlockedRequests CountedRequests PassedRequests]
|
57
|
+
|
58
|
+
option :end_time,
|
59
|
+
short: '-t T',
|
60
|
+
long: '--end-time TIME',
|
61
|
+
default: Time.now,
|
62
|
+
proc: proc { |a| Time.parse a },
|
63
|
+
description: 'CloudWatch metric statistics end time'
|
64
|
+
|
65
|
+
option :period,
|
66
|
+
short: '-p N',
|
67
|
+
long: '--period SECONDS',
|
68
|
+
default: 60,
|
69
|
+
proc: proc(&:to_i),
|
70
|
+
description: 'CloudWatch metric statistics period'
|
71
|
+
|
72
|
+
def print_statistics(statistics, config)
|
73
|
+
statistics.each do |key, stats|
|
74
|
+
r = client.get_metric_statistics(metrics_request(config).merge(metric_name: key, statistics: [stats]))
|
75
|
+
keys = [config[:scheme]]
|
76
|
+
keys.concat([key, stats])
|
77
|
+
unless r[:datapoints].first.nil?
|
78
|
+
output metric_name: keys.join('.'), value: r[:datapoints].first[stats.downcase]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def run
|
84
|
+
statistic = {
|
85
|
+
'AllowedRequests' => 'Sum',
|
86
|
+
'BlockedRequests' => 'Sum',
|
87
|
+
'CountedRequests' => 'Sum',
|
88
|
+
'PassedRequests' => 'Sum'
|
89
|
+
}
|
90
|
+
|
91
|
+
unless config[:metric].nil?
|
92
|
+
statistic.select! { |key, _| key == config[:metric] }
|
93
|
+
end
|
94
|
+
|
95
|
+
new_config = config.clone
|
96
|
+
new_config[:namespace] = 'WAF'
|
97
|
+
new_config[:dimensions] = [
|
98
|
+
{
|
99
|
+
name: 'WebACL',
|
100
|
+
value: 'SecurityAutomationsMaliciousRequesters'
|
101
|
+
},
|
102
|
+
{
|
103
|
+
name: 'Rule',
|
104
|
+
value: 'ALL'
|
105
|
+
}
|
106
|
+
]
|
107
|
+
|
108
|
+
print_statistics(statistic, new_config)
|
109
|
+
ok
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module CloudwatchCommon
|
2
|
+
include Common
|
3
|
+
|
4
|
+
def client
|
5
|
+
@client ||= Aws::CloudWatch::Client.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def read_value(resp, stats)
|
9
|
+
if extended_stats? stats
|
10
|
+
resp.datapoints.sort_by(&:timestamp).last.extended_statistics[stats]
|
11
|
+
else
|
12
|
+
resp.datapoints.sort_by(&:timestamp).last.send(stats.downcase)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def resp_has_no_data(resp, stats)
|
17
|
+
resp.datapoints.nil? || resp.datapoints.empty? || resp.datapoints.first.nil? || read_value(resp, stats).nil?
|
18
|
+
end
|
19
|
+
|
20
|
+
def compare(value, threshold, compare_method)
|
21
|
+
case compare_method
|
22
|
+
when 'greater'
|
23
|
+
value > threshold
|
24
|
+
when 'less'
|
25
|
+
value < threshold
|
26
|
+
when 'not'
|
27
|
+
value != threshold
|
28
|
+
else
|
29
|
+
value == threshold
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def extended_stats?(stats)
|
34
|
+
stats[/p\d+\.\d+|p\d+/] # Check for percentile format
|
35
|
+
end
|
36
|
+
|
37
|
+
def metrics_request(config)
|
38
|
+
request = {
|
39
|
+
namespace: config[:namespace],
|
40
|
+
metric_name: config[:metric_name],
|
41
|
+
dimensions: config[:dimensions],
|
42
|
+
start_time: Time.now - config[:period] * 10,
|
43
|
+
end_time: Time.now,
|
44
|
+
period: config[:period],
|
45
|
+
unit: config[:unit]
|
46
|
+
}
|
47
|
+
stats_key = extended_stats?(config[:statistics]) ? :extended_statistics : :statistics
|
48
|
+
request[stats_key] = [config[:statistics]]
|
49
|
+
request
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_metric(metric)
|
53
|
+
client.get_metric_statistics(composite_metrics_request(metric))
|
54
|
+
end
|
55
|
+
|
56
|
+
def composite_metrics_request(metric)
|
57
|
+
## config is a class variable but don't want to change signature
|
58
|
+
metrics_request(config).merge(metric_name: metric)
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.parse_dimensions(dimension_string)
|
62
|
+
dimension_string.split(',')
|
63
|
+
.collect { |d| d.split '=' }
|
64
|
+
.collect { |a| { name: a[0], value: a[1] } }
|
65
|
+
end
|
66
|
+
|
67
|
+
def dimension_string
|
68
|
+
config[:dimensions].map { |d| "#{d[:name]}=#{d[:value]}" }.join('&')
|
69
|
+
end
|
70
|
+
|
71
|
+
def check(config)
|
72
|
+
resp = client.get_metric_statistics(metrics_request(config))
|
73
|
+
|
74
|
+
no_data = resp_has_no_data(resp, config[:statistics])
|
75
|
+
if no_data && config[:no_data_ok]
|
76
|
+
ok "#{metric_desc} returned no data but that's ok"
|
77
|
+
elsif no_data && !config[:no_data_ok]
|
78
|
+
unknown "#{metric_desc} could not be retrieved"
|
79
|
+
end
|
80
|
+
|
81
|
+
value = read_value(resp, config[:statistics])
|
82
|
+
base_msg = "#{metric_desc} is #{value}: comparison=#{config[:compare]}"
|
83
|
+
|
84
|
+
if compare value, config[:critical], config[:compare]
|
85
|
+
critical "#{base_msg} threshold=#{config[:critical]}"
|
86
|
+
elsif config[:warning] && compare(value, config[:warning], config[:compare])
|
87
|
+
warning "#{base_msg} threshold=#{config[:warning]}"
|
88
|
+
else
|
89
|
+
ok "#{base_msg}, will alarm at #{!config[:warning].nil? ? config[:warning] : config[:critical]}"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|