sensu-plugins-influxdb-metrics-checker 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a411a61cdc51bafe60712716217185aefe837634
4
- data.tar.gz: 76638bfde428cacb530d5739475922ce65161a55
3
+ metadata.gz: ccb29431c1bbb430e550f511a497e1d8e1d931af
4
+ data.tar.gz: 306719c980c7af31026af1d391780ca6d7a932c5
5
5
  SHA512:
6
- metadata.gz: b9b12d1bf3a78fbcb321900c60daa954a624db003daf1cfc8036cad040f3a074b30fcd8142e9cff914483369ff5fff4b1fb6d60254a9b03d4ea155fabd066034
7
- data.tar.gz: edbed248f91536267de79fe2529a7ded71fedb1b36b7b847baa1fddd377e034a5c1959e48c34fbfd39c8a16843c9afc528022d4c26759e955a8a235b54dfbb5d
6
+ metadata.gz: 0a1c31569b1db373c41bd42d5cc6c28535224def9823b4fe1c6ca0eddbfd3f50862a2d9e1eefa35ab9e54c289fa0076a4069771712a72191d8e35a4d106b8fe0
7
+ data.tar.gz: 2b415e127ebb09a7c6fdfe843aa86c3231202be2b5c855b2a971a4d0ef1021946151813bf343e5522f776afcbb19a79218fb7786fe369fde3aa5931037e4e006
data/CHANGELOG.md CHANGED
@@ -3,8 +3,16 @@ 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.2.0] - 2016-11-21
7
+ ### Added
8
+ - second release
9
+ Added the possibility to use tag and filter.
10
+ Querying from the past 10 minutes vs Yesterday in the past 10 minutes.
11
+ Leaving 5 minutes to the data to consolidate.
12
+
6
13
  # [0.1.0] - 2016-11-17
7
14
  ### Added
8
15
  - initial release
9
16
 
10
- [0.1.0]: https://github.com/pliyosenpai/sensu-plugins-influxdb-metrics-checker/0.1.0...HEAD
17
+ [0.1.0]: https://github.com/pliyosenpai/sensu-plugins-influxdb-metrics-checker/0.1.0...0.2.0
18
+ [0.2.0]: https://github.com/pliyosenpai/sensu-plugins-influxdb-metrics-checker/0.2.0...HEAD
data/README.md CHANGED
@@ -1,20 +1,65 @@
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
5
 
5
- Plugin to retrieve metrics and evaluate them. Aiming to track outages.
6
+ ## Background story
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.
6
8
 
7
- Example of use:
9
+ We chose to do it as a Sensu plugin because it comes with Handlers that will allow us to extend the usability of this information, such as sending a message to slack, or sending an alert to OpsGenie.
10
+
11
+ The result is that now we are able to experiment with our metrics and alerts, giving us a better understanding of whats going on in our systems.
12
+
13
+ ## What it does
14
+ The script will compare the values of yesterday at this time minus 10 minutes, with the values of today at this time minus 10 minus.
15
+ It will calculate the percentage of difference and will act on that.
16
+ You will be able set a threshold of warning and critical values where your program will act.
17
+
18
+ ## Components
19
+ There is just one script that you can find at
20
+ * bin/check-influxdb-metrics.rb
21
+
22
+ ## Getting started
23
+
24
+ At the moment there is just one script
25
+ **check-influxdb-metrics** which you can run in a bash doing:
8
26
 
9
27
  ```
10
28
  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
29
  ```
12
30
 
13
- Important things to now about InfluxDB:
31
+ Once in Sensu:
32
+ ```
33
+ /opt/sensu/embedded/bin$ /opt/sensu/embedded/bin/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
34
+ ```
35
+
36
+ If you have environments you can filter them by doing:
37
+ ```
38
+ 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 --env=datacenter --filter=ci
39
+
40
+ ```
41
+
42
+ ## Lessons learnt
43
+ The InfluxDb query language that we used is not the latest, you can find it here:
44
+
45
+ [InfluxDb query language](https://docs.influxdata.com/influxdb/v0.10/query_language/)
46
+
47
+ What matters for this program is that:
48
+ **When doing a query**:
49
+ ```
50
+ -24h will turn into bad request
51
+ - 24h good
52
+ ```
53
+
54
+ **When passing parameters**
55
+ ```
56
+ -c=-3 Will be transform as 0.0.
57
+ -c -3 counts as a number
58
+ ```
59
+
60
+ ## Installation
14
61
 
15
- When doing a query, writing:
16
- -24h is wrong
17
- - 24h is right
62
+ [Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
18
63
 
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
64
+ ## Notes
65
+ The ruby executables are install in path similar to `/opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-plugins-storm-0.1.0/bin`
@@ -70,17 +70,33 @@ class CheckInfluxDbMetrics < Sensu::Plugin::Check::CLI
70
70
  long: '--metric=VALUE',
71
71
  description: 'Metric to influx DB. Ex datareceivers.messages.count'
72
72
 
73
+ option :env,
74
+ long: '--tag=VALUE',
75
+ description: 'Filter by tag if provided.'
76
+
77
+ option :filter,
78
+ short: '-f',
79
+ long: '--filter=VALUE',
80
+ description: 'Set the name of your filter, for example: `datacenter`'
81
+
73
82
  def encode_parameters(parameters)
74
83
  encodedparams = Addressable::URI.escape(parameters)
75
84
  "#{config[:db]}&q=" + encodedparams
76
85
  end
77
86
 
78
- def yesterday_query
79
- "SELECT sum(\"value\") from \"#{config[:metric]}\" WHERE time > now() - 48h AND time < now() - 24h"
87
+ def filter_by_environment_when_needed
88
+ return unless !config[:tag].nil? && !config[:filter].nil?
89
+ " AND \"#{config[:tag]}\" =~ /#{config[:filter]}/"
90
+ end
91
+
92
+ def yesterday_query # Reads the value from 10 minutes before yesterday at this time.
93
+ query = "SELECT sum(\"value\") from \"#{config[:metric]}\" WHERE time > now() - 1455m AND time < now() - 1445m"
94
+ query + filter_by_environment_when_needed
80
95
  end
81
96
 
82
97
  def today_query
83
- "SELECT sum(\"value\") from \"#{config[:metric]}\" WHERE time > now() - 24h"
98
+ query = "SELECT sum(\"value\") from \"#{config[:metric]}\" WHERE time > now() - 15m AND time < now() - 5m"
99
+ query + filter_by_environment_when_needed
84
100
  end
85
101
 
86
102
  def yesterday_query_encoded
@@ -123,7 +139,7 @@ class CheckInfluxDbMetrics < Sensu::Plugin::Check::CLI
123
139
  end
124
140
 
125
141
  def request(path)
126
- protocol = 'http'
142
+ protocol = config[:ssl] ? 'https' : 'http'
127
143
  auth = Base64.encode64("#{config[:user]}:#{config[:pass]}")
128
144
  url = "#{protocol}://#{config[:host]}:#{config[:port]}/query?db=#{path}"
129
145
  RestClient::Request.execute(
@@ -136,9 +152,9 @@ class CheckInfluxDbMetrics < Sensu::Plugin::Check::CLI
136
152
 
137
153
  def evaluate_percentage_and_notify(difference)
138
154
  if difference < config[:crit]
139
- critical "\"#{config[:metric]}\" sum is below allowed minimum of #{config[:crit]} %"
155
+ critical "\"#{config[:metric]}\" difference is below allowed minimum of #{config[:crit]} %"
140
156
  elsif difference < config[:warn]
141
- warning "\"#{config[:metric]}\" sum is below warn threshold of #{config[:warn]}"
157
+ warning "\"#{config[:metric]}\" difference is below warn threshold of #{config[:warn]}"
142
158
  else
143
159
  ok 'metrics count ok'
144
160
  end
@@ -146,8 +162,9 @@ class CheckInfluxDbMetrics < Sensu::Plugin::Check::CLI
146
162
 
147
163
  def run
148
164
  difference = calculate_percentage_ofdifference(today_value, yesterday_value)
149
-
165
+ puts difference
150
166
  evaluate_percentage_and_notify(difference)
167
+
151
168
  rescue Errno::ECONNREFUSED => e
152
169
  critical 'InfluxDB is not responding' + e.message
153
170
  rescue RestClient::RequestTimeout
@@ -1,7 +1,7 @@
1
1
  module SensuPluginsInfluxDbMetricsChecker
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 1
4
+ MINOR = 2
5
5
  PATCH = 0
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-influxdb-metrics-checker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.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-17 00:00:00.000000000 Z
11
+ date: 2016-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-plugin
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.2'
27
27
  - !ruby/object:Gem::Dependency
@@ -42,164 +42,164 @@ dependencies:
42
42
  name: addressable
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '2.5'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.5'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: codeclimate-test-reporter
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0.4'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.4'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '1.7'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.7'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: github-markup
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: '1.3'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.3'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: pry
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ~>
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0.10'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ~>
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0.10'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rake
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ~>
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
117
  version: '10.0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ~>
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '10.0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: redcarpet
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ~>
129
+ - - "~>"
130
130
  - !ruby/object:Gem::Version
131
131
  version: '3.2'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ~>
136
+ - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '3.2'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rspec
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ~>
143
+ - - "~>"
144
144
  - !ruby/object:Gem::Version
145
145
  version: '3.1'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ~>
150
+ - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '3.1'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: rubocop
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - ~>
157
+ - - "~>"
158
158
  - !ruby/object:Gem::Version
159
159
  version: 0.40.0
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - ~>
164
+ - - "~>"
165
165
  - !ruby/object:Gem::Version
166
166
  version: 0.40.0
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: yard
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - ~>
171
+ - - "~>"
172
172
  - !ruby/object:Gem::Version
173
173
  version: '0.8'
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - ~>
178
+ - - "~>"
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0.8'
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: test-unit
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
- - - ~>
185
+ - - "~>"
186
186
  - !ruby/object:Gem::Version
187
187
  version: '3.2'
188
- - - '>='
188
+ - - ">="
189
189
  - !ruby/object:Gem::Version
190
190
  version: 3.2.1
191
191
  type: :development
192
192
  prerelease: false
193
193
  version_requirements: !ruby/object:Gem::Requirement
194
194
  requirements:
195
- - - ~>
195
+ - - "~>"
196
196
  - !ruby/object:Gem::Version
197
197
  version: '3.2'
198
- - - '>='
198
+ - - ">="
199
199
  - !ruby/object:Gem::Version
200
200
  version: 3.2.1
201
201
  description: This plugin retrieves metrics and evaluate them. Aiming to track downsides.
202
- email: <pliyosan@gmail.com>
202
+ email: "<pliyosan@gmail.com>"
203
203
  executables:
204
204
  - check-influxdb-metrics.rb
205
205
  extensions: []
@@ -227,17 +227,17 @@ require_paths:
227
227
  - lib
228
228
  required_ruby_version: !ruby/object:Gem::Requirement
229
229
  requirements:
230
- - - '>='
230
+ - - ">="
231
231
  - !ruby/object:Gem::Version
232
232
  version: 2.0.0
233
233
  required_rubygems_version: !ruby/object:Gem::Requirement
234
234
  requirements:
235
- - - '>='
235
+ - - ">="
236
236
  - !ruby/object:Gem::Version
237
237
  version: '0'
238
238
  requirements: []
239
239
  rubyforge_project:
240
- rubygems_version: 2.4.8
240
+ rubygems_version: 2.4.5
241
241
  signing_key:
242
242
  specification_version: 4
243
243
  summary: Sensu plugins for InfluxDB to checks metrics