sensu-plugins-aws 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +26 -1
- data/README.md +4 -1
- data/bin/check-autoscaling-cpucredits.rb +21 -21
- data/bin/check-beanstalk-elb-metric.rb +3 -3
- data/bin/check-certificate-expiry.rb +5 -5
- data/bin/check-cloudwatch-metric.rb +2 -2
- data/bin/check-dynamodb-capacity.rb +29 -18
- data/bin/check-dynamodb-throttle.rb +28 -17
- data/bin/check-ec2-cpu_balance.rb +107 -0
- data/bin/check-ec2-filter.rb +5 -5
- data/bin/check-ec2-network.rb +19 -15
- data/bin/check-elb-certs.rb +2 -2
- data/bin/check-elb-health-fog.rb +3 -5
- data/bin/check-elb-health-sdk.rb +5 -5
- data/bin/check-elb-latency.rb +1 -1
- data/bin/check-elb-sum-requests.rb +1 -1
- data/bin/check-emr-cluster.rb +3 -5
- data/bin/check-instance-events.rb +2 -4
- data/bin/check-instance-health.rb +80 -0
- data/bin/check-rds-events.rb +18 -7
- data/bin/check-rds.rb +30 -27
- data/bin/check-s3-bucket.rb +2 -4
- data/bin/check-s3-object.rb +2 -4
- data/bin/check-vpc-vpn.rb +4 -6
- data/bin/handler-ec2_node.rb +6 -15
- data/bin/handler-ses.rb +5 -5
- data/bin/handler-sns.rb +12 -14
- data/bin/metrics-autoscaling-instance-count.rb +5 -5
- data/bin/metrics-ec2-count.rb +10 -10
- data/bin/metrics-elasticache.rb +5 -5
- data/bin/metrics-elb-full.rb +5 -5
- data/bin/metrics-sqs.rb +5 -5
- data/lib/sensu-plugins-aws/cloudwatch-common.rb +9 -8
- data/lib/sensu-plugins-aws/common.rb +1 -3
- data/lib/sensu-plugins-aws/filter.rb +2 -2
- data/lib/sensu-plugins-aws/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +139 -125
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YjA0M2U4MDE1M2U4N2Y3NGY0ODVjZDM3M2RlODNhYmY3MTFkZDI3YQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
Mjc2NDdjYzliYjNlMzM0NzMwZWM3OTVmZTc4MjdhMDY3MjJiYWQ2Yw==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ODU0NzhhNjQwODg2ZTdmMmRhYWFhNDIxZTFlNTQ1OTcxYmZlMTlhNjMxZTFl
|
10
|
+
NzU2YjMyNmY3OGMzNTgyZjcwMmQzN2IzNzM1YTk0YTQxOTI4MjU0ZGY4OTcx
|
11
|
+
YTBjMTU2NjE3MzIyZWNiZDIxZTEzZDA1ZDk1NjZkNGE4YjE5Mzg=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
M2MwMGNmZTBiYWUyYzAxMTkwMWI0ZGNjNmUzNDkxNTBjOTI1OGMzMjUxMzc0
|
14
|
+
OTUwNTM2NDhhMzAxN2I1YTgyNTUzODEwNDUzMzIzYjMyM2UyM2NjZWExMDJl
|
15
|
+
YzcyZTFjMWE4ODhkYTUzZTRmYzE2MmRlZjJiMjFkZDEyZDZkMWY=
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,19 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
|
|
5
5
|
|
6
6
|
## Unreleased
|
7
7
|
|
8
|
+
## [2.1.1] - 2016-02-05
|
9
|
+
### Added
|
10
|
+
- check-ec2-cpu_balance.rb: scans for any t2 instances that are below a certain threshold of cpu credits
|
11
|
+
- check-instance-health.rb: adding ec2 instance health and event data
|
12
|
+
|
13
|
+
### Changed
|
14
|
+
- Update to aws-sdk 2.2.11 and aws-sdk-v1 1.66.0
|
15
|
+
|
16
|
+
### Fixed
|
17
|
+
- check-vpc-vpn.rb: fix execution error by running with aws-sdk-v1
|
18
|
+
- handler-ec2_node.rb: default values for ec2_states were ignored
|
19
|
+
- added new certs
|
20
|
+
|
8
21
|
## [2.1.0] - 2016-01-15
|
9
22
|
### Added
|
10
23
|
- check-elb-health-sdk.rb: add option for warning instead of critical when unhealthy instances are found
|
@@ -107,6 +120,18 @@ WARNING: This release contains major breaking changes that will impact all user
|
|
107
120
|
### Changed
|
108
121
|
- removed cruft from /lib
|
109
122
|
|
110
|
-
##
|
123
|
+
## 0.0.1 - 2015-05-21
|
111
124
|
### Added
|
112
125
|
- initial release
|
126
|
+
|
127
|
+
[unreleased]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/2.1.1...HEAD
|
128
|
+
[2.1.1]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/2.1.0...2.1.1
|
129
|
+
[2.1.0]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/2.0.1...2.1.0
|
130
|
+
[2.0.1]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/2.0.0...2.0.1
|
131
|
+
[2.0.0]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/1.2.0...2.0.0
|
132
|
+
[1.2.0]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/1.1.0...1.2.0
|
133
|
+
[1.1.0]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/1.0.0...1.1.0
|
134
|
+
[1.0.0]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/0.0.4...1.0.0
|
135
|
+
[0.0.4]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/0.0.3...0.0.4
|
136
|
+
[0.0.3]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/0.0.2...0.0.3
|
137
|
+
[0.0.2]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/0.0.1...0.0.2
|
data/README.md
CHANGED
@@ -5,7 +5,6 @@
|
|
5
5
|
[![Code Climate](https://codeclimate.com/github/sensu-plugins/sensu-plugins-aws/badges/gpa.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-aws)
|
6
6
|
[![Test Coverage](https://codeclimate.com/github/sensu-plugins/sensu-plugins-aws/badges/coverage.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-aws)
|
7
7
|
[![Dependency Status](https://gemnasium.com/sensu-plugins/sensu-plugins-aws.svg)](https://gemnasium.com/sensu-plugins/sensu-plugins-aws)
|
8
|
-
[![Codeship Status for sensu-plugins/sensu-plugins-aws](https://codeship.com/projects/2a9c6e70-d4b4-0132-67ee-4e043b6b23b5/status?branch=master)](https://codeship.com/projects/77866)
|
9
8
|
|
10
9
|
## Functionality
|
11
10
|
|
@@ -23,6 +22,8 @@
|
|
23
22
|
|
24
23
|
**check-ebs-snapshots.rb**
|
25
24
|
|
25
|
+
**check-ec2-cpu_balance.rb**
|
26
|
+
|
26
27
|
**check-ec2-filter.rb**
|
27
28
|
|
28
29
|
**check-ec2-network.rb**
|
@@ -47,6 +48,8 @@
|
|
47
48
|
|
48
49
|
**check-instance-events.rb**
|
49
50
|
|
51
|
+
**check-instance-health.rb**
|
52
|
+
|
50
53
|
**check-rds-events.rb**
|
51
54
|
|
52
55
|
**check-rds.rb**
|
@@ -12,7 +12,7 @@
|
|
12
12
|
# Linux
|
13
13
|
#
|
14
14
|
# DEPENDENCIES:
|
15
|
-
# gem: aws-sdk
|
15
|
+
# gem: aws-sdk
|
16
16
|
# gem: sensu-plugin
|
17
17
|
#
|
18
18
|
# USAGE:
|
@@ -28,7 +28,7 @@
|
|
28
28
|
#
|
29
29
|
|
30
30
|
require 'sensu-plugin/check/cli'
|
31
|
-
require 'aws-sdk
|
31
|
+
require 'aws-sdk'
|
32
32
|
|
33
33
|
class CheckEc2CpuCredits < Sensu::Plugin::Check::CLI
|
34
34
|
option :aws_access_key,
|
@@ -90,38 +90,38 @@ class CheckEc2CpuCredits < Sensu::Plugin::Check::CLI
|
|
90
90
|
end
|
91
91
|
|
92
92
|
def asg
|
93
|
-
@asg ||=
|
93
|
+
@asg ||= Aws::AutoScaling::Client.new aws_config
|
94
94
|
end
|
95
95
|
|
96
96
|
def cloud_watch
|
97
|
-
@cloud_watch ||=
|
97
|
+
@cloud_watch ||= Aws::CloudWatch::Client.new aws_config
|
98
98
|
end
|
99
99
|
|
100
100
|
def get_count_metric(group)
|
101
|
-
cloud_watch.
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
101
|
+
cloud_watch.get_metric_statistics(
|
102
|
+
namespace: 'AWS/EC2',
|
103
|
+
metric_name: config[:countmetric].to_s,
|
104
|
+
dimensions: [
|
105
|
+
{
|
106
|
+
name: 'AutoScalingGroupName',
|
107
|
+
value: group
|
108
|
+
}
|
109
|
+
],
|
110
110
|
start_time: config[:end_time] - 600,
|
111
|
-
end_time:
|
111
|
+
end_time: config[:end_time],
|
112
112
|
statistics: ['Average'],
|
113
|
-
period:
|
114
|
-
|
113
|
+
period: config[:period],
|
114
|
+
unit: 'Count'
|
115
|
+
)
|
115
116
|
end
|
116
117
|
|
117
|
-
def latest_value(
|
118
|
-
value = metric.statistics(statistics_options.merge unit: 'Count')
|
118
|
+
def latest_value(value)
|
119
119
|
value.datapoints[0][:average].to_f unless value.datapoints[0].nil?
|
120
120
|
end
|
121
121
|
|
122
122
|
def check_metric(group)
|
123
123
|
metric = get_count_metric group
|
124
|
-
latest_value metric
|
124
|
+
latest_value metric unless metric.nil?
|
125
125
|
end
|
126
126
|
|
127
127
|
def check_group(group, reportstring, warnflag, critflag)
|
@@ -141,9 +141,9 @@ class CheckEc2CpuCredits < Sensu::Plugin::Check::CLI
|
|
141
141
|
critflag = 0
|
142
142
|
reportstring = ''
|
143
143
|
if config[:group].nil?
|
144
|
-
asg.
|
144
|
+
asg.describe_auto_scaling_groups.auto_scaling_groups.each do |group|
|
145
145
|
if group.desired_capacity > 0
|
146
|
-
reportstring, warnflag, critflag = check_group(group.
|
146
|
+
reportstring, warnflag, critflag = check_group(group.auto_scaling_group_name, reportstring, warnflag, critflag)
|
147
147
|
end
|
148
148
|
end
|
149
149
|
else
|
@@ -103,9 +103,9 @@ class BeanstalkELBCheck < Sensu::Plugin::Check::CLI
|
|
103
103
|
|
104
104
|
def elb_name
|
105
105
|
@elb_name ||= Aws::ElasticBeanstalk::Client.new
|
106
|
-
|
107
|
-
|
108
|
-
|
106
|
+
.describe_environment_resources(environment_name: config[:environment])
|
107
|
+
.environment_resources
|
108
|
+
.load_balancers[config[:elb_idx]]
|
109
109
|
.name
|
110
110
|
end
|
111
111
|
|
@@ -89,11 +89,11 @@ class CheckCertificateExpiry < Sensu::Plugin::Check::CLI
|
|
89
89
|
|
90
90
|
if time_to_expiry <= config[:critical].to_i
|
91
91
|
critflag = true
|
92
|
-
if time_to_expiry < 1
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
92
|
+
reportstring += if time_to_expiry < 1
|
93
|
+
" #{cert.server_certificate_name} certificate is expired!"
|
94
|
+
else
|
95
|
+
" #{cert.server_certificate_name} certificate expires in #{time_to_expiry} days;"
|
96
|
+
end
|
97
97
|
elsif time_to_expiry <= config[:warning].to_i
|
98
98
|
warnflag = true
|
99
99
|
reportstring += " #{cert.server_certificate_name} certificate expires in #{time_to_expiry} days;"
|
@@ -99,8 +99,8 @@ class CloudWatchMetricCheck < Sensu::Plugin::Check::CLI
|
|
99
99
|
|
100
100
|
def self.parse_dimensions(dimension_string)
|
101
101
|
dimension_string.split(',')
|
102
|
-
|
103
|
-
|
102
|
+
.collect { |d| d.split '=' }
|
103
|
+
.collect { |a| { name: a[0], value: a[1] } }
|
104
104
|
end
|
105
105
|
|
106
106
|
def dimension_string
|
@@ -12,7 +12,7 @@
|
|
12
12
|
# Linux
|
13
13
|
#
|
14
14
|
# DEPENDENCIES:
|
15
|
-
# gem: aws-sdk
|
15
|
+
# gem: aws-sdk
|
16
16
|
# gem: sensu-plugin
|
17
17
|
#
|
18
18
|
# USAGE:
|
@@ -31,7 +31,7 @@
|
|
31
31
|
#
|
32
32
|
|
33
33
|
require 'sensu-plugin/check/cli'
|
34
|
-
require 'aws-sdk
|
34
|
+
require 'aws-sdk'
|
35
35
|
require 'time'
|
36
36
|
|
37
37
|
class CheckDynamoDB < Sensu::Plugin::Check::CLI
|
@@ -104,35 +104,46 @@ class CheckDynamoDB < Sensu::Plugin::Check::CLI
|
|
104
104
|
end
|
105
105
|
|
106
106
|
def dynamo_db
|
107
|
-
@dynamo_db ||=
|
107
|
+
@dynamo_db ||= Aws::DynamoDB::Client.new aws_config
|
108
108
|
end
|
109
109
|
|
110
110
|
def cloud_watch
|
111
|
-
@cloud_watch ||=
|
111
|
+
@cloud_watch ||= Aws::CloudWatch::Client.new aws_config
|
112
112
|
end
|
113
113
|
|
114
114
|
def tables
|
115
115
|
return @tables if @tables
|
116
|
-
|
117
|
-
|
116
|
+
table_names = dynamo_db.list_tables.table_names.to_a
|
117
|
+
table_names.select! { |table_name| config[:table_names].include? table_name } if config[:table_names]
|
118
|
+
@tables = []
|
119
|
+
table_names.each do |table_name|
|
120
|
+
@tables.push(dynamo_db.describe_table(
|
121
|
+
table_name: table_name
|
122
|
+
).table)
|
123
|
+
end
|
118
124
|
@tables
|
119
125
|
end
|
120
126
|
|
121
127
|
def cloud_watch_metric(metric_name, table_name)
|
122
|
-
cloud_watch.
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
128
|
+
cloud_watch.get_metric_statistics(
|
129
|
+
namespace: 'AWS/DynamoDB',
|
130
|
+
metric_name: metric_name,
|
131
|
+
dimensions: [
|
132
|
+
{
|
133
|
+
name: 'TableName',
|
134
|
+
value: table_name
|
135
|
+
}
|
136
|
+
],
|
127
137
|
start_time: config[:end_time] - config[:period],
|
128
|
-
end_time:
|
138
|
+
end_time: config[:end_time],
|
129
139
|
statistics: [config[:statistics].to_s.capitalize],
|
130
|
-
period:
|
131
|
-
|
140
|
+
period: config[:period],
|
141
|
+
unit: 'Count'
|
142
|
+
)
|
132
143
|
end
|
133
144
|
|
134
145
|
def latest_value(metric)
|
135
|
-
metric.
|
146
|
+
metric.datapoints.sort_by { |datapoint| datapoint[:timestamp] }.last[config[:statistics]]
|
136
147
|
end
|
137
148
|
|
138
149
|
def flag_alert(severity, message)
|
@@ -143,19 +154,19 @@ class CheckDynamoDB < Sensu::Plugin::Check::CLI
|
|
143
154
|
def check_capacity(table)
|
144
155
|
config[:capacity_for].each do |r_or_w|
|
145
156
|
metric_name = "Consumed#{r_or_w.to_s.capitalize}CapacityUnits"
|
146
|
-
metric = cloud_watch_metric metric_name, table.
|
157
|
+
metric = cloud_watch_metric metric_name, table.table_name
|
147
158
|
metric_value = begin
|
148
159
|
latest_value(metric)
|
149
160
|
rescue
|
150
161
|
0
|
151
162
|
end
|
152
|
-
percentage = metric_value / table.send("#{r_or_w}_capacity_units").to_f * 100
|
163
|
+
percentage = metric_value / table.provisioned_throughput.send("#{r_or_w}_capacity_units").to_f * 100
|
153
164
|
|
154
165
|
@severities.keys.each do |severity|
|
155
166
|
threshold = config[:"#{severity}_over"]
|
156
167
|
next unless threshold
|
157
168
|
next if percentage < threshold
|
158
|
-
flag_alert severity, "; On table #{table.
|
169
|
+
flag_alert severity, "; On table #{table.table_name} consumed #{r_or_w} capacity is #{sprintf '%.2f', percentage}% (expected_lower_than #{threshold})"
|
159
170
|
break
|
160
171
|
end
|
161
172
|
end
|
@@ -12,7 +12,7 @@
|
|
12
12
|
# Linux
|
13
13
|
#
|
14
14
|
# DEPENDENCIES:
|
15
|
-
# gem: aws-sdk
|
15
|
+
# gem: aws-sdk
|
16
16
|
# gem: sensu-plugin
|
17
17
|
#
|
18
18
|
# USAGE:
|
@@ -28,7 +28,7 @@
|
|
28
28
|
#
|
29
29
|
|
30
30
|
require 'sensu-plugin/check/cli'
|
31
|
-
require 'aws-sdk
|
31
|
+
require 'aws-sdk'
|
32
32
|
require 'time'
|
33
33
|
|
34
34
|
class CheckDynamoDB < Sensu::Plugin::Check::CLI
|
@@ -99,35 +99,46 @@ class CheckDynamoDB < Sensu::Plugin::Check::CLI
|
|
99
99
|
end
|
100
100
|
|
101
101
|
def dynamo_db
|
102
|
-
@dynamo_db ||=
|
102
|
+
@dynamo_db ||= Aws::DynamoDB::Client.new aws_config
|
103
103
|
end
|
104
104
|
|
105
105
|
def cloud_watch
|
106
|
-
@cloud_watch ||=
|
106
|
+
@cloud_watch ||= Aws::CloudWatch::Client.new aws_config
|
107
107
|
end
|
108
108
|
|
109
109
|
def tables
|
110
110
|
return @tables if @tables
|
111
|
-
|
112
|
-
|
111
|
+
table_names = dynamo_db.list_tables.table_names.to_a
|
112
|
+
table_names.select! { |table_name| config[:table_names].include? table_name } if config[:table_names]
|
113
|
+
@tables = []
|
114
|
+
table_names.each do |table_name|
|
115
|
+
@tables.push(dynamo_db.describe_table(
|
116
|
+
table_name: table_name
|
117
|
+
).table)
|
118
|
+
end
|
113
119
|
@tables
|
114
120
|
end
|
115
121
|
|
116
122
|
def cloud_watch_metric(metric_name, table_name)
|
117
|
-
cloud_watch.
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
123
|
+
cloud_watch.get_metric_statistics(
|
124
|
+
namespace: 'AWS/DynamoDB',
|
125
|
+
metric_name: metric_name,
|
126
|
+
dimensions: [
|
127
|
+
{
|
128
|
+
name: 'TableName',
|
129
|
+
value: table_name
|
130
|
+
}
|
131
|
+
],
|
122
132
|
start_time: config[:end_time] - config[:period],
|
123
|
-
end_time:
|
133
|
+
end_time: config[:end_time],
|
124
134
|
statistics: [config[:statistics].to_s.capitalize],
|
125
|
-
period:
|
126
|
-
|
135
|
+
period: config[:period],
|
136
|
+
unit: 'Count'
|
137
|
+
)
|
127
138
|
end
|
128
139
|
|
129
140
|
def latest_value(metric)
|
130
|
-
metric.
|
141
|
+
metric.datapoints.sort_by { |datapoint| datapoint[:timestamp] }.last[config[:statistics]]
|
131
142
|
end
|
132
143
|
|
133
144
|
def flag_alert(severity, message)
|
@@ -138,7 +149,7 @@ class CheckDynamoDB < Sensu::Plugin::Check::CLI
|
|
138
149
|
def check_throttle(table)
|
139
150
|
config[:throttle_for].each do |r_or_w|
|
140
151
|
metric_name = "#{r_or_w.to_s.capitalize}ThrottleEvents"
|
141
|
-
metric = cloud_watch_metric metric_name, table.
|
152
|
+
metric = cloud_watch_metric metric_name, table.table_name
|
142
153
|
metric_value = begin
|
143
154
|
latest_value(metric)
|
144
155
|
rescue
|
@@ -149,7 +160,7 @@ class CheckDynamoDB < Sensu::Plugin::Check::CLI
|
|
149
160
|
threshold = config[:"#{severity}_over"]
|
150
161
|
next unless threshold
|
151
162
|
next if metric_value < threshold
|
152
|
-
flag_alert severity, "; On table #{table.
|
163
|
+
flag_alert severity, "; On table #{table.table_name} #{r_or_w.to_s.capitalize}ThrottleEvents is #{metric_value} (higher_than #{threshold})"
|
153
164
|
break
|
154
165
|
end
|
155
166
|
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-ec2-cpu_balance
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This plugin retrieves the value of the cpu balance for all servers
|
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-ec2-cpu_balance -c 20
|
20
|
+
#
|
21
|
+
# NOTES:
|
22
|
+
#
|
23
|
+
# LICENSE:
|
24
|
+
# Shane Starcher
|
25
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
26
|
+
# for details.
|
27
|
+
#
|
28
|
+
|
29
|
+
require 'sensu-plugins-aws'
|
30
|
+
require 'sensu-plugin/check/cli'
|
31
|
+
require 'aws-sdk'
|
32
|
+
|
33
|
+
class EC2CpuBalance < Sensu::Plugin::Check::CLI
|
34
|
+
include Common
|
35
|
+
|
36
|
+
option :critical,
|
37
|
+
description: 'Trigger a critical when value is below VALUE',
|
38
|
+
short: '-c VALUE',
|
39
|
+
long: '--critical VALUE',
|
40
|
+
proc: proc(&:to_f),
|
41
|
+
required: true
|
42
|
+
|
43
|
+
option :warning,
|
44
|
+
description: 'Trigger a warning when value is below VALUE',
|
45
|
+
short: '-w VALUE',
|
46
|
+
long: '--warning VALUE',
|
47
|
+
proc: proc(&:to_f)
|
48
|
+
|
49
|
+
option :aws_region,
|
50
|
+
short: '-r R',
|
51
|
+
long: '--region REGION',
|
52
|
+
description: 'AWS region',
|
53
|
+
default: 'us-east-1'
|
54
|
+
|
55
|
+
def data(instance)
|
56
|
+
client = Aws::CloudWatch::Client.new
|
57
|
+
stats = 'Average'
|
58
|
+
period = 60
|
59
|
+
resp = client.get_metric_statistics(
|
60
|
+
namespace: 'AWS/EC2',
|
61
|
+
metric_name: 'CPUCreditBalance',
|
62
|
+
dimensions: [{
|
63
|
+
name: 'InstanceId',
|
64
|
+
value: instance
|
65
|
+
}],
|
66
|
+
start_time: Time.now - period * 10,
|
67
|
+
end_time: Time.now,
|
68
|
+
period: period,
|
69
|
+
statistics: [stats]
|
70
|
+
)
|
71
|
+
|
72
|
+
return resp.datapoints.first.send(stats.downcase) unless resp.datapoints.first.nil?
|
73
|
+
end
|
74
|
+
|
75
|
+
def run
|
76
|
+
ec2 = Aws::EC2::Client.new
|
77
|
+
instances = ec2.describe_instances(
|
78
|
+
filters: [
|
79
|
+
{
|
80
|
+
name: 'instance-state-name',
|
81
|
+
values: ['running']
|
82
|
+
}
|
83
|
+
])
|
84
|
+
|
85
|
+
messages = "\n"
|
86
|
+
level = 0
|
87
|
+
instances.reservations.each do |reservation|
|
88
|
+
reservation.instances.each do |instance|
|
89
|
+
next unless instance.instance_type.start_with? 't2.'
|
90
|
+
id = instance.instance_id
|
91
|
+
result = data id
|
92
|
+
unless result.nil?
|
93
|
+
if result < config[:critical]
|
94
|
+
level = 2
|
95
|
+
messages << "#{id} is below critical threshold [#{config[:critical]} < #{result}]\n"
|
96
|
+
elsif config[:warning] && result < config[:warning]
|
97
|
+
level = 1 if level == 0
|
98
|
+
messages << "#{id} is below warning threshold [#{config[:warning]} < #{result}]\n"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
ok messages if level == 0
|
104
|
+
warning messages if level == 1
|
105
|
+
critical messages if level == 2
|
106
|
+
end
|
107
|
+
end
|