sensu-plugins-aws 0.0.1.alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,150 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # elb-latency-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: sensu-plugin
16
+ #
17
+ # USAGE:
18
+ # #YELLOW
19
+ #
20
+ # NOTES:
21
+ # Returns latency statistics by default. You can specify any valid ELB metric type, see
22
+ # http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/CW_Support_For_AWS.html#elb-metricscollected
23
+ #
24
+ # By default fetches statistics from one minute ago. You may need to fetch further back than this;
25
+ # high traffic ELBs can sometimes experience statistic delays of up to 10 minutes. If you experience this,
26
+ # raising a ticket with AWS support should get the problem resolved.
27
+ # As a workaround you can use eg -f 300 to fetch data from 5 minutes ago.
28
+ #
29
+ # LICENSE:
30
+ # Copyright 2013 Bashton Ltd http://www.bashton.com/
31
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
32
+ # for details.
33
+ #
34
+ #
35
+
36
+ require 'rubygems' if RUBY_VERSION < '1.9.0'
37
+ require 'sensu-plugin/metric/cli'
38
+ require 'aws-sdk'
39
+
40
+ class ELBMetrics < Sensu::Plugin::Metric::CLI::Graphite
41
+ option :elbname,
42
+ description: 'Name of the Elastic Load Balancer',
43
+ short: '-n ELB_NAME',
44
+ long: '--name ELB_NAME'
45
+
46
+ option :scheme,
47
+ description: 'Metric naming scheme, text to prepend to metric',
48
+ short: '-s SCHEME',
49
+ long: '--scheme SCHEME',
50
+ default: ''
51
+
52
+ option :fetch_age,
53
+ description: 'How long ago to fetch metrics for',
54
+ short: '-f AGE',
55
+ long: '--fetch_age',
56
+ default: 60,
57
+ proc: proc(&:to_i)
58
+
59
+ option :metric,
60
+ description: 'Metric to fetch',
61
+ short: '-m METRIC',
62
+ long: '--metric',
63
+ default: 'Latency'
64
+
65
+ option :statistic,
66
+ rescription: 'Statistics type',
67
+ short: '-t STATISTIC',
68
+ long: '--statistic',
69
+ default: ''
70
+
71
+ option :aws_access_key,
72
+ short: '-a AWS_ACCESS_KEY',
73
+ long: '--aws-access-key AWS_ACCESS_KEY',
74
+ description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY'] or provide it as an option",
75
+ default: ENV['AWS_ACCESS_KEY']
76
+
77
+ option :aws_secret_access_key,
78
+ short: '-k AWS_SECRET_KEY',
79
+ long: '--aws-secret-access-key AWS_SECRET_KEY',
80
+ description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_KEY'] or provide it as an option",
81
+ default: ENV['AWS_SECRET_KEY']
82
+
83
+ option :aws_region,
84
+ short: '-r AWS_REGION',
85
+ long: '--aws-region REGION',
86
+ description: 'AWS Region (such as eu-west-1).',
87
+ default: 'us-east-1'
88
+
89
+ def aws_config
90
+ hash = {}
91
+ hash.update access_key_id: config[:access_key_id], secret_access_key: config[:secret_access_key] if config[:access_key_id] && config[:secret_access_key]
92
+ hash.update region: config[:aws_region]
93
+ hash
94
+ end
95
+
96
+ def run
97
+ statistic = ''
98
+ if config[:statistic] == ''
99
+ default_statistic_per_metric = {
100
+ 'Latency' => 'Average',
101
+ 'RequestCount' => 'Sum',
102
+ 'UnHealthyHostCount' => 'Average',
103
+ 'HealthyHostCount' => 'Average',
104
+ 'HTTPCode_Backend_2XX' => 'Sum',
105
+ 'HTTPCode_Backend_4XX' => 'Sum',
106
+ 'HTTPCode_Backend_5XX' => 'Sum',
107
+ 'HTTPCode_ELB_4XX' => 'Sum',
108
+ 'HTTPCode_ELB_5XX' => 'Sum'
109
+ }
110
+ statistic = default_statistic_per_metric[config[:metric]]
111
+ else
112
+ statistic = config[:statistic]
113
+ end
114
+
115
+ begin
116
+ et = Time.now - config[:fetch_age]
117
+ st = et - 60
118
+
119
+ cw = AWS::CloudWatch::Client.new aws_config
120
+
121
+ options = {
122
+ 'namespace' => 'AWS/ELB',
123
+ 'metric_name' => config[:metric],
124
+ 'dimensions' => [
125
+ {
126
+ 'name' => 'LoadBalancerName',
127
+ 'value' => config[:elbname]
128
+ }
129
+ ],
130
+ 'statistics' => [statistic],
131
+ 'start_time' => st.iso8601,
132
+ 'end_time' => et.iso8601,
133
+ 'period' => 60
134
+ }
135
+ result = cw.get_metric_statistics(options)
136
+ data = result[:datapoints][0]
137
+ unless data.nil?
138
+ # We only return data when we have some to return
139
+ graphitepath = config[:scheme]
140
+ if config[:scheme] == ''
141
+ graphitepath = "#{config[:elbname]}.#{config[:metric].downcase}"
142
+ end
143
+ output graphitepath, data[statistic.downcase.to_sym], data[:timestamp].to_i
144
+ end
145
+ rescue => e
146
+ critical "Error: exception: #{e}"
147
+ end
148
+ ok
149
+ end
150
+ end
@@ -0,0 +1,150 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # elb-latency-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: sensu-plugin
16
+ #
17
+ # USAGE:
18
+ # #YELLOW
19
+ #
20
+ # NOTES:
21
+ # Returns latency statistics by default. You can specify any valid ELB metric type, see
22
+ # http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/CW_Support_For_AWS.html#elb-metricscollected
23
+ #
24
+ # By default fetches statistics from one minute ago. You may need to fetch further back than this;
25
+ # high traffic ELBs can sometimes experience statistic delays of up to 10 minutes. If you experience this,
26
+ # raising a ticket with AWS support should get the problem resolved.
27
+ # As a workaround you can use eg -f 300 to fetch data from 5 minutes ago.
28
+ #
29
+ # LICENSE:
30
+ # Copyright 2013 Bashton Ltd http://www.bashton.com/
31
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
32
+ # for details.
33
+ #
34
+ #
35
+
36
+ require 'rubygems' if RUBY_VERSION < '1.9.0'
37
+ require 'sensu-plugin/metric/cli'
38
+ require 'aws-sdk'
39
+
40
+ class ELBMetrics < Sensu::Plugin::Metric::CLI::Graphite
41
+ option :elbname,
42
+ description: 'Name of the Elastic Load Balancer',
43
+ short: '-n ELB_NAME',
44
+ long: '--name ELB_NAME'
45
+
46
+ option :scheme,
47
+ description: 'Metric naming scheme, text to prepend to metric',
48
+ short: '-s SCHEME',
49
+ long: '--scheme SCHEME',
50
+ default: ''
51
+
52
+ option :fetch_age,
53
+ description: 'How long ago to fetch metrics for',
54
+ short: '-f AGE',
55
+ long: '--fetch_age',
56
+ default: 60,
57
+ proc: proc(&:to_i)
58
+
59
+ option :metric,
60
+ description: 'Metric to fetch',
61
+ short: '-m METRIC',
62
+ long: '--metric',
63
+ default: 'Latency'
64
+
65
+ option :statistic,
66
+ rescription: 'Statistics type',
67
+ short: '-t STATISTIC',
68
+ long: '--statistic',
69
+ default: ''
70
+
71
+ option :aws_access_key,
72
+ short: '-a AWS_ACCESS_KEY',
73
+ long: '--aws-access-key AWS_ACCESS_KEY',
74
+ description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY'] or provide it as an option",
75
+ default: ENV['AWS_ACCESS_KEY']
76
+
77
+ option :aws_secret_access_key,
78
+ short: '-k AWS_SECRET_KEY',
79
+ long: '--aws-secret-access-key AWS_SECRET_KEY',
80
+ description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_KEY'] or provide it as an option",
81
+ default: ENV['AWS_SECRET_KEY']
82
+
83
+ option :aws_region,
84
+ short: '-r AWS_REGION',
85
+ long: '--aws-region REGION',
86
+ description: 'AWS Region (such as eu-west-1).',
87
+ default: 'us-east-1'
88
+
89
+ def aws_config
90
+ hash = {}
91
+ hash.update access_key_id: config[:access_key_id], secret_access_key: config[:secret_access_key] if config[:access_key_id] && config[:secret_access_key]
92
+ hash.update region: config[:aws_region]
93
+ hash
94
+ end
95
+
96
+ def run
97
+ statistic = ''
98
+ if config[:statistic] == ''
99
+ default_statistic_per_metric = {
100
+ 'Latency' => 'Average',
101
+ 'RequestCount' => 'Sum',
102
+ 'UnHealthyHostCount' => 'Average',
103
+ 'HealthyHostCount' => 'Average',
104
+ 'HTTPCode_Backend_2XX' => 'Sum',
105
+ 'HTTPCode_Backend_4XX' => 'Sum',
106
+ 'HTTPCode_Backend_5XX' => 'Sum',
107
+ 'HTTPCode_ELB_4XX' => 'Sum',
108
+ 'HTTPCode_ELB_5XX' => 'Sum'
109
+ }
110
+ statistic = default_statistic_per_metric[config[:metric]]
111
+ else
112
+ statistic = config[:statistic]
113
+ end
114
+
115
+ begin
116
+ et = Time.now - config[:fetch_age]
117
+ st = et - 60
118
+
119
+ cw = AWS::CloudWatch::Client.new aws_config
120
+
121
+ options = {
122
+ 'namespace' => 'AWS/ELB',
123
+ 'metric_name' => config[:metric],
124
+ 'dimensions' => [
125
+ {
126
+ 'name' => 'LoadBalancerName',
127
+ 'value' => config[:elbname]
128
+ }
129
+ ],
130
+ 'statistics' => [statistic],
131
+ 'start_time' => st.iso8601,
132
+ 'end_time' => et.iso8601,
133
+ 'period' => 60
134
+ }
135
+ result = cw.get_metric_statistics(options)
136
+ data = result[:datapoints][0]
137
+ unless data.nil?
138
+ # We only return data when we have some to return
139
+ graphitepath = config[:scheme]
140
+ if config[:scheme] == ''
141
+ graphitepath = "#{config[:elbname]}.#{config[:metric].downcase}"
142
+ end
143
+ output graphitepath, data[statistic.downcase.to_sym], data[:timestamp].to_i
144
+ end
145
+ rescue => e
146
+ critical "Error: exception: #{e}"
147
+ end
148
+ ok
149
+ end
150
+ end
@@ -0,0 +1,84 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # sqs-metrics
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
+ # sqs-metrics -q my_queue -a key -k secret
20
+ #
21
+ # NOTES:
22
+ #
23
+ # LICENSE:
24
+ # Copyright 2015 Eric Heydrick <eheydrick@gmail.com>
25
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
26
+ # for details.
27
+ #
28
+
29
+ require 'rubygems' if RUBY_VERSION < '1.9.0'
30
+ require 'sensu-plugin/metric/cli'
31
+ require 'aws-sdk'
32
+
33
+ class SQSMetrics < Sensu::Plugin::Metric::CLI::Graphite
34
+ option :queue,
35
+ description: 'Name of the queue',
36
+ short: '-q QUEUE',
37
+ long: '--queue QUEUE',
38
+ required: true
39
+
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 :aws_access_key,
47
+ description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY_ID'] or provide it as an option",
48
+ short: '-a AWS_ACCESS_KEY',
49
+ long: '--aws-access-key AWS_ACCESS_KEY'
50
+
51
+ option :aws_secret_access_key,
52
+ description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_ACCESS_KEY'] or provide it as an option",
53
+ short: '-k AWS_SECRET_ACCESS_KEY',
54
+ long: '--aws-secret-access-key AWS_SECRET_ACCESS_KEY'
55
+
56
+ option :aws_region,
57
+ description: 'AWS Region (such as us-east-1)',
58
+ short: '-r AWS_REGION',
59
+ long: '--aws-region AWS_REGION',
60
+ default: 'us-east-1'
61
+
62
+ def run
63
+ if config[:scheme] == ''
64
+ scheme = "aws.sqs.queue.#{config[:queue].gsub('-', '_')}.message_count"
65
+ else
66
+ scheme = config[:scheme]
67
+ end
68
+
69
+ begin
70
+ sqs = AWS::SQS.new(
71
+ access_key_id: config[:aws_access_key],
72
+ secret_access_key: config[:aws_secret_access_key],
73
+ region: config[:aws_region]
74
+ )
75
+
76
+ messages = sqs.queues.named(config[:queue]).approximate_number_of_messages
77
+ output scheme, messages
78
+
79
+ rescue => e
80
+ critical "Error fetching SQS queue metrics: #{e.message}"
81
+ end
82
+ ok
83
+ end
84
+ end
@@ -0,0 +1,7 @@
1
+ #
2
+ # Set gem version
3
+ #
4
+ module SensuPluginsAWS
5
+ # Gem version
6
+ VERSION = '0.0.1.alpha.2'
7
+ end
data.tar.gz.sig ADDED
Binary file