sensu-plugins-edgelab 1.4.1 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/metrics-asg.rb +156 -0
  3. data/bin/metrics-rds.rb +141 -0
  4. metadata +24 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 767cd7f52f180cdf66ade32292be2855f54f01be
4
- data.tar.gz: f18ed6b06634fa17d95e48333a1c91a2d4825825
3
+ metadata.gz: aff0f83083b3b45316ce9789b73c0ed28d65b95c
4
+ data.tar.gz: 6ba237be39191b6af36b6e510876047a552848b6
5
5
  SHA512:
6
- metadata.gz: c51d4f70eb23341ef24cc7b4744b970f5cfd1804b07896290ed3ffb3bea20f1c2f704ea547bdf8c8451379dc738f6f62081e72872aafa2aea6268f95828d73a3
7
- data.tar.gz: d62adba4a0d37aeb0177ab045015761f2a342f2508b544d71528f324048787a6536763ce7e957e6ef5541da58c8babf503bea779aaa6f442ebb2c3f7b57cc7ca
6
+ metadata.gz: a3439b60756ee772557f80590689502d959f21180d305316320895876f1beb3883fea39cd4358002acddaf7662b08e62913a1f04d111eb58d8be1eecdbc59bcf
7
+ data.tar.gz: 8c1625aee402668b80f0d244d58d0581f67c7041d4420caed1ee7db5643dc5528edf37a9ad71ca6ca97629fa561cc742ae90837a5abe3db15c32cf471b835979
@@ -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: 'AutoScalingGroupName',
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 config[:scheme] + '.' + 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
@@ -0,0 +1,141 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # rds-metrics
4
+ #
5
+ # DESCRIPTION:
6
+ # Gets RDS 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
+ # rds-metrics --aws-region eu-west-1
19
+ # rds-metrics --aws-region eu-west-1 --name sr2x8pbti0eon1
20
+ #
21
+ # NOTES:
22
+ # Returns all RDS statistics for all RDS instances in this account unless you specify --name
23
+ #
24
+ # LICENSE:
25
+ # Peter Hoppe <peter.hoppe.extern@bertelsmann.de>
26
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
27
+ # for details.
28
+ #
29
+
30
+ require 'sensu-plugins-aws'
31
+ require 'sensu-plugin/metric/cli'
32
+ require 'aws-sdk'
33
+ require 'time'
34
+
35
+ class RDSMetrics < Sensu::Plugin::Metric::CLI::Graphite
36
+ include Common
37
+ option :aws_region,
38
+ short: '-r AWS_REGION',
39
+ long: '--aws-region REGION',
40
+ description: 'AWS Region (defaults to us-east-1).',
41
+ default: ENV['AWS_REGION']
42
+
43
+ option :db_instance_id,
44
+ short: '-i N',
45
+ long: '--db-instance-id NAME',
46
+ description: 'DB instance identifier'
47
+
48
+ option :end_time,
49
+ short: '-t T',
50
+ long: '--end-time TIME',
51
+ default: Time.now,
52
+ proc: proc { |a| Time.parse a },
53
+ description: 'CloudWatch metric statistics end time'
54
+
55
+ option :period,
56
+ short: '-p N',
57
+ long: '--period SECONDS',
58
+ default: 60,
59
+ proc: proc(&:to_i),
60
+ description: 'CloudWatch metric statistics period'
61
+
62
+ option :statistics,
63
+ short: '-S N',
64
+ long: '--statistics NAME',
65
+ default: :average,
66
+ proc: proc { |a| a.downcase.intern },
67
+ description: 'CloudWatch statistics method'
68
+
69
+ option :scheme,
70
+ description: 'Metric naming scheme, text to prepend to metric',
71
+ short: '-s SCHEME',
72
+ long: '--scheme SCHEME',
73
+ default: ''
74
+
75
+ def rds
76
+ @rds = Aws::RDS::Client.new
77
+ end
78
+
79
+ def cloud_watch
80
+ @cloud_watch = Aws::CloudWatch::Client.new
81
+ end
82
+
83
+ def find_db_instance(id)
84
+ db = rds.describe_db_instances.db_instances.detect { |db_instance| db_instance.db_instance_identifier == id }
85
+ unknown 'DB instance not found.' if db.nil?
86
+ db
87
+ end
88
+
89
+ def cloud_watch_metric(metric_name, value)
90
+ cloud_watch.get_metric_statistics(
91
+ namespace: 'AWS/RDS',
92
+ metric_name: metric_name,
93
+ dimensions: [
94
+ {
95
+ name: 'DBInstanceIdentifier',
96
+ value: value
97
+ }
98
+ ],
99
+ start_time: config[:end_time] - config[:period],
100
+ end_time: config[:end_time],
101
+ statistics: [config[:statistics].to_s.capitalize],
102
+ period: config[:period]
103
+ )
104
+ end
105
+
106
+ def run
107
+ statistic_type = {
108
+ 'CPUUtilization' => 'Average',
109
+ 'DatabaseConnections' => 'Average',
110
+ 'FreeStorageSpace' => 'Average',
111
+ 'ReadIOPS' => 'Average',
112
+ 'ReadLatency' => 'Average',
113
+ 'ReadThroughput' => 'Average',
114
+ 'WriteIOPS' => 'Average',
115
+ 'WriteLatency' => 'Average',
116
+ 'WriteThroughput' => 'Average',
117
+ 'ReplicaLag' => 'Average',
118
+ 'SwapUsage' => 'Average',
119
+ 'BinLogDiskUsage' => 'Average',
120
+ 'DiskQueueDepth' => 'Average'
121
+ }
122
+
123
+ @db_instance = find_db_instance config[:db_instance_id]
124
+ @message = "#{config[:db_instance_id]}: "
125
+
126
+ result = {}
127
+
128
+ rdsname = @db_instance.db_instance_identifier
129
+
130
+ statistic_type.each do |key, _value|
131
+ r = cloud_watch_metric key, rdsname
132
+ result[config[:scheme] + '.' + rdsname + '.' + key] = r[:datapoints][0] unless r[:datapoints][0].nil?
133
+ end
134
+ unless result.nil?
135
+ result.each do |key, value|
136
+ output key.to_s, value.average, value[:timestamp].to_i
137
+ end
138
+ end
139
+ exit
140
+ end
141
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-edgelab
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edgelab
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-20 00:00:00.000000000 Z
11
+ date: 2017-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-plugin
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sensu-plugins-aws
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 4.0.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 4.0.0
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: bundler
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -111,12 +125,14 @@ dependencies:
111
125
  description: Sensu plugins developed by Edgelab
112
126
  email:
113
127
  executables:
114
- - check-swarm-cluster.rb
115
- - metrics-mysql-processes.rb
116
- - metrics-swarm-cluster.rb
117
- - check-apt-expired-keys.rb
118
128
  - check-nomad-jobs.rb
129
+ - metrics-rds.rb
130
+ - check-swarm-cluster.rb
131
+ - metrics-asg.rb
119
132
  - check-nomad-leader.rb
133
+ - check-apt-expired-keys.rb
134
+ - metrics-swarm-cluster.rb
135
+ - metrics-mysql-processes.rb
120
136
  extensions: []
121
137
  extra_rdoc_files: []
122
138
  files:
@@ -124,7 +140,9 @@ files:
124
140
  - bin/check-nomad-jobs.rb
125
141
  - bin/check-nomad-leader.rb
126
142
  - bin/check-swarm-cluster.rb
143
+ - bin/metrics-asg.rb
127
144
  - bin/metrics-mysql-processes.rb
145
+ - bin/metrics-rds.rb
128
146
  - bin/metrics-swarm-cluster.rb
129
147
  homepage:
130
148
  licenses: []