sensu-plugins-influxdb-metrics-checker 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe60799563f025075be685429026d01164be54a2
4
- data.tar.gz: 4e1b65bedb39167ae07df9e8ac79f5248e12378e
3
+ metadata.gz: ae9964965f956ab4e09596bae8dcfd2e421ea560
4
+ data.tar.gz: dc833f54f35dac20514ab2d399527f49bc04f224
5
5
  SHA512:
6
- metadata.gz: 0fbccdbcd99caa5d8a53ae28879faf6ec50753c9d593e2dea2e9024c30e297987b165669d4488924e7a313b5bb77958999afb51e4acd415891a18540fade14ce
7
- data.tar.gz: 720e9cc1537a845dd63742aa7cdc8ef477de1d8d7d8bc21ae103adfd3221cb74ba8aa79c1d7fbba72798ee112a65666f5d4b58e23f58cb4867302449c76cb32a
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...HEAD
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
  [ ![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
- [![Gem Version](https://badge.fury.io/rb/sensu-plugins-influxdb-metrics-checker.svg)](http://badge.fury.io/rb/sensu-plugins-influxdb-metrics-checker.svg)
4
+ [![Gem Version](https://badge.fury.io/rb/sensu-plugins-influxdb-metrics-checker.svg)](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.service.veinternal.com --port=8086 --user=admin --password=password -c -20 -w -10 --db=statsd_metrics --metric=datareceivers.request.counter --tag=datacenter --filter=ci
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
- def encode_parameters(parameters)
83
- encodedparams = Addressable::URI.escape(parameters)
84
- "#{config[:db]}&q=" + encodedparams
85
- end
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 yesterday_query # Reads the value from 10 minutes before yesterday at this time.
92
- query = "SELECT sum(\"value\") from \"#{config[:metric]}\" WHERE time > now() - 1455m AND time < now() - 1445m"
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 today_query
97
- query = "SELECT sum(\"value\") from \"#{config[:metric]}\" WHERE time > now() - 15m AND time < now() - 5m"
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 = yesterday_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 = today_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 + e.stacktrace
191
+ unknown 'An exception occurred:' + e.message
173
192
  end
174
193
  end
@@ -1,8 +1,8 @@
1
1
  module SensuPluginsInfluxDbMetricsChecker
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 2
5
- PATCH = 1
4
+ MINOR = 3
5
+ PATCH = 0
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  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.2.1
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-21 00:00:00.000000000 Z
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 downsides.
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