sensu-plugins-aws-boutetnico 1.0.6 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -220
- data/bin/check-expiring-reservations.rb +1 -1
- data/bin/metrics-cloudwatch-ebs.rb +165 -0
- data/bin/metrics-cloudwatch-ec2.rb +171 -0
- data/bin/metrics-cloudwatch-ses.rb +128 -0
- data/bin/metrics-ses-usage.rb +68 -0
- data/lib/sensu-plugins-aws/version.rb +2 -2
- metadata +9 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14aefd0ae3cc72aa7dbd592f227c1643b624415ac69268267502c25c913f0289
|
4
|
+
data.tar.gz: 7d2436a38fda39835d0d3b763f4d830c0cede2888ff2a78d768230ffa68f89aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a05ad94ff9da240670b27aad97a697a4cce3d7cce48a4f88d7fb41dcd96906b5f10010bf352916214eb7fc41973c7a295be203313480ba38e79e1d47c1784a86
|
7
|
+
data.tar.gz: 14536556c223a3cd93a83a9c63a164888a6439697ba1f7b776c7130d090a1958f3324a8cade4293387b1109a6fa6306ccd6952a99e65cc71a3cd422bd5692745
|
data/README.md
CHANGED
@@ -11,226 +11,6 @@ Due to the lack of activity from owners of [sensu-plugins-aws](https://github.co
|
|
11
11
|
## Sensu Asset
|
12
12
|
The Sensu assets packaged from this repository are built against the Sensu Ruby runtime environment. When using these assets as part of a Sensu Go resource (check, mutator or handler), make sure you include the corresponding Sensu Ruby runtime asset in the list of assets needed by the resource. The current ruby-runtime assets can be found [here](https://bonsai.sensu.io/assets/sensu/sensu-ruby-runtime) in the [Bonsai Asset Index](bonsai.sensu.io).
|
13
13
|
|
14
|
-
## Functionality
|
15
|
-
|
16
|
-
**check-alb-target-group-health.rb**
|
17
|
-
|
18
|
-
**check-asg-instances-created.rb**
|
19
|
-
|
20
|
-
**check-asg-instances-inservice.rb**
|
21
|
-
|
22
|
-
**check-autoscaling-cpucredits.rb**
|
23
|
-
|
24
|
-
**check-beanstalk-elb-metric.rb**
|
25
|
-
|
26
|
-
**check-certificate-expiry.rb**
|
27
|
-
|
28
|
-
**check-cloudwatch-alarm**
|
29
|
-
|
30
|
-
**check-cloudwatch-alarms**
|
31
|
-
|
32
|
-
**check-cloudwatch-composite-metric**
|
33
|
-
|
34
|
-
**check-cloudwatch-metric**
|
35
|
-
|
36
|
-
**check-cloudfront-tag**
|
37
|
-
|
38
|
-
**check-configservice-rules**
|
39
|
-
|
40
|
-
**check-dynamodb-capacity.rb**
|
41
|
-
|
42
|
-
**check-dynamodb-throttle.rb**
|
43
|
-
|
44
|
-
**check-direct-connect-virtual-interfaces.rb**
|
45
|
-
|
46
|
-
**check-ebs-snapshots.rb**
|
47
|
-
|
48
|
-
**check-ebs-burst-limit.rb**
|
49
|
-
|
50
|
-
**check-ec2-cpu_balance.rb**
|
51
|
-
|
52
|
-
**check-ec2-filter.rb**
|
53
|
-
|
54
|
-
**check-ec2-network.rb**
|
55
|
-
|
56
|
-
**check-ecs-service-health.rb**
|
57
|
-
|
58
|
-
**check-efs-metric.rb**
|
59
|
-
|
60
|
-
**check-eip-allocation.rb**
|
61
|
-
|
62
|
-
**check-elasticache-failover.rb**
|
63
|
-
|
64
|
-
**check-elb-certs.rb**
|
65
|
-
|
66
|
-
**check-elb-health-fog.rb**
|
67
|
-
|
68
|
-
**check-elb-health-sdk.rb**
|
69
|
-
|
70
|
-
**check-elb-health.rb**
|
71
|
-
|
72
|
-
**check-elb-instances-inservice.rb**
|
73
|
-
|
74
|
-
**check-elb-latency.rb**
|
75
|
-
|
76
|
-
**check-elb-nodes.rb**
|
77
|
-
|
78
|
-
**check-elb-sum-requests.rb**
|
79
|
-
|
80
|
-
**check-emr-cluster.rb**
|
81
|
-
|
82
|
-
**check-emr-steps.rb**
|
83
|
-
|
84
|
-
**check-eni-status.rb**
|
85
|
-
|
86
|
-
**check-instance-events.rb**
|
87
|
-
|
88
|
-
**check-instance-health.rb**
|
89
|
-
|
90
|
-
**check-kms-key.rb**
|
91
|
-
|
92
|
-
**check-rds-events.rb**
|
93
|
-
|
94
|
-
**check-rds-pending.rb**
|
95
|
-
|
96
|
-
**check-rds.rb**
|
97
|
-
|
98
|
-
**check-redshift-events.rb**
|
99
|
-
|
100
|
-
**check-reserved-instances.rb**
|
101
|
-
|
102
|
-
**check-route53-domain-expiration.rb**
|
103
|
-
|
104
|
-
**check-s3-bucket.rb**
|
105
|
-
|
106
|
-
**check-s3-bucket-visibility.rb**
|
107
|
-
|
108
|
-
**check-s3-object.rb**
|
109
|
-
|
110
|
-
**check-s3-tag.rb**
|
111
|
-
|
112
|
-
**check-ses-limit.rb**
|
113
|
-
|
114
|
-
**check-ses-statistics.rb**
|
115
|
-
|
116
|
-
**check-sns-subscriptions**
|
117
|
-
|
118
|
-
**check-sqs-messages.rb**
|
119
|
-
|
120
|
-
**check-subnet-ip-consumption**
|
121
|
-
|
122
|
-
**check-vpc-nameservers**
|
123
|
-
|
124
|
-
**check-instances-count.rb**
|
125
|
-
|
126
|
-
**check-vpc-vpn.rb**
|
127
|
-
|
128
|
-
**handler-ec2_node.rb**
|
129
|
-
|
130
|
-
**handler-scale-asg-down.rb**
|
131
|
-
|
132
|
-
**handler-scale-asg-up.rb**
|
133
|
-
|
134
|
-
**handler-ses.rb**
|
135
|
-
|
136
|
-
**handler-sns.rb**
|
137
|
-
|
138
|
-
**metrics-asg.rb**
|
139
|
-
|
140
|
-
**metrics-autoscaling-instance-count.rb**
|
141
|
-
|
142
|
-
**metrics-billing.rb**
|
143
|
-
|
144
|
-
**metrics-ec2-count.rb**
|
145
|
-
|
146
|
-
**metrics-ec2-filter.rb**
|
147
|
-
|
148
|
-
**metrics-elasticache.rb**
|
149
|
-
|
150
|
-
**metrics-elb-full.rb**
|
151
|
-
|
152
|
-
**metrics-elb.rb**
|
153
|
-
|
154
|
-
**metrics-emr-steps.rb**
|
155
|
-
|
156
|
-
**metrics-rds.rb**
|
157
|
-
|
158
|
-
**metrics-s3.rb**
|
159
|
-
|
160
|
-
**metrics-ses.rb**
|
161
|
-
|
162
|
-
**metrics-sqs.rb**
|
163
|
-
|
164
|
-
|
165
|
-
## Files
|
166
|
-
|
167
|
-
* /bin/check-alb-target-group-health.rb
|
168
|
-
* /bin/check-asg-instances-created.rb
|
169
|
-
* /bin/check-autoscaling-cpucredits.rb
|
170
|
-
* /bin/check-asg-instances-inservice.rb
|
171
|
-
* /bin/check-beanstalk-elb-metric.rb
|
172
|
-
* /bin/check-certificate-expiry.rb
|
173
|
-
* /bin/check-configservice-rules.rb
|
174
|
-
* /bin/check-cloudfront-tag.rb
|
175
|
-
* /bin/check-cloudwatch-alarm.rb
|
176
|
-
* /bin/check-cloudwatch-metric.rb
|
177
|
-
* /bin/check-cloudwatch-composite-metric.rb
|
178
|
-
* /bin/check-dynamodb-capacity.rb
|
179
|
-
* /bin/check-dynamodb-throttle.rb
|
180
|
-
* /bin/check-direct-connect-virtual-interfaces.rb
|
181
|
-
* /bin/check-ebs-burst-limit.rb
|
182
|
-
* /bin/check-ebs-snapshots.rb
|
183
|
-
* /bin/check-ec2-filter.rb
|
184
|
-
* /bin/check-ec2-network.rb
|
185
|
-
* /bin/check-ecs-service-health.rb
|
186
|
-
* /bin/check-efs-metric.rb
|
187
|
-
* /bin/check-elasticache-failover.rb
|
188
|
-
* /bin/check-elb-certs.rb
|
189
|
-
* /bin/check-elb-health-fog.rb
|
190
|
-
* /bin/check-elb-health-sdk.rb
|
191
|
-
* /bin/check-elb-health.rb
|
192
|
-
* /bin/check-elb-instances-inservice.rb
|
193
|
-
* /bin/check-elb-latency.rb
|
194
|
-
* /bin/check-elb-nodes.rb
|
195
|
-
* /bin/check-elb-sum-requests.rb
|
196
|
-
* /bin/check-emr-cluster.rb
|
197
|
-
* /bin/check-emr-steps.rb
|
198
|
-
* /bin/check-eni-status.rb
|
199
|
-
* /bin/check-expiring-reservations.rb
|
200
|
-
* /bin/check-instance-events.rb
|
201
|
-
* /bin/check-rds-events.rb
|
202
|
-
* /bin/check-rds-pending.rb
|
203
|
-
* /bin/check-rds.rb
|
204
|
-
* /bin/check-redshift-events.rb
|
205
|
-
* /bin/check-route53-domain-expiration.rb
|
206
|
-
* /bin/check-s3-object.rb
|
207
|
-
* /bin/check-s3-tag.rb
|
208
|
-
* /bin/check-ses-limit.rb
|
209
|
-
* /bin/check-ses-statistics.rb
|
210
|
-
* /bin/check-sqs-messages.rb
|
211
|
-
* /bin/check-subnet-ip-consumption.rb
|
212
|
-
* /bin/check-vpc-nameservers.rb
|
213
|
-
* /bin/check_vpc_vpn.py
|
214
|
-
* /bin/check_vpc_vpn.rb
|
215
|
-
* /bin/handler-ec2_node.rb
|
216
|
-
* /bin/handler-ses.rb
|
217
|
-
* /bin/handler-sns.rb
|
218
|
-
* /bin/metrics-autoscaling-instance-count.rb
|
219
|
-
* /bin/check-instances-count.rb
|
220
|
-
* /bin/metrics-asg.rb
|
221
|
-
* /bin/metrics-billing.rb
|
222
|
-
* /bin/metrics-ec2-count.rb
|
223
|
-
* /bin/metrics-ec2-filter.rb
|
224
|
-
* /bin/metrics-elasticache.rb
|
225
|
-
* /bin/metrics-elb-full.rb
|
226
|
-
* /bin/metrics-elb.rb
|
227
|
-
* /bin/metrics-emr-steps.rb
|
228
|
-
* /bin/metrics-rds.rb
|
229
|
-
* /bin/metrics-reservation-utilization.rb
|
230
|
-
* /bin/metrics-s3.rb
|
231
|
-
* /bin/metrics-ses.rb
|
232
|
-
* /bin/metrics-sqs.rb
|
233
|
-
|
234
14
|
## Usage
|
235
15
|
|
236
16
|
**handler-ses**
|
@@ -0,0 +1,165 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# metrics-cloudwatch-ebs
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# Fetch EBS metrics from CloudWatch and store them into 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
|
+
# ./metrics-cloudwatch-ebs -m BurstBalance
|
22
|
+
# ./metrics-cloudwatch-ebs -m BurstBalance -t Name
|
23
|
+
# ./metrics-cloudwatch-ebs -m BurstBalance -t Name -F "{name:tag-value,values:[staging]}"
|
24
|
+
#
|
25
|
+
# NOTES:
|
26
|
+
#
|
27
|
+
# LICENSE:
|
28
|
+
# Copyright 2018 Nicolas Boutet
|
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/filter'
|
35
|
+
require 'aws-sdk'
|
36
|
+
require 'sensu-plugins-aws'
|
37
|
+
require 'time'
|
38
|
+
|
39
|
+
class CloudWatchEc2Metrics < Sensu::Plugin::Metric::CLI::Graphite
|
40
|
+
include Common
|
41
|
+
include Filter
|
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.cloudwatch.ebs'
|
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
|
+
option :tag,
|
75
|
+
description: 'Add instance TAG value to metrics instead of instance id.',
|
76
|
+
short: '-t TAG',
|
77
|
+
long: '--tag TAG'
|
78
|
+
|
79
|
+
option :filter,
|
80
|
+
short: '-F FILTER',
|
81
|
+
long: '--filter FILTER',
|
82
|
+
description: 'String representation of the filter to apply',
|
83
|
+
default: '{}'
|
84
|
+
|
85
|
+
def cloud_watch
|
86
|
+
@cloud_watch ||= Aws::CloudWatch::Client.new
|
87
|
+
end
|
88
|
+
|
89
|
+
def cloud_watch_metric(metric_name, value, volume)
|
90
|
+
cloud_watch.get_metric_statistics(
|
91
|
+
namespace: 'AWS/EBS',
|
92
|
+
metric_name: metric_name,
|
93
|
+
dimensions: [
|
94
|
+
{
|
95
|
+
name: 'VolumeId',
|
96
|
+
value: volume.ebs.volume_id
|
97
|
+
}
|
98
|
+
],
|
99
|
+
statistics: [value],
|
100
|
+
start_time: config[:end_time] - config[:period],
|
101
|
+
end_time: config[:end_time],
|
102
|
+
period: config[:period]
|
103
|
+
)
|
104
|
+
end
|
105
|
+
|
106
|
+
def print_statistics(statistics, instance)
|
107
|
+
statistics.each do |key, static|
|
108
|
+
instance.block_device_mappings.each do |volume|
|
109
|
+
r = cloud_watch_metric(key, static, volume)
|
110
|
+
keys = [config[:scheme]]
|
111
|
+
instance_name = config[:tag] ? instance_tag(instance, config[:tag]).to_s : instance.instance_id
|
112
|
+
keys.concat [instance_name, volume.device_name, key, static]
|
113
|
+
output(keys.join('.'), r[:datapoints].first[static.downcase]) unless r[:datapoints].first.nil?
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def print_metrics(metrics, instance)
|
119
|
+
metrics_statistic = {
|
120
|
+
'BurstBalance' => 'Average'
|
121
|
+
}
|
122
|
+
|
123
|
+
metrics.each do |metric|
|
124
|
+
statistic = metrics_statistic.select { |key, _| key == metric }
|
125
|
+
if statistic.empty?
|
126
|
+
unknown "Invalid metric #{metric}. Possible values: #{metrics_statistic.keys.join(',')}"
|
127
|
+
end
|
128
|
+
print_statistics(statistic, instance)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def parse_metrics(metrics)
|
133
|
+
if metrics.nil?
|
134
|
+
unknown 'No metrics provided. See usage for details'
|
135
|
+
end
|
136
|
+
metrics.split(',')
|
137
|
+
end
|
138
|
+
|
139
|
+
def instance_tag(instance, tag_name)
|
140
|
+
tag = instance.tags.select { |t| t.key == tag_name }.first
|
141
|
+
tag.nil? ? '' : tag.value
|
142
|
+
end
|
143
|
+
|
144
|
+
def run
|
145
|
+
filters = Filter.parse(config[:filter])
|
146
|
+
filters.push(
|
147
|
+
name: 'instance-state-name',
|
148
|
+
values: ['running']
|
149
|
+
)
|
150
|
+
ec2 = Aws::EC2::Client.new
|
151
|
+
instances = ec2.describe_instances(
|
152
|
+
filters: filters
|
153
|
+
)
|
154
|
+
|
155
|
+
metrics = parse_metrics(config[:metrics])
|
156
|
+
|
157
|
+
instances.reservations.each do |reservation|
|
158
|
+
reservation.instances.each do |instance|
|
159
|
+
print_metrics(metrics, instance)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
ok
|
164
|
+
end
|
165
|
+
end
|
@@ -0,0 +1,171 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# metrics-cloudwatch-ec2
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# Fetch EC2 metrics from CloudWatch and store them into 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
|
+
# ./metrics-cloudwatch-ec2 -m CPUCreditBalance
|
22
|
+
# ./metrics-cloudwatch-ec2 -m CPUCreditBalance -t Name
|
23
|
+
# ./metrics-cloudwatch-ec2 -m CPUCreditBalance -t Name -F "{name:tag-value,values:[staging]}"
|
24
|
+
#
|
25
|
+
# NOTES:
|
26
|
+
#
|
27
|
+
# LICENSE:
|
28
|
+
# Copyright 2018 Nicolas Boutet
|
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/filter'
|
35
|
+
require 'aws-sdk'
|
36
|
+
require 'sensu-plugins-aws'
|
37
|
+
require 'time'
|
38
|
+
|
39
|
+
class CloudWatchEc2Metrics < Sensu::Plugin::Metric::CLI::Graphite
|
40
|
+
include Common
|
41
|
+
include Filter
|
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.cloudwatch.ec2'
|
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
|
+
option :tag,
|
75
|
+
description: 'Add instance TAG value to metrics instead of instance id.',
|
76
|
+
short: '-t TAG',
|
77
|
+
long: '--tag TAG'
|
78
|
+
|
79
|
+
option :instance_families,
|
80
|
+
description: 'List of burstable instance families to check. Default to t2,t3',
|
81
|
+
short: '-f t2,t3',
|
82
|
+
long: '--instance-families t2,t3',
|
83
|
+
proc: proc { |x| x.split(',') },
|
84
|
+
default: %w[t2 t3]
|
85
|
+
|
86
|
+
option :filter,
|
87
|
+
short: '-F FILTER',
|
88
|
+
long: '--filter FILTER',
|
89
|
+
description: 'String representation of the filter to apply',
|
90
|
+
default: '{}'
|
91
|
+
|
92
|
+
def cloud_watch
|
93
|
+
@cloud_watch ||= Aws::CloudWatch::Client.new
|
94
|
+
end
|
95
|
+
|
96
|
+
def cloud_watch_metric(metric_name, value, instance)
|
97
|
+
cloud_watch.get_metric_statistics(
|
98
|
+
namespace: 'AWS/EC2',
|
99
|
+
metric_name: metric_name,
|
100
|
+
dimensions: [
|
101
|
+
{
|
102
|
+
name: 'InstanceId',
|
103
|
+
value: instance.instance_id
|
104
|
+
}
|
105
|
+
],
|
106
|
+
statistics: [value],
|
107
|
+
start_time: config[:end_time] - config[:period],
|
108
|
+
end_time: config[:end_time],
|
109
|
+
period: config[:period]
|
110
|
+
)
|
111
|
+
end
|
112
|
+
|
113
|
+
def print_statistics(statistics, instance)
|
114
|
+
statistics.each do |key, static|
|
115
|
+
r = cloud_watch_metric(key, static, instance)
|
116
|
+
keys = [config[:scheme]]
|
117
|
+
tag = config[:tag] ? instance_tag(instance, config[:tag]).to_s : instance.instance_id
|
118
|
+
keys.concat [tag, key, static]
|
119
|
+
output(keys.join('.'), r[:datapoints].first[static.downcase]) unless r[:datapoints].first.nil?
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def print_metrics(metrics, instance)
|
124
|
+
metrics_statistic = {
|
125
|
+
'CPUCreditBalance' => 'Average'
|
126
|
+
}
|
127
|
+
|
128
|
+
metrics.each do |metric|
|
129
|
+
statistic = metrics_statistic.select { |key, _| key == metric }
|
130
|
+
if statistic.empty?
|
131
|
+
unknown "Invalid metric #{metric}. Possible values: #{metrics_statistic.keys.join(',')}"
|
132
|
+
end
|
133
|
+
print_statistics(statistic, instance)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def parse_metrics(metrics)
|
138
|
+
if metrics.nil?
|
139
|
+
unknown 'No metrics provided. See usage for details'
|
140
|
+
end
|
141
|
+
metrics.split(',')
|
142
|
+
end
|
143
|
+
|
144
|
+
def instance_tag(instance, tag_name)
|
145
|
+
tag = instance.tags.select { |t| t.key == tag_name }.first
|
146
|
+
tag.nil? ? '' : tag.value
|
147
|
+
end
|
148
|
+
|
149
|
+
def run
|
150
|
+
filters = Filter.parse(config[:filter])
|
151
|
+
filters.push(
|
152
|
+
name: 'instance-state-name',
|
153
|
+
values: ['running']
|
154
|
+
)
|
155
|
+
ec2 = Aws::EC2::Client.new
|
156
|
+
instances = ec2.describe_instances(
|
157
|
+
filters: filters
|
158
|
+
)
|
159
|
+
|
160
|
+
metrics = parse_metrics(config[:metrics])
|
161
|
+
|
162
|
+
instances.reservations.each do |reservation|
|
163
|
+
reservation.instances.each do |instance|
|
164
|
+
next unless instance.instance_type.start_with?(*config[:instance_families])
|
165
|
+
print_metrics(metrics, instance)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
ok
|
170
|
+
end
|
171
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# metrics-cloudwatch-ses
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# Fetch SES metrics from CloudWatch and store them into 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
|
+
# ./metrics-cloudwatch-ses -m Send
|
22
|
+
# ./metrics-cloudwatch-ses -m Send,Open -p 3600
|
23
|
+
#
|
24
|
+
# NOTES:
|
25
|
+
#
|
26
|
+
# LICENSE:
|
27
|
+
# Copyright 2018 Nicolas Boutet
|
28
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
29
|
+
# for details.
|
30
|
+
#
|
31
|
+
|
32
|
+
require 'sensu-plugin/metric/cli'
|
33
|
+
require 'aws-sdk'
|
34
|
+
require 'sensu-plugins-aws'
|
35
|
+
require 'time'
|
36
|
+
|
37
|
+
class CloudWatchSesMetrics < Sensu::Plugin::Metric::CLI::Graphite
|
38
|
+
include Common
|
39
|
+
option :scheme,
|
40
|
+
description: 'Metric naming scheme, text to prepend to metric',
|
41
|
+
short: '-s SCHEME',
|
42
|
+
long: '--scheme SCHEME',
|
43
|
+
default: 'aws.cloudwatch.ses'
|
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 :metrics,
|
52
|
+
description: 'Commas separated list of metric(s) to fetch',
|
53
|
+
short: '-m METRIC1,METRIC2',
|
54
|
+
long: '--metrics METRIC1,METRIC2'
|
55
|
+
|
56
|
+
option :end_time,
|
57
|
+
short: '-t T',
|
58
|
+
long: '--end-time TIME',
|
59
|
+
default: Time.now,
|
60
|
+
proc: proc { |a| Time.parse a },
|
61
|
+
description: 'CloudWatch metric statistics end time'
|
62
|
+
|
63
|
+
option :period,
|
64
|
+
short: '-p N',
|
65
|
+
long: '--period SECONDS',
|
66
|
+
default: 60,
|
67
|
+
proc: proc(&:to_i),
|
68
|
+
description: 'CloudWatch metric statistics period'
|
69
|
+
|
70
|
+
def cloud_watch
|
71
|
+
@cloud_watch ||= Aws::CloudWatch::Client.new
|
72
|
+
end
|
73
|
+
|
74
|
+
def cloud_watch_metric(metric_name, value)
|
75
|
+
cloud_watch.get_metric_statistics(
|
76
|
+
namespace: 'AWS/SES',
|
77
|
+
metric_name: metric_name,
|
78
|
+
dimensions: [],
|
79
|
+
statistics: [value],
|
80
|
+
start_time: config[:end_time] - config[:period],
|
81
|
+
end_time: config[:end_time],
|
82
|
+
period: config[:period]
|
83
|
+
)
|
84
|
+
end
|
85
|
+
|
86
|
+
def print_statistics(statistics)
|
87
|
+
statistics.each do |key, static|
|
88
|
+
r = cloud_watch_metric(key, static)
|
89
|
+
keys = [config[:scheme]]
|
90
|
+
keys.concat [key, static]
|
91
|
+
output(keys.join('.'), r[:datapoints].first[static.downcase]) unless r[:datapoints].first.nil?
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def print_metrics(metrics)
|
96
|
+
metrics_statistic = {
|
97
|
+
'Bounce' => 'Sum',
|
98
|
+
'Click' => 'Sum',
|
99
|
+
'Complaint' => 'Sum',
|
100
|
+
'Delivery' => 'Average',
|
101
|
+
'Open' => 'Sum',
|
102
|
+
'Reputation.BounceRate' => 'Average',
|
103
|
+
'Reputation.ComplaintRate' => 'Average',
|
104
|
+
'Send' => 'Sum'
|
105
|
+
}
|
106
|
+
|
107
|
+
metrics.each do |metric|
|
108
|
+
statistic = metrics_statistic.select { |key, _| key == metric }
|
109
|
+
if statistic.empty?
|
110
|
+
unknown "Invalid metric #{metric}. Possible values: #{metrics_statistic.keys.join(',')}"
|
111
|
+
end
|
112
|
+
print_statistics(statistic)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def parse_metrics(metrics)
|
117
|
+
if metrics.nil?
|
118
|
+
unknown 'No metrics provided. See usage for details'
|
119
|
+
end
|
120
|
+
metrics.split(',')
|
121
|
+
end
|
122
|
+
|
123
|
+
def run
|
124
|
+
metrics = parse_metrics(config[:metrics])
|
125
|
+
print_metrics(metrics)
|
126
|
+
ok
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# metrics-ses-usage
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# Gets your SES sending usage and limit and store them into Graphite.
|
7
|
+
#
|
8
|
+
# OUTPUT:
|
9
|
+
# plain-text
|
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-cloudwatch-ses -r eu-west-1
|
21
|
+
#
|
22
|
+
# NOTES:
|
23
|
+
#
|
24
|
+
# LICENSE:
|
25
|
+
# Copyright 2018 Nicolas Boutet
|
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 MetricsSESUsage < Sensu::Plugin::Metric::CLI::Graphite
|
35
|
+
include Common
|
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 :scheme,
|
43
|
+
description: 'Metric naming scheme, text to prepend to metric',
|
44
|
+
short: '-s SCHEME',
|
45
|
+
long: '--scheme SCHEME',
|
46
|
+
required: true,
|
47
|
+
default: 'aws.ses.usage'
|
48
|
+
|
49
|
+
def run
|
50
|
+
begin
|
51
|
+
ses = Aws::SES::Client.new
|
52
|
+
response = ses.get_send_quota
|
53
|
+
rescue StandardError => e
|
54
|
+
unknown "An issue occured while communicating with the AWS SES API: #{e.message}"
|
55
|
+
end
|
56
|
+
|
57
|
+
unknown 'Empty response from AWS SES API' if response.empty? # Can this happen?
|
58
|
+
|
59
|
+
percent = ((response.sent_last_24_hours.to_f / response.max_24_hour_send.to_f) * 100).to_f.round(2)
|
60
|
+
|
61
|
+
output "#{config[:scheme]}.max_24_hour_send", response.max_24_hour_send.to_f
|
62
|
+
output "#{config[:scheme]}.max_send_rate", response.max_send_rate.to_f
|
63
|
+
output "#{config[:scheme]}.sent_last_24_hours", response.sent_last_24_hours.to_f
|
64
|
+
output "#{config[:scheme]}.quota_used", percent
|
65
|
+
|
66
|
+
ok
|
67
|
+
end
|
68
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-aws-boutetnico
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sensu-Plugins and contributors
|
@@ -253,6 +253,7 @@ executables:
|
|
253
253
|
- metrics-autoscaling-instance-count.rb
|
254
254
|
- check-cloudwatch-alarm.rb
|
255
255
|
- check-dynamodb-throttle.rb
|
256
|
+
- metrics-cloudwatch-ebs.rb
|
256
257
|
- check-cloudwatch-alarms.rb
|
257
258
|
- check-kms-key.rb
|
258
259
|
- check-ses-limit.rb
|
@@ -282,6 +283,7 @@ executables:
|
|
282
283
|
- check-ebs-snapshots.rb
|
283
284
|
- metrics-waf.rb
|
284
285
|
- metrics-billing.rb
|
286
|
+
- metrics-cloudwatch-ec2.rb
|
285
287
|
- check-autoscaling-cpucredits.rb
|
286
288
|
- metrics-asg.rb
|
287
289
|
- check-instance-events.rb
|
@@ -302,8 +304,10 @@ executables:
|
|
302
304
|
- check-cloudwatch-metric.rb
|
303
305
|
- check-beanstalk-health.rb
|
304
306
|
- check-dynamodb-capacity.rb
|
307
|
+
- metrics-cloudwatch-ses.rb
|
305
308
|
- check-eni-status.rb
|
306
309
|
- check-s3-tag.rb
|
310
|
+
- metrics-ses-usage.rb
|
307
311
|
- check-direct-connect-virtual-interfaces.rb
|
308
312
|
- check-cloudwatch-composite-metric.rb
|
309
313
|
- metrics-ec2-count.rb
|
@@ -407,6 +411,9 @@ files:
|
|
407
411
|
- bin/metrics-autoscaling-instance-count.rb
|
408
412
|
- bin/metrics-billing.rb
|
409
413
|
- bin/metrics-cloudfront.rb
|
414
|
+
- bin/metrics-cloudwatch-ebs.rb
|
415
|
+
- bin/metrics-cloudwatch-ec2.rb
|
416
|
+
- bin/metrics-cloudwatch-ses.rb
|
410
417
|
- bin/metrics-ec2-count.rb
|
411
418
|
- bin/metrics-ec2-filter.rb
|
412
419
|
- bin/metrics-elasticache.rb
|
@@ -415,6 +422,7 @@ files:
|
|
415
422
|
- bin/metrics-rds.rb
|
416
423
|
- bin/metrics-reservation-utilization.rb
|
417
424
|
- bin/metrics-s3.rb
|
425
|
+
- bin/metrics-ses-usage.rb
|
418
426
|
- bin/metrics-ses.rb
|
419
427
|
- bin/metrics-sqs.rb
|
420
428
|
- bin/metrics-waf.rb
|