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
@@ -0,0 +1,159 @@
|
|
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 (defaults to all distributions)',
|
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 :metrics,
|
56
|
+
description: 'Commas separated list of metric(s) to fetch',
|
57
|
+
short: '-m METRIC1,METRIC2',
|
58
|
+
long: '--metrics METRIC1,METRIC2'
|
59
|
+
|
60
|
+
option :end_time,
|
61
|
+
short: '-t T',
|
62
|
+
long: '--end-time TIME',
|
63
|
+
default: Time.now,
|
64
|
+
proc: proc { |a| Time.parse a },
|
65
|
+
description: 'CloudWatch metric statistics end time'
|
66
|
+
|
67
|
+
option :period,
|
68
|
+
short: '-p N',
|
69
|
+
long: '--period SECONDS',
|
70
|
+
default: 60,
|
71
|
+
proc: proc(&:to_i),
|
72
|
+
description: 'CloudWatch metric statistics period'
|
73
|
+
|
74
|
+
def cloud_watch
|
75
|
+
@cloud_watch ||= Aws::CloudWatch::Client.new
|
76
|
+
end
|
77
|
+
|
78
|
+
def cloud_watch_metric(metric_name, statistics, distribution_id)
|
79
|
+
cloud_watch.get_metric_statistics(
|
80
|
+
namespace: 'AWS/CloudFront',
|
81
|
+
metric_name: metric_name,
|
82
|
+
dimensions: [
|
83
|
+
{
|
84
|
+
name: 'Region',
|
85
|
+
value: 'Global'
|
86
|
+
},
|
87
|
+
{
|
88
|
+
name: 'DistributionId',
|
89
|
+
value: distribution_id
|
90
|
+
}
|
91
|
+
],
|
92
|
+
statistics: [statistics],
|
93
|
+
start_time: config[:end_time] - config[:period],
|
94
|
+
end_time: config[:end_time],
|
95
|
+
period: config[:period]
|
96
|
+
)
|
97
|
+
end
|
98
|
+
|
99
|
+
def distribution_list(metrics)
|
100
|
+
list_metrics = cloud_watch.list_metrics(
|
101
|
+
namespace: 'AWS/CloudFront'
|
102
|
+
).metrics
|
103
|
+
|
104
|
+
list_metrics = list_metrics.select { |e| metrics.include? e.metric_name }
|
105
|
+
|
106
|
+
list_metrics.reduce(Set.new) do |result, item|
|
107
|
+
result << item.dimensions.find { |element| element.name == 'DistributionId' }.value
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def print_statistics(distribution_id, statistic)
|
112
|
+
statistic.each do |metric, static|
|
113
|
+
r = cloud_watch_metric(metric, static, distribution_id)
|
114
|
+
keys = [config[:scheme]]
|
115
|
+
keys.concat [distribution_id, metric, static]
|
116
|
+
output(keys.join('.'), r[:datapoints].first[static.downcase]) unless r[:datapoints].first.nil?
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def print_metrics(distribution_id, metrics)
|
121
|
+
metrics_statistic = {
|
122
|
+
'Requests' => 'Sum',
|
123
|
+
'BytesDownloaded' => 'Sum',
|
124
|
+
'BytesUploaded' => 'Sum',
|
125
|
+
'TotalErrorRate' => 'Average',
|
126
|
+
'4xxErrorRate' => 'Average',
|
127
|
+
'5xxErrorRate' => 'Average'
|
128
|
+
}
|
129
|
+
|
130
|
+
metrics.each do |metric|
|
131
|
+
statistic = metrics_statistic.select { |key, _| key == metric }
|
132
|
+
if statistic.empty?
|
133
|
+
unknown "Invalid metric #{metric}. Possible values: #{metrics_statistic.keys.join(',')}"
|
134
|
+
end
|
135
|
+
print_statistics(distribution_id, statistic)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def parse_metrics(metrics)
|
140
|
+
if metrics.nil?
|
141
|
+
unknown 'No metrics provided. See usage for details'
|
142
|
+
end
|
143
|
+
metrics.split(',')
|
144
|
+
end
|
145
|
+
|
146
|
+
def run
|
147
|
+
metrics = parse_metrics(config[:metrics])
|
148
|
+
|
149
|
+
if config[:distribution_id].nil?
|
150
|
+
distribution_list(metrics).each do |distribution|
|
151
|
+
print_metrics(distribution, metrics)
|
152
|
+
end
|
153
|
+
else
|
154
|
+
print_metrics(config[:distribution_id], metrics)
|
155
|
+
end
|
156
|
+
|
157
|
+
ok
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# metrics-ec2-count
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This plugin retrieves number of EC2 instances.
|
7
|
+
#
|
8
|
+
# OUTPUT:
|
9
|
+
# plain-text
|
10
|
+
#
|
11
|
+
# PLATFORMS:
|
12
|
+
# Linux
|
13
|
+
#
|
14
|
+
# DEPENDENCIES:
|
15
|
+
# gem: aws-sdk
|
16
|
+
# gem: sensu-plugin
|
17
|
+
#
|
18
|
+
# USAGE:
|
19
|
+
# # get metrics on the status of all instances in the region
|
20
|
+
# metrics-ec2-count.rb -t status
|
21
|
+
#
|
22
|
+
# # get metrics on all instance types in the region
|
23
|
+
# metrics-ec2-count.rb -t instance
|
24
|
+
#
|
25
|
+
# NOTES:
|
26
|
+
#
|
27
|
+
# LICENSE:
|
28
|
+
# Copyright (c) 2014, Tim Smith, tsmith@chef.io
|
29
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
30
|
+
# for details.
|
31
|
+
#
|
32
|
+
|
33
|
+
require 'sensu-plugin/metric/cli'
|
34
|
+
require 'sensu-plugins-aws'
|
35
|
+
require 'aws-sdk'
|
36
|
+
|
37
|
+
class EC2Metrics < Sensu::Plugin::Metric::CLI::Graphite
|
38
|
+
include Common
|
39
|
+
|
40
|
+
option :scheme,
|
41
|
+
description: 'Metric naming scheme, text to prepend to metric',
|
42
|
+
short: '-s SCHEME',
|
43
|
+
long: '--scheme SCHEME',
|
44
|
+
default: 'sensu.aws.ec2'
|
45
|
+
|
46
|
+
option :aws_region,
|
47
|
+
short: '-r AWS_REGION',
|
48
|
+
long: '--aws-region REGION',
|
49
|
+
description: 'AWS Region (defaults to us-east-1).',
|
50
|
+
default: 'us-east-1'
|
51
|
+
|
52
|
+
option :type,
|
53
|
+
short: '-t METRIC type',
|
54
|
+
long: '--type METRIC type',
|
55
|
+
description: 'Count by type: status, instance',
|
56
|
+
default: 'instance'
|
57
|
+
|
58
|
+
def aws_config
|
59
|
+
{ access_key_id: config[:aws_access_key],
|
60
|
+
secret_access_key: config[:aws_secret_access_key],
|
61
|
+
region: config[:aws_region] }
|
62
|
+
end
|
63
|
+
|
64
|
+
def by_instances_status(client)
|
65
|
+
if config[:scheme] == 'sensu.aws.ec2'
|
66
|
+
config[:scheme] += '.count'
|
67
|
+
end
|
68
|
+
|
69
|
+
options = { include_all_instances: true }
|
70
|
+
status_data = client.describe_instance_status(options)
|
71
|
+
|
72
|
+
total = status_data.instance_statuses.count
|
73
|
+
status = {}
|
74
|
+
|
75
|
+
unless total.nil?
|
76
|
+
status_data.instance_statuses.each do |value|
|
77
|
+
stat = value.instance_state.name
|
78
|
+
status[stat] = if status[stat].nil?
|
79
|
+
1
|
80
|
+
else
|
81
|
+
status[stat] + 1
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
unless status_data.nil? # rubocop: disable Style/GuardClause
|
87
|
+
# We only return data when we have some to return
|
88
|
+
output config[:scheme] + '.total', total
|
89
|
+
status.each do |name, count|
|
90
|
+
output config[:scheme] + ".#{name}", count
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def by_instances_type(client)
|
96
|
+
if config[:scheme] == 'sensu.aws.ec2'
|
97
|
+
config[:scheme] += '.types'
|
98
|
+
end
|
99
|
+
|
100
|
+
data = {}
|
101
|
+
|
102
|
+
instances = client.describe_instances
|
103
|
+
instances.reservations.each do |i|
|
104
|
+
i.instances.each do |instance|
|
105
|
+
type = instance.instance_type
|
106
|
+
data[type] = if data[type].nil?
|
107
|
+
1
|
108
|
+
else
|
109
|
+
data[type] + 1
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
unless data.nil? # rubocop: disable Style/GuardClause
|
115
|
+
# We only return data when we have some to return
|
116
|
+
data.each do |name, count|
|
117
|
+
output config[:scheme] + ".#{name}", count
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def run
|
123
|
+
begin
|
124
|
+
client = Aws::EC2::Client.new(aws_config)
|
125
|
+
|
126
|
+
if config[:type] == 'instance'
|
127
|
+
by_instances_type(client)
|
128
|
+
elsif config[:type] == 'status'
|
129
|
+
by_instances_status(client)
|
130
|
+
end
|
131
|
+
rescue StandardError => e
|
132
|
+
puts "Error: exception: #{e}"
|
133
|
+
critical
|
134
|
+
end
|
135
|
+
ok
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# metrics-ec2-filter
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This plugin retrieves EC2 instances matching a given filter
|
7
|
+
#
|
8
|
+
# OUTPUT:
|
9
|
+
# plain-text
|
10
|
+
#
|
11
|
+
# PLATFORMS:
|
12
|
+
# Linux
|
13
|
+
#
|
14
|
+
# DEPENDENCIES:
|
15
|
+
# gem: aws-sdk
|
16
|
+
# gem: sensu-plugin
|
17
|
+
#
|
18
|
+
# USAGE:
|
19
|
+
# ./metrics-ec2-filter.rb -f "{name:tag-value,values:[infrastructure]}"
|
20
|
+
# ./metrics-ec2-filter.rb -f "{name:tag-value,values:[infrastructure]} {name:instance-state-name,values:[running]}"
|
21
|
+
#
|
22
|
+
# NOTES:
|
23
|
+
#
|
24
|
+
# LICENSE:
|
25
|
+
# Justin McCarty
|
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 EC2Filter < Sensu::Plugin::Metric::CLI::Graphite
|
35
|
+
include Filter
|
36
|
+
include Common
|
37
|
+
|
38
|
+
option :aws_region,
|
39
|
+
short: '-r AWS_REGION',
|
40
|
+
long: '--aws-region REGION',
|
41
|
+
description: 'AWS Region (defaults to us-east-1).',
|
42
|
+
default: 'us-east-1'
|
43
|
+
|
44
|
+
option :name,
|
45
|
+
description: 'Filter naming scheme, text to prepend to metric',
|
46
|
+
short: '-n NAME',
|
47
|
+
long: '--name NAME',
|
48
|
+
default: ''
|
49
|
+
|
50
|
+
option :filter,
|
51
|
+
short: '-f FILTER',
|
52
|
+
long: '--filter FILTER',
|
53
|
+
description: 'String representation of the filter to apply',
|
54
|
+
default: '{}'
|
55
|
+
|
56
|
+
option :scheme,
|
57
|
+
description: 'Metric naming scheme, text to prepend to metric',
|
58
|
+
short: '-s SCHEME',
|
59
|
+
long: '--scheme SCHEME',
|
60
|
+
default: 'sensu.aws.ec2'
|
61
|
+
|
62
|
+
def aws_config
|
63
|
+
{ access_key_id: config[:aws_access_key],
|
64
|
+
secret_access_key: config[:aws_secret_access_key],
|
65
|
+
region: config[:aws_region] }
|
66
|
+
end
|
67
|
+
|
68
|
+
def run
|
69
|
+
begin
|
70
|
+
client = Aws::EC2::Client.new aws_config
|
71
|
+
|
72
|
+
filter = Filter.parse(config[:filter])
|
73
|
+
|
74
|
+
options = { filters: filter }
|
75
|
+
|
76
|
+
data = client.describe_instances(options)
|
77
|
+
|
78
|
+
instance_ids = Set.new
|
79
|
+
scheme = config[:scheme]
|
80
|
+
|
81
|
+
unless config[:name].empty?
|
82
|
+
scheme += ".#{config[:name]}"
|
83
|
+
end
|
84
|
+
data[:reservations].each do |res|
|
85
|
+
res[:instances].each do |i|
|
86
|
+
instance_ids << i[:instance_id]
|
87
|
+
output scheme + ".ids.#{i[:instance_id]}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
output scheme + ".count.#{instance_ids.count}"
|
91
|
+
rescue StandardError => e
|
92
|
+
puts "Error: exception: #{e}"
|
93
|
+
critical
|
94
|
+
end
|
95
|
+
ok
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# elasticache-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
|
+
# Returns latency statistics by default. You can specify any valid ASG metric type, see
|
25
|
+
# http://http://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/as-metricscollected.html
|
26
|
+
#
|
27
|
+
# LICENSE:
|
28
|
+
# Peter Hoppe <peter.hoppe.extern@bertelsmann.de>
|
29
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
30
|
+
# for details.
|
31
|
+
#
|
32
|
+
|
33
|
+
require 'sensu-plugin/metric/cli'
|
34
|
+
require 'aws-sdk'
|
35
|
+
require 'sensu-plugins-aws'
|
36
|
+
require 'time'
|
37
|
+
|
38
|
+
class ElasticMetrics < Sensu::Plugin::Metric::CLI::Graphite
|
39
|
+
include Common
|
40
|
+
option :scheme,
|
41
|
+
description: 'Metric naming scheme, text to prepend to metric',
|
42
|
+
short: '-s SCHEME',
|
43
|
+
long: '--scheme SCHEME',
|
44
|
+
default: ''
|
45
|
+
|
46
|
+
option :statistic,
|
47
|
+
description: 'Statistics type',
|
48
|
+
short: '-t STATISTIC',
|
49
|
+
long: '--statistic',
|
50
|
+
default: ''
|
51
|
+
|
52
|
+
option :aws_region,
|
53
|
+
short: '-r AWS_REGION',
|
54
|
+
long: '--aws-region REGION',
|
55
|
+
description: 'AWS Region (defaults to us-east-1).',
|
56
|
+
default: ENV['AWS_REGION']
|
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 cloud_watch
|
73
|
+
@cloud_watch = Aws::CloudWatch::Client.new
|
74
|
+
end
|
75
|
+
|
76
|
+
def elasticaches
|
77
|
+
@elasticaches = Aws::ElastiCache::Client.new
|
78
|
+
end
|
79
|
+
|
80
|
+
def cloud_watch_metric(metric_name, value, cache_cluster_id)
|
81
|
+
cloud_watch.get_metric_statistics(
|
82
|
+
namespace: 'AWS/ElastiCache',
|
83
|
+
metric_name: metric_name,
|
84
|
+
dimensions: [
|
85
|
+
{
|
86
|
+
name: 'CacheClusterId',
|
87
|
+
value: cache_cluster_id
|
88
|
+
}
|
89
|
+
],
|
90
|
+
statistics: [value],
|
91
|
+
start_time: config[:end_time] - config[:period],
|
92
|
+
end_time: config[:end_time],
|
93
|
+
period: config[:period]
|
94
|
+
)
|
95
|
+
end
|
96
|
+
|
97
|
+
def print_statistics(cache_cluster_id, statistics)
|
98
|
+
result = {}
|
99
|
+
statistics.each do |key, static|
|
100
|
+
r = cloud_watch_metric(key, static, cache_cluster_id)
|
101
|
+
result['elasticache.' + cache_cluster_id + '.' + key] = r[:datapoints][0] unless r[:datapoints][0].nil?
|
102
|
+
end
|
103
|
+
return if result.nil?
|
104
|
+
result.each do |key, value|
|
105
|
+
output key.downcase.to_s, value.average, value[:timestamp].to_i
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def run
|
110
|
+
# TODO: come back and refactor
|
111
|
+
elasticaches.describe_cache_clusters.cache_clusters.each do |elasticache| # rubocop:disable Metrics/BlockLength)
|
112
|
+
if elasticache.engine.include? 'redis'
|
113
|
+
if config[:statistic] == ''
|
114
|
+
default_statistic_per_metric = {
|
115
|
+
'BytesUsedForCache' => 'Average',
|
116
|
+
'CacheHits' => 'Average',
|
117
|
+
'CacheMisses' => 'Average',
|
118
|
+
'CurrConnections' => 'Average',
|
119
|
+
'Evictions' => 'Average',
|
120
|
+
'HyperLogLogBasedCmds' => 'Average',
|
121
|
+
'NewConnections' => 'Average',
|
122
|
+
'Reclaimed' => 'Average',
|
123
|
+
'ReplicationBytes' => 'Average',
|
124
|
+
'ReplicationLag' => 'Average',
|
125
|
+
'SaveInProgress' => 'Average'
|
126
|
+
}
|
127
|
+
statistic = default_statistic_per_metric
|
128
|
+
else
|
129
|
+
statistic = config[:statistic]
|
130
|
+
end
|
131
|
+
print_statistics(elasticache.cache_cluster_id, statistic)
|
132
|
+
elsif elasticache.engine.include? 'memcached'
|
133
|
+
if config[:statistic] == ''
|
134
|
+
default_statistic_per_metric = {
|
135
|
+
'BytesReadIntoMemcached' => 'Average',
|
136
|
+
'BytesUsedForCacheItems' => 'Average',
|
137
|
+
'BytesWrittenOutFromMemcached' => 'Average',
|
138
|
+
'CasBadval' => 'Average',
|
139
|
+
'CasHits' => 'Average',
|
140
|
+
'CasMisses' => 'Average',
|
141
|
+
'CmdFlush' => 'Average',
|
142
|
+
'CmdGet' => 'Average',
|
143
|
+
'CmdSet' => 'Average',
|
144
|
+
'CurrConnections' => 'Average',
|
145
|
+
'CurrItems' => 'Average',
|
146
|
+
'DecrHits' => 'Average',
|
147
|
+
'DecrMisses' => 'Average',
|
148
|
+
'DeleteHits' => 'Average',
|
149
|
+
'DeleteMisses' => 'Average',
|
150
|
+
'Evictions' => 'Average',
|
151
|
+
'GetHits' => 'Average',
|
152
|
+
'GetMisses' => 'Average',
|
153
|
+
'IncrHits' => 'Average',
|
154
|
+
'IncrMisses' => 'Average',
|
155
|
+
'Reclaimed' => 'Average'
|
156
|
+
}
|
157
|
+
statistic = default_statistic_per_metric
|
158
|
+
else
|
159
|
+
statistic = config[:statistic]
|
160
|
+
end
|
161
|
+
print_statistics(elasticache.cache_cluster_id, statistic)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
exit
|
165
|
+
end
|
166
|
+
end
|