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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +45 -1
- data/README.md +33 -0
- data/bin/check-asg-instances-created.rb +127 -0
- data/bin/check-asg-instances-inservice.rb +109 -0
- data/bin/check-cloudfront-tag.rb +70 -0
- data/bin/check-cloudwatch-metric.rb +7 -1
- data/bin/check-ebs-burst-limit.rb +96 -0
- data/bin/check-ec2-cpu_balance.rb +2 -2
- data/bin/check-ec2-filter.rb +38 -5
- data/bin/check-ecs-service-health.rb +37 -6
- data/bin/check-elb-instances-inservice.rb +103 -0
- data/bin/check-instance-events.rb +8 -11
- data/bin/check-instance-health.rb +24 -1
- data/bin/check-instances-count.rb +13 -1
- data/bin/check-rds-events.rb +3 -6
- data/bin/check-rds.rb +92 -52
- data/bin/check-route53-domain-expiration.rb +79 -0
- data/bin/check-s3-object.rb +59 -20
- data/bin/check-s3-tag.rb +70 -0
- data/bin/check-ses-limit.rb +1 -1
- data/bin/check-sqs-messages.rb +16 -18
- data/bin/check-vpc-vpn.rb +42 -47
- data/bin/metrics-asg.rb +156 -0
- data/bin/metrics-autoscaling-instance-count.rb +26 -10
- data/bin/metrics-billing.rb +98 -0
- data/bin/metrics-elasticache.rb +118 -167
- data/bin/metrics-elb-full.rb +1 -1
- data/bin/metrics-elb.rb +68 -59
- data/bin/metrics-rds.rb +135 -0
- data/bin/metrics-s3.rb +105 -0
- data/lib/sensu-plugins-aws.rb +1 -0
- data/lib/sensu-plugins-aws/cloudwatch-common.rb +2 -1
- data/lib/sensu-plugins-aws/version.rb +3 -3
- metadata +39 -3
data/bin/check-s3-tag.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-s3-tag
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This plugin checks if buckets have a set of tags.
|
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
|
+
# ./check-s3-tag.rb --aws-region eu-west-1 --tag-keys xxx
|
20
|
+
#
|
21
|
+
# NOTES:
|
22
|
+
#
|
23
|
+
# LICENSE:
|
24
|
+
# Copyright (c) 2016, Olivier Bazoud, olivier.bazoud@gmail.com
|
25
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
26
|
+
# for details.
|
27
|
+
#
|
28
|
+
|
29
|
+
require 'sensu-plugin/check/cli'
|
30
|
+
require 'sensu-plugins-aws/common'
|
31
|
+
require 'aws-sdk'
|
32
|
+
|
33
|
+
class CheckS3Tag < Sensu::Plugin::Check::CLI
|
34
|
+
include Common
|
35
|
+
|
36
|
+
option :aws_region,
|
37
|
+
short: '-r AWS_REGION',
|
38
|
+
long: '--aws-region REGION',
|
39
|
+
description: 'AWS Region (defaults to us-east-1).',
|
40
|
+
default: 'us-east-1'
|
41
|
+
|
42
|
+
option :tag_keys,
|
43
|
+
short: '-t TAG_KEYS',
|
44
|
+
long: '--tag-keys TAG_KEYS',
|
45
|
+
description: 'Tag keys'
|
46
|
+
|
47
|
+
def run
|
48
|
+
tags = config[:tag_keys].split(',')
|
49
|
+
s3 = Aws::S3::Client.new
|
50
|
+
missing_tags = []
|
51
|
+
s3.list_buckets.buckets.each do |bucket|
|
52
|
+
begin
|
53
|
+
keys = s3.get_bucket_tagging(bucket: bucket.name).tag_set.map(&:key)
|
54
|
+
if keys.sort & tags.sort != tags.sort
|
55
|
+
missing_tags.push bucket.name
|
56
|
+
end
|
57
|
+
rescue => _
|
58
|
+
missing_tags.push bucket.name
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
if missing_tags.empty?
|
63
|
+
ok
|
64
|
+
else
|
65
|
+
critical("Missing tags in #{missing_tags}")
|
66
|
+
end
|
67
|
+
rescue => e
|
68
|
+
critical "Error: #{e.message} - #{e.backtrace}"
|
69
|
+
end
|
70
|
+
end
|
data/bin/check-ses-limit.rb
CHANGED
@@ -75,7 +75,7 @@ class CheckSESLimit < Sensu::Plugin::Check::CLI
|
|
75
75
|
|
76
76
|
unknown 'Empty response from AWS SES API' if response.empty? # Can this happen?
|
77
77
|
|
78
|
-
percent = (response.sent_last_24_hours.
|
78
|
+
percent = ((response.sent_last_24_hours.to_f / response.max_24_hour_send.to_f) * 100).to_i
|
79
79
|
message = "SES sending limit is at #{percent}%"
|
80
80
|
|
81
81
|
if config[:crit_percent] > 0 && config[:crit_percent] <= percent
|
data/bin/check-sqs-messages.rb
CHANGED
@@ -28,23 +28,14 @@
|
|
28
28
|
#
|
29
29
|
|
30
30
|
require 'sensu-plugin/check/cli'
|
31
|
-
require '
|
31
|
+
require 'sensu-plugins-aws'
|
32
|
+
require 'aws-sdk'
|
32
33
|
|
33
34
|
#
|
34
35
|
# Check SQS Messages
|
35
36
|
#
|
36
37
|
class SQSMsgs < Sensu::Plugin::Check::CLI
|
37
|
-
|
38
|
-
short: '-a AWS_ACCESS_KEY',
|
39
|
-
long: '--aws-access-key AWS_ACCESS_KEY',
|
40
|
-
description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY'] or provide it as an option",
|
41
|
-
default: ENV['AWS_ACCESS_KEY']
|
42
|
-
|
43
|
-
option :aws_secret_access_key,
|
44
|
-
short: '-k AWS_SECRET_KEY',
|
45
|
-
long: '--aws-secret-access-key AWS_SECRET_KEY',
|
46
|
-
description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_KEY'] or provide it as an option",
|
47
|
-
default: ENV['AWS_SECRET_KEY']
|
38
|
+
include Common
|
48
39
|
|
49
40
|
option :aws_region,
|
50
41
|
short: '-r AWS_REGION',
|
@@ -64,6 +55,12 @@ class SQSMsgs < Sensu::Plugin::Check::CLI
|
|
64
55
|
description: 'The prefix of the queues you want to check the number of messages for',
|
65
56
|
default: ''
|
66
57
|
|
58
|
+
option :metric,
|
59
|
+
short: '-m METTIC',
|
60
|
+
long: '--metric METRIC',
|
61
|
+
description: 'The metric of the queues you want to check the number of messages for',
|
62
|
+
default: 'ApproximateNumberOfMessages'
|
63
|
+
|
67
64
|
option :warn_over,
|
68
65
|
short: '-w WARN_OVER',
|
69
66
|
long: '--warnnum WARN_OVER',
|
@@ -99,15 +96,16 @@ class SQSMsgs < Sensu::Plugin::Check::CLI
|
|
99
96
|
end
|
100
97
|
|
101
98
|
def run
|
102
|
-
|
103
|
-
sqs =
|
99
|
+
Aws.config.update(aws_config)
|
100
|
+
sqs = Aws::SQS::Resource.new
|
104
101
|
|
105
102
|
if config[:prefix] == ''
|
106
103
|
if config[:queue] == ''
|
107
104
|
critical 'Error, either QUEUE or PREFIX must be specified'
|
108
105
|
end
|
109
106
|
|
110
|
-
|
107
|
+
url = sqs.get_queue_by_name(queue_name: config[:queue]).url
|
108
|
+
messages = sqs.client.get_queue_attributes(queue_url: url, attribute_names: ['All']).attributes[config[:metric]].to_i
|
111
109
|
|
112
110
|
if (config[:crit_under] >= 0 && messages < config[:crit_under]) || (config[:crit_over] >= 0 && messages > config[:crit_over])
|
113
111
|
critical "#{messages} message(s) in #{config[:queue]} queue"
|
@@ -121,9 +119,9 @@ class SQSMsgs < Sensu::Plugin::Check::CLI
|
|
121
119
|
crit = false
|
122
120
|
queues = []
|
123
121
|
|
124
|
-
sqs.queues
|
125
|
-
|
126
|
-
|
122
|
+
sqs.queues(queue_name_prefix: config[:prefix]).each do |q|
|
123
|
+
messages = sqs.client.get_queue_attributes(queue_url: q.url, attribute_names: ['All']).attributes[config[:metric]].to_i
|
124
|
+
queue_name = q.attributes['QueueArn'].split(':').last
|
127
125
|
|
128
126
|
if (config[:crit_under] >= 0 && messages < config[:crit_under]) || (config[:crit_over] >= 0 && messages > config[:crit_over])
|
129
127
|
crit = true
|
data/bin/check-vpc-vpn.rb
CHANGED
@@ -13,7 +13,8 @@
|
|
13
13
|
#
|
14
14
|
# DEPENDENCIES:
|
15
15
|
# gem: sensu-plugin
|
16
|
-
# gem: aws-sdk
|
16
|
+
# gem: aws-sdk
|
17
|
+
# gem: sensu-plugins-aws
|
17
18
|
#
|
18
19
|
# USAGE:
|
19
20
|
# ./check-vpc-vpn.rb --aws-region us-east-1 --vpn-connection-id vpn-abc1234
|
@@ -25,61 +26,50 @@
|
|
25
26
|
# John Dyer johntdyer@gmail.com
|
26
27
|
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
27
28
|
# for details.
|
29
|
+
# Updated by Peter Hoppe <peter.hoppe.extern@bertelsmann.de> to aws-sdk-v2
|
28
30
|
#
|
29
31
|
|
32
|
+
require 'sensu-plugins-aws'
|
30
33
|
require 'sensu-plugin/check/cli'
|
31
|
-
require 'aws-sdk
|
34
|
+
require 'aws-sdk'
|
32
35
|
|
33
36
|
class CheckAwsVpcVpnConnections < Sensu::Plugin::Check::CLI
|
34
|
-
|
35
|
-
# rubocop:disable Style/AlignParameters
|
36
|
-
option :access_key,
|
37
|
-
short: '-a AWS_ACCESS_KEY',
|
38
|
-
long: '--aws-access-key AWS_ACCESS_KEY',
|
39
|
-
description: 'AWS Access Key',
|
40
|
-
default: ENV['AWS_ACCESS_KEY_ID']
|
41
|
-
|
42
|
-
option :secret_key,
|
43
|
-
short: '-s AWS_SECRET_ACCESS_KEY',
|
44
|
-
long: '--aws-secret-access-key AWS_SECRET_ACCESS_KEY',
|
45
|
-
description: 'AWS Secret Access Key.',
|
46
|
-
default: ENV['AWS_SECRET_ACCESS_KEY']
|
47
|
-
|
48
|
-
option :use_iam_role,
|
49
|
-
short: '-u',
|
50
|
-
long: '--use-iam',
|
51
|
-
description: 'Use IAM authentication'
|
52
|
-
|
37
|
+
include Common
|
53
38
|
option :vpn_id,
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
39
|
+
short: '-v VPN_ID',
|
40
|
+
long: '--vpn-connection-id VPN_ID',
|
41
|
+
required: true,
|
42
|
+
description: 'VPN connection ID'
|
58
43
|
|
59
44
|
option :aws_region,
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
45
|
+
short: '-r AWS_REGION',
|
46
|
+
long: '--aws-region REGION',
|
47
|
+
description: 'AWS Region (defaults to us-east-1).',
|
48
|
+
default: ENV['AWS_REGION']
|
64
49
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
50
|
+
option :warn_count,
|
51
|
+
short: '-W WARN_COUNT',
|
52
|
+
long: '--warn_count WARN_COUNT',
|
53
|
+
description: 'Warn when the count of down tunnels is at or above this number',
|
54
|
+
default: 1,
|
55
|
+
proc: proc(&:to_i)
|
56
|
+
|
57
|
+
option :crit_count,
|
58
|
+
short: '-C CRIT_COUNT',
|
59
|
+
long: '--crit_count CRIT_COUNT',
|
60
|
+
description: 'Critical when the count of down tunnels is at or above this number',
|
61
|
+
default: 2,
|
62
|
+
proc: proc(&:to_i)
|
73
63
|
|
74
64
|
def fetch_connection_data
|
75
65
|
begin
|
76
|
-
ec2 =
|
77
|
-
vpn_info = ec2.describe_vpn_connections(vpn_connection_ids: [config[:vpn_id]]).
|
66
|
+
ec2 = Aws::EC2::Client.new
|
67
|
+
vpn_info = ec2.describe_vpn_connections(vpn_connection_ids: [config[:vpn_id]]).vpn_connections
|
78
68
|
down_connections = vpn_info.first.vgw_telemetry.select { |x| x.status != 'UP' }
|
79
69
|
results = { down_count: down_connections.count }
|
80
|
-
results[:down_connection_status] = down_connections.map { |x| "#{x.outside_ip_address} => #{x.status_message.
|
81
|
-
results[:connection_name] = vpn_info[0].
|
82
|
-
rescue
|
70
|
+
results[:down_connection_status] = down_connections.map { |x| "#{x.outside_ip_address} => #{x.status_message.empty? ? 'none' : x.status_message}" }
|
71
|
+
results[:connection_name] = vpn_info[0].tags.find { |x| x.key == 'Name' }.value
|
72
|
+
rescue Aws::EC2::Errors::ServiceError
|
83
73
|
warning "The vpnConnection ID '#{config[:vpn_id]}' does not exist"
|
84
74
|
rescue => e
|
85
75
|
warning e.backtrace.join(' ')
|
@@ -92,12 +82,17 @@ class CheckAwsVpcVpnConnections < Sensu::Plugin::Check::CLI
|
|
92
82
|
msg = data[:down_connection_status].join(' | ')
|
93
83
|
name = data[:connection_name]
|
94
84
|
case data[:down_count]
|
95
|
-
when 2 then
|
96
|
-
when 1 then
|
97
|
-
|
85
|
+
when 2 then message = "'#{name}' shows both tunnels as DOWN - [ #{msg} ]"
|
86
|
+
when 1 then message = "'#{name}' shows 1 of 2 tunnels as DOWN - [ #{msg} ]"
|
87
|
+
end
|
88
|
+
|
89
|
+
if data[:down_count] >= config[:crit_count]
|
90
|
+
critical message
|
91
|
+
elsif data[:down_count] >= config[:warn_count]
|
92
|
+
warning message
|
98
93
|
else
|
99
|
-
|
100
|
-
|
94
|
+
up_count = 2 - data[:down_count]
|
95
|
+
ok "'#{name}' shows #{up_count} of 2 tunnels as UP"
|
101
96
|
end
|
102
97
|
end
|
103
98
|
end
|
data/bin/metrics-asg.rb
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# asg-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 ASGMetrics < Sensu::Plugin::Metric::CLI::Graphite
|
39
|
+
include Common
|
40
|
+
option :asgname,
|
41
|
+
description: 'Name of the Auto Scaling Group',
|
42
|
+
short: '-n ASG_NAME',
|
43
|
+
long: '--name ASG_NAME'
|
44
|
+
|
45
|
+
option :scheme,
|
46
|
+
description: 'Metric naming scheme, text to prepend to metric',
|
47
|
+
short: '-s SCHEME',
|
48
|
+
long: '--scheme SCHEME',
|
49
|
+
default: ''
|
50
|
+
|
51
|
+
option :fetch_age,
|
52
|
+
description: 'How long ago to fetch metrics for',
|
53
|
+
short: '-f AGE',
|
54
|
+
long: '--fetch_age',
|
55
|
+
default: 60,
|
56
|
+
proc: proc(&:to_i)
|
57
|
+
|
58
|
+
option :metric,
|
59
|
+
description: 'Metric to fetch',
|
60
|
+
short: '-m METRIC',
|
61
|
+
long: '--metric',
|
62
|
+
default: 'GroupInServiceInstances'
|
63
|
+
|
64
|
+
option :statistic,
|
65
|
+
description: 'Statistics type',
|
66
|
+
short: '-t STATISTIC',
|
67
|
+
long: '--statistic',
|
68
|
+
default: ''
|
69
|
+
|
70
|
+
option :aws_region,
|
71
|
+
short: '-r AWS_REGION',
|
72
|
+
long: '--aws-region REGION',
|
73
|
+
description: 'AWS Region (defaults to us-east-1).',
|
74
|
+
default: ENV['AWS_REGION']
|
75
|
+
|
76
|
+
option :end_time,
|
77
|
+
short: '-t T',
|
78
|
+
long: '--end-time TIME',
|
79
|
+
default: Time.now,
|
80
|
+
proc: proc { |a| Time.parse a },
|
81
|
+
description: 'CloudWatch metric statistics end time'
|
82
|
+
|
83
|
+
option :period,
|
84
|
+
short: '-p N',
|
85
|
+
long: '--period SECONDS',
|
86
|
+
default: 60,
|
87
|
+
proc: proc(&:to_i),
|
88
|
+
description: 'CloudWatch metric statistics period'
|
89
|
+
|
90
|
+
def cloud_watch
|
91
|
+
@cloud_watch = Aws::CloudWatch::Client.new
|
92
|
+
end
|
93
|
+
|
94
|
+
def asg
|
95
|
+
@asg = Aws::AutoScaling::Client.new
|
96
|
+
end
|
97
|
+
|
98
|
+
def cloud_watch_metric(metric_name, value, asg_name)
|
99
|
+
cloud_watch.get_metric_statistics(
|
100
|
+
namespace: 'AWS/AutoScaling',
|
101
|
+
metric_name: metric_name,
|
102
|
+
dimensions: [
|
103
|
+
{
|
104
|
+
name: 'AutoScaling',
|
105
|
+
value: asg_name
|
106
|
+
}
|
107
|
+
],
|
108
|
+
statistics: [value],
|
109
|
+
start_time: config[:end_time] - config[:period],
|
110
|
+
end_time: config[:end_time],
|
111
|
+
period: config[:period]
|
112
|
+
)
|
113
|
+
end
|
114
|
+
|
115
|
+
def print_statistics(asg_name, statistics)
|
116
|
+
result = {}
|
117
|
+
static_value = {}
|
118
|
+
statistics.each do |key, static|
|
119
|
+
r = cloud_watch_metric(key, static, asg_name)
|
120
|
+
static_value['AutoScalingGroup.' + asg_name + '.' + key + '.' + static] = static
|
121
|
+
result['AutoScalingGroup.' + asg_name + '.' + key + '.' + static] = r[:datapoints][0] unless r[:datapoints][0].nil?
|
122
|
+
end
|
123
|
+
result.each do |key, value|
|
124
|
+
output key.downcase.to_s, value[static_value[key].downcase], value[:timestamp].to_i
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def run
|
129
|
+
if config[:statistic] == ''
|
130
|
+
default_statistic_per_metric = {
|
131
|
+
'GroupMinSize' => 'Sum',
|
132
|
+
'GroupMaxSize' => 'Sum',
|
133
|
+
'GroupDesiredCapacity' => 'Sum',
|
134
|
+
'GroupInServiceInstances' => 'Sum',
|
135
|
+
'GroupPendingInstances' => 'Sum',
|
136
|
+
'GroupStandbyInstances' => 'Sum',
|
137
|
+
'GroupTerminatingInstances' => 'Sum',
|
138
|
+
'GroupTotalInstances' => 'Sum'
|
139
|
+
}
|
140
|
+
statistic = default_statistic_per_metric
|
141
|
+
else
|
142
|
+
statistic = config[:statistic]
|
143
|
+
end
|
144
|
+
|
145
|
+
begin
|
146
|
+
if config[:asgname].nil?
|
147
|
+
asg.describe_auto_scaling_groups.auto_scaling_groups.each do |autoascalinggroup|
|
148
|
+
print_statistics(autoascalinggroup.auto_scaling_group_name, statistic)
|
149
|
+
end
|
150
|
+
else
|
151
|
+
print_statistics(config[:asgname], statistic)
|
152
|
+
end
|
153
|
+
ok
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
@@ -27,14 +27,14 @@
|
|
27
27
|
#
|
28
28
|
|
29
29
|
require 'sensu-plugin/metric/cli'
|
30
|
-
require 'aws-sdk
|
30
|
+
require 'aws-sdk'
|
31
31
|
|
32
32
|
class AutoScalingInstanceCountMetrics < Sensu::Plugin::Metric::CLI::Graphite
|
33
33
|
option :groupname,
|
34
34
|
description: 'Name of the AutoScaling group',
|
35
35
|
short: '-g GROUP_NAME',
|
36
36
|
long: '--autoscaling-group GROUP_NAME',
|
37
|
-
|
37
|
+
default: false
|
38
38
|
|
39
39
|
option :scheme,
|
40
40
|
description: 'Metric naming scheme, text to prepend to metric',
|
@@ -60,22 +60,38 @@ class AutoScalingInstanceCountMetrics < Sensu::Plugin::Metric::CLI::Graphite
|
|
60
60
|
description: 'AWS Region (defaults to us-east-1).',
|
61
61
|
default: 'us-east-1'
|
62
62
|
|
63
|
+
option :include_name,
|
64
|
+
short: '-n',
|
65
|
+
long: '--include-name',
|
66
|
+
description: "Includes any offending instance's 'Name' tag in the metric output",
|
67
|
+
default: false
|
68
|
+
|
63
69
|
def aws_config
|
64
70
|
{ access_key_id: config[:aws_access_key],
|
65
71
|
secret_access_key: config[:aws_secret_access_key],
|
66
72
|
region: config[:aws_region] }
|
67
73
|
end
|
68
74
|
|
75
|
+
def autoscaling_groups
|
76
|
+
client = Aws::AutoScaling::Client.new(aws_config)
|
77
|
+
client.describe_auto_scaling_groups[:auto_scaling_groups].map(&:auto_scaling_group_name)
|
78
|
+
end
|
79
|
+
|
69
80
|
def run
|
70
|
-
graphitepath = if config[:scheme] == ''
|
71
|
-
"#{config[:groupname]}.autoscaling.instance_count"
|
72
|
-
else
|
73
|
-
config[:scheme]
|
74
|
-
end
|
75
81
|
begin
|
76
|
-
|
77
|
-
|
78
|
-
|
82
|
+
groupnames ||= config[:groupname] ? [config[:groupname]] : autoscaling_groups
|
83
|
+
groupnames.each do |g|
|
84
|
+
as = Aws::AutoScaling::AutoScalingGroup.new aws_config.merge!(name: g)
|
85
|
+
count = as.instances.map(&:lifecycle_state).count('InService')
|
86
|
+
scheme_name ||= config[:include_name] ? as.data[:tags].select { |tag| tag[:key] == 'Name' }[0][:value] : g
|
87
|
+
graphitepath =
|
88
|
+
if config[:scheme] == ''
|
89
|
+
"#{scheme_name}.autoscaling.instance_count"
|
90
|
+
else
|
91
|
+
"#{config[:scheme]}.#{scheme_name}.instance_count"
|
92
|
+
end
|
93
|
+
output graphitepath, count
|
94
|
+
end
|
79
95
|
rescue => e
|
80
96
|
puts "Error: exception: #{e}"
|
81
97
|
critical
|