sensu-plugins-influxdb-metrics-checker 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +10 -0
- data/LICENSE +21 -0
- data/README.md +20 -0
- data/bin/check-influxdb-metrics.rb +158 -0
- data/lib/sensu-plugins-influxdb-metrics-checker.rb +1 -0
- data/lib/sensu-plugins-influxdb-metrics-checker/version.rb +9 -0
- metadata +244 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a411a61cdc51bafe60712716217185aefe837634
|
4
|
+
data.tar.gz: 76638bfde428cacb530d5739475922ce65161a55
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b9b12d1bf3a78fbcb321900c60daa954a624db003daf1cfc8036cad040f3a074b30fcd8142e9cff914483369ff5fff4b1fb6d60254a9b03d4ea155fabd066034
|
7
|
+
data.tar.gz: edbed248f91536267de79fe2529a7ded71fedb1b36b7b847baa1fddd377e034a5c1959e48c34fbfd39c8a16843c9afc528022d4c26759e955a8a235b54dfbb5d
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
Change Log
|
2
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
3
|
+
|
4
|
+
This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
|
5
|
+
|
6
|
+
# [0.1.0] - 2016-11-17
|
7
|
+
### Added
|
8
|
+
- initial release
|
9
|
+
|
10
|
+
[0.1.0]: https://github.com/pliyosenpai/sensu-plugins-influxdb-metrics-checker/0.1.0...HEAD
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016 Juanjo Guerrero Cerezuela
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# sensu-plugins-influxdb-metrics-checker
|
2
|
+
|
3
|
+
[ ![Build Status](https://travis-ci.org/pliyosenpai/sensu-plugins-influxdb-metrics-checker.svg?branch=master)](https://travis-ci.org/pliyosenpai/sensu-plugins-influxdb-metrics-checker)
|
4
|
+
|
5
|
+
Plugin to retrieve metrics and evaluate them. Aiming to track outages.
|
6
|
+
|
7
|
+
Example of use:
|
8
|
+
|
9
|
+
```
|
10
|
+
ruby check-influxdb-metrics.rb --host=metrics-influxdb.internal.com --port=8086 --user=admin --password=password -c -3 -w -10 --db=statsd_metrics --metric=api.request.counter
|
11
|
+
```
|
12
|
+
|
13
|
+
Important things to now about InfluxDB:
|
14
|
+
|
15
|
+
When doing a query, writing:
|
16
|
+
-24h is wrong
|
17
|
+
- 24h is right
|
18
|
+
|
19
|
+
Important things to now about passing parameters in Ruby:
|
20
|
+
-c=-3 Will be transform as 0.0. While -c -3 counts as a float
|
@@ -0,0 +1,158 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Check a given metric and compare it to its values in the past
|
3
|
+
# to produce health status
|
4
|
+
|
5
|
+
require 'sensu-plugin/check/cli'
|
6
|
+
require 'rest-client'
|
7
|
+
require 'openssl'
|
8
|
+
require 'uri'
|
9
|
+
require 'json'
|
10
|
+
require 'base64'
|
11
|
+
require 'addressable/uri'
|
12
|
+
|
13
|
+
class CheckInfluxDbMetrics < Sensu::Plugin::Check::CLI
|
14
|
+
option :host,
|
15
|
+
short: '-h',
|
16
|
+
long: '--host=VALUE',
|
17
|
+
description: 'Cluster host',
|
18
|
+
required: true
|
19
|
+
|
20
|
+
option :port,
|
21
|
+
short: '-p',
|
22
|
+
long: '--port=VALUE',
|
23
|
+
description: 'Api port',
|
24
|
+
required: true
|
25
|
+
|
26
|
+
option :user,
|
27
|
+
short: '-u',
|
28
|
+
long: '--username=VALUE',
|
29
|
+
description: 'username',
|
30
|
+
required: true
|
31
|
+
|
32
|
+
option :pass,
|
33
|
+
short: '-p',
|
34
|
+
long: '--password=VALUE',
|
35
|
+
description: 'password',
|
36
|
+
required: true
|
37
|
+
|
38
|
+
option :ssl,
|
39
|
+
description: 'use HTTPS (default false)',
|
40
|
+
long: '--ssl'
|
41
|
+
|
42
|
+
option :crit,
|
43
|
+
short: '-c',
|
44
|
+
long: '--critical=VALUE',
|
45
|
+
description: 'Critical threshold',
|
46
|
+
required: true,
|
47
|
+
proc: proc { |l| l.to_f }
|
48
|
+
|
49
|
+
option :warn,
|
50
|
+
short: '-w',
|
51
|
+
long: '--warn=VALUE',
|
52
|
+
description: 'Warn threshold',
|
53
|
+
required: true,
|
54
|
+
proc: proc { |l| l.to_f }
|
55
|
+
|
56
|
+
option :timeout,
|
57
|
+
short: '-t',
|
58
|
+
long: '--timeout=VALUE',
|
59
|
+
description: 'Timeout in seconds',
|
60
|
+
proc: proc { |l| l.to_f },
|
61
|
+
default: 5
|
62
|
+
|
63
|
+
option :db,
|
64
|
+
short: '-d',
|
65
|
+
long: '--db=VALUE',
|
66
|
+
description: 'Default DB'
|
67
|
+
|
68
|
+
option :metric,
|
69
|
+
short: '-m',
|
70
|
+
long: '--metric=VALUE',
|
71
|
+
description: 'Metric to influx DB. Ex datareceivers.messages.count'
|
72
|
+
|
73
|
+
def encode_parameters(parameters)
|
74
|
+
encodedparams = Addressable::URI.escape(parameters)
|
75
|
+
"#{config[:db]}&q=" + encodedparams
|
76
|
+
end
|
77
|
+
|
78
|
+
def yesterday_query
|
79
|
+
"SELECT sum(\"value\") from \"#{config[:metric]}\" WHERE time > now() - 48h AND time < now() - 24h"
|
80
|
+
end
|
81
|
+
|
82
|
+
def today_query
|
83
|
+
"SELECT sum(\"value\") from \"#{config[:metric]}\" WHERE time > now() - 24h"
|
84
|
+
end
|
85
|
+
|
86
|
+
def yesterday_query_encoded
|
87
|
+
query = yesterday_query
|
88
|
+
encode_parameters(query)
|
89
|
+
end
|
90
|
+
|
91
|
+
def today_query_encoded
|
92
|
+
query = today_query
|
93
|
+
encode_parameters(query)
|
94
|
+
end
|
95
|
+
|
96
|
+
def today_value
|
97
|
+
second_query = today_query_encoded
|
98
|
+
response_to_compare = request(second_query)
|
99
|
+
read_metrics(response_to_compare)
|
100
|
+
end
|
101
|
+
|
102
|
+
def yesterday_value
|
103
|
+
query = yesterday_query_encoded
|
104
|
+
response = request(query)
|
105
|
+
read_metrics(response)
|
106
|
+
end
|
107
|
+
|
108
|
+
def read_metrics(response)
|
109
|
+
metrics = JSON.parse(response.to_str)['results']
|
110
|
+
series = metrics[0]['series']
|
111
|
+
values = series[0]['values'][0][1]
|
112
|
+
|
113
|
+
if values.nil?
|
114
|
+
values = 0
|
115
|
+
end
|
116
|
+
|
117
|
+
values.to_f
|
118
|
+
end
|
119
|
+
|
120
|
+
def calculate_percentage_ofdifference(original, newnumber)
|
121
|
+
decrease = original - newnumber
|
122
|
+
decrease.to_f / original.to_f * 100
|
123
|
+
end
|
124
|
+
|
125
|
+
def request(path)
|
126
|
+
protocol = 'http'
|
127
|
+
auth = Base64.encode64("#{config[:user]}:#{config[:pass]}")
|
128
|
+
url = "#{protocol}://#{config[:host]}:#{config[:port]}/query?db=#{path}"
|
129
|
+
RestClient::Request.execute(
|
130
|
+
method: :get,
|
131
|
+
url: url,
|
132
|
+
timeout: config[:timeout],
|
133
|
+
headers: { 'Authorization' => "Basic #{auth}" }
|
134
|
+
)
|
135
|
+
end
|
136
|
+
|
137
|
+
def evaluate_percentage_and_notify(difference)
|
138
|
+
if difference < config[:crit]
|
139
|
+
critical "\"#{config[:metric]}\" sum is below allowed minimum of #{config[:crit]} %"
|
140
|
+
elsif difference < config[:warn]
|
141
|
+
warning "\"#{config[:metric]}\" sum is below warn threshold of #{config[:warn]}"
|
142
|
+
else
|
143
|
+
ok 'metrics count ok'
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def run
|
148
|
+
difference = calculate_percentage_ofdifference(today_value, yesterday_value)
|
149
|
+
|
150
|
+
evaluate_percentage_and_notify(difference)
|
151
|
+
rescue Errno::ECONNREFUSED => e
|
152
|
+
critical 'InfluxDB is not responding' + e.message
|
153
|
+
rescue RestClient::RequestTimeout
|
154
|
+
critical 'InfluxDB Connection timed out'
|
155
|
+
rescue StandardError => e
|
156
|
+
unknown 'An exception occurred:' + e.message
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'sensu-plugins-influxdb-metrics-checker/version'
|
metadata
ADDED
@@ -0,0 +1,244 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sensu-plugins-influxdb-metrics-checker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Juanjo Guerrero Cerezuela
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sensu-plugin
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rest-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: addressable
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.5'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: codeclimate-test-reporter
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.7'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.7'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: github-markup
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.10'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.10'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '10.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ~>
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '10.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: redcarpet
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ~>
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3.2'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ~>
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3.2'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rspec
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ~>
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '3.1'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ~>
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '3.1'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rubocop
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ~>
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 0.40.0
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ~>
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 0.40.0
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: yard
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ~>
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0.8'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ~>
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0.8'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: test-unit
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ~>
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '3.2'
|
188
|
+
- - '>='
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: 3.2.1
|
191
|
+
type: :development
|
192
|
+
prerelease: false
|
193
|
+
version_requirements: !ruby/object:Gem::Requirement
|
194
|
+
requirements:
|
195
|
+
- - ~>
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: '3.2'
|
198
|
+
- - '>='
|
199
|
+
- !ruby/object:Gem::Version
|
200
|
+
version: 3.2.1
|
201
|
+
description: This plugin retrieves metrics and evaluate them. Aiming to track downsides.
|
202
|
+
email: <pliyosan@gmail.com>
|
203
|
+
executables:
|
204
|
+
- check-influxdb-metrics.rb
|
205
|
+
extensions: []
|
206
|
+
extra_rdoc_files: []
|
207
|
+
files:
|
208
|
+
- CHANGELOG.md
|
209
|
+
- LICENSE
|
210
|
+
- README.md
|
211
|
+
- bin/check-influxdb-metrics.rb
|
212
|
+
- lib/sensu-plugins-influxdb-metrics-checker.rb
|
213
|
+
- lib/sensu-plugins-influxdb-metrics-checker/version.rb
|
214
|
+
homepage: https://github.com/pliyosenpai/sensu-plugins-influxdb-metrics-checker
|
215
|
+
licenses:
|
216
|
+
- MIT
|
217
|
+
metadata:
|
218
|
+
maintainer: pliyosenpai
|
219
|
+
development_status: active
|
220
|
+
production_status: unstable - testing recommended
|
221
|
+
release_draft: 'false'
|
222
|
+
release_prerelease: 'false'
|
223
|
+
post_install_message: You can use the embedded Ruby by setting EMBEDDED_RUBY=true
|
224
|
+
in /etc/default/sensu
|
225
|
+
rdoc_options: []
|
226
|
+
require_paths:
|
227
|
+
- lib
|
228
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
229
|
+
requirements:
|
230
|
+
- - '>='
|
231
|
+
- !ruby/object:Gem::Version
|
232
|
+
version: 2.0.0
|
233
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
234
|
+
requirements:
|
235
|
+
- - '>='
|
236
|
+
- !ruby/object:Gem::Version
|
237
|
+
version: '0'
|
238
|
+
requirements: []
|
239
|
+
rubyforge_project:
|
240
|
+
rubygems_version: 2.4.8
|
241
|
+
signing_key:
|
242
|
+
specification_version: 4
|
243
|
+
summary: Sensu plugins for InfluxDB to checks metrics
|
244
|
+
test_files: []
|