sensu-plugins-influxdb-metrics-checker 0.2.1 → 0.3.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/README.md +8 -2
- data/bin/check-influxdb-metrics.rb +31 -12
- data/lib/sensu-plugins-influxdb-metrics-checker/version.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae9964965f956ab4e09596bae8dcfd2e421ea560
|
4
|
+
data.tar.gz: dc833f54f35dac20514ab2d399527f49bc04f224
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7b2d9d1a0832147e9bec1ad820adacccffdc244053a6eca15d3fd02aae8ddf706681744b3d3a8cff8b79a37a35526429fdae460513b6d4f300fde25af99dc43
|
7
|
+
data.tar.gz: 53aa9bbda02dcbeafb580eb94f407f3f679392c4369a77615c85e59eb82993be8022b7f6546e33c5e15fd08df915fa0ab14c3dcd4f2b6897ced67fc94f17bd71
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
3
3
|
|
4
4
|
This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
|
5
5
|
|
6
|
+
# [0.3.0] - 2016-11-21
|
7
|
+
### Added
|
8
|
+
- fourth release
|
9
|
+
Added the possibility to tweak your queries by adding --period in your parameters.
|
10
|
+
By default --period will be 10 minutes to work with previous versions
|
11
|
+
|
6
12
|
# [0.2.1] - 2016-11-21
|
7
13
|
### Added
|
8
14
|
- third release
|
@@ -21,4 +27,5 @@ Leaving 5 minutes to the data to consolidate.
|
|
21
27
|
|
22
28
|
[0.1.0]: https://github.com/pliyosenpai/sensu-plugins-influxdb-metrics-checker/0.1.0...0.2.0
|
23
29
|
[0.2.0]: https://github.com/pliyosenpai/sensu-plugins-influxdb-metrics-checker/0.2.0...0.2.1
|
24
|
-
[0.2.1]: https://github.com/pliyosenpai/sensu-plugins-influxdb-metrics-checker/0.2.1...
|
30
|
+
[0.2.1]: https://github.com/pliyosenpai/sensu-plugins-influxdb-metrics-checker/0.2.1...0.3.0
|
31
|
+
[0.3.0]: https://github.com/pliyosenpai/sensu-plugins-influxdb-metrics-checker/0.3.0...HEAD
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# sensu-plugins-influxdb-metrics-checker
|
2
2
|
|
3
3
|
[ ](https://travis-ci.org/pliyosenpai/sensu-plugins-influxdb-metrics-checker)
|
4
|
-
[](
|
4
|
+
[](https://rubygems.org/gems/sensu-plugins-influxdb-metrics-checker)
|
5
5
|
|
6
6
|
## Background story
|
7
7
|
As soon as we started using InfluxDB we were wondering how we could read a given metric, compare it to its previous days, evaluate the percentage of difference, and act according to it.
|
@@ -36,7 +36,13 @@ Once in Sensu:
|
|
36
36
|
|
37
37
|
If you have a tag you can filter your metrics by doing, for example:
|
38
38
|
```
|
39
|
-
ruby check-influxdb-metrics.rb --host=metrics-influxdb.
|
39
|
+
ruby check-influxdb-metrics.rb --host=metrics-influxdb.internal.com --port=8086 --user=admin --password=password -c -20 -w -10 --db=statsd_metrics --metric=api.request.counter --tag=datacenter --filter=ci
|
40
|
+
|
41
|
+
```
|
42
|
+
|
43
|
+
Also, you can set the period that you want for your queries, for example:
|
44
|
+
```
|
45
|
+
ruby check-influxdb-metrics.rb --host=metrics-influxdb.internal.com --port=8086 --user=admin --password=password -c -20 -w -10 --db=statsd_metrics --metric=api.request.counter --tag=datacenter --filter=ci --period=1440
|
40
46
|
|
41
47
|
```
|
42
48
|
|
@@ -79,32 +79,51 @@ class CheckInfluxDbMetrics < Sensu::Plugin::Check::CLI
|
|
79
79
|
long: '--filter=VALUE',
|
80
80
|
description: 'Set the name of your filter, for example: `datacenter`'
|
81
81
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
82
|
+
option :period,
|
83
|
+
long: '--period=VALUE',
|
84
|
+
description: 'Filter by a given day period in minutes',
|
85
|
+
proc: proc { |l| l.to_i },
|
86
|
+
default: 10
|
86
87
|
|
87
88
|
def filter_by_environment_when_needed
|
88
89
|
config[:tag].nil? && config[:filter].nil? ? '' : " AND \"#{config[:tag]}\" =~ /#{config[:filter]}/"
|
89
90
|
end
|
90
91
|
|
91
|
-
def
|
92
|
-
|
92
|
+
def base_query
|
93
|
+
"SELECT sum(\"value\") from \"#{config[:metric]}\" "
|
94
|
+
end
|
95
|
+
|
96
|
+
def today_query_for_a_period
|
97
|
+
start_period = 5; # starts counting 5 minutes before now() to let influxdb time to aggregate the data
|
98
|
+
end_period = config[:period] + 5; # adds 5 minutes to match with start_period
|
99
|
+
query = query_for_a_period(start_period, end_period)
|
100
|
+
query + filter_by_environment_when_needed
|
101
|
+
end
|
102
|
+
|
103
|
+
def yesterday_query_for_a_period
|
104
|
+
start_period = 1445; # starts counting 1445 minutes before now() [ yesetrday - 5 minutes] to match with today_query_for_a_period start_period
|
105
|
+
end_period = config[:period] + 1445; # adds 1445 minutes to match with start_period
|
106
|
+
query = query_for_a_period(start_period, end_period)
|
93
107
|
query + filter_by_environment_when_needed
|
94
108
|
end
|
95
109
|
|
96
|
-
def
|
97
|
-
query =
|
110
|
+
def query_for_a_period(start_period, end_period)
|
111
|
+
query = base_query + ' WHERE time > now() - ' + end_period.to_s + 'm AND time < now() - ' + start_period.to_s + 'm'
|
98
112
|
query + filter_by_environment_when_needed
|
99
113
|
end
|
100
114
|
|
115
|
+
def encode_parameters(parameters)
|
116
|
+
encodedparams = Addressable::URI.escape(parameters)
|
117
|
+
"#{config[:db]}&q=" + encodedparams
|
118
|
+
end
|
119
|
+
|
101
120
|
def yesterday_query_encoded
|
102
|
-
query =
|
121
|
+
query = yesterday_query_for_a_period
|
103
122
|
encode_parameters(query)
|
104
123
|
end
|
105
124
|
|
106
125
|
def today_query_encoded
|
107
|
-
query =
|
126
|
+
query = today_query_for_a_period
|
108
127
|
encode_parameters(query)
|
109
128
|
end
|
110
129
|
|
@@ -161,7 +180,7 @@ class CheckInfluxDbMetrics < Sensu::Plugin::Check::CLI
|
|
161
180
|
|
162
181
|
def run
|
163
182
|
difference = calculate_percentage_ofdifference(today_value, yesterday_value)
|
164
|
-
puts difference
|
183
|
+
puts 'Difference of: ' + difference.to_s + ' % for a period of ' + config[:period].to_s + 'm'
|
165
184
|
evaluate_percentage_and_notify(difference)
|
166
185
|
|
167
186
|
rescue Errno::ECONNREFUSED => e
|
@@ -169,6 +188,6 @@ class CheckInfluxDbMetrics < Sensu::Plugin::Check::CLI
|
|
169
188
|
rescue RestClient::RequestTimeout
|
170
189
|
critical 'InfluxDB Connection timed out'
|
171
190
|
rescue StandardError => e
|
172
|
-
unknown 'An exception occurred:' + e.message
|
191
|
+
unknown 'An exception occurred:' + e.message
|
173
192
|
end
|
174
193
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-influxdb-metrics-checker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juanjo Guerrero Cerezuela
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sensu-plugin
|
@@ -198,7 +198,7 @@ dependencies:
|
|
198
198
|
- - ">="
|
199
199
|
- !ruby/object:Gem::Version
|
200
200
|
version: 3.2.1
|
201
|
-
description: This plugin retrieves metrics and evaluate them. Aiming to track
|
201
|
+
description: This plugin retrieves metrics and evaluate them. Aiming to track outages.
|
202
202
|
email: "<pliyosan@gmail.com>"
|
203
203
|
executables:
|
204
204
|
- check-influxdb-metrics.rb
|