sensu-plugins-prometheus-checks 3.1.0 → 3.1.1
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/.travis.yml +3 -0
- data/lib/sensu/plugins/prometheus/checks/output.rb +1 -5
- data/lib/sensu/plugins/prometheus/checks/runner.rb +18 -21
- data/lib/sensu/plugins/prometheus/checks/version.rb +1 -1
- data/lib/sensu/plugins/prometheus/metrics.rb +81 -15
- data/test.sh +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2b75d8632e35855807a914b346bd3c8edaaf9aad
|
|
4
|
+
data.tar.gz: 6177065bc88675d911c9e3e1f8229486e5125ae4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b142eec6539074b6e487ce37f98d7586eec24c5bc456cd81b75dba9cefa2368e3709da078d56d0c56d5d58bedfb54527d25fcfe901265674ae33a2c3b227b69a
|
|
7
|
+
data.tar.gz: 25cfccae7ba869dfac79dccc9583f7e91bb3513c6a131ef3a9aa0ab00f41e5a6bcfb134c421516b8016177f60f8a6e4ab788c62f75fdd9b0adc007689e027ceb
|
data/.travis.yml
CHANGED
|
@@ -14,3 +14,6 @@ deploy:
|
|
|
14
14
|
secure: jcfJuW8IX7qBLIq2wyeXYvq3n4swwGUfs/Gk2IRkmo9AwbbTaNmzbNJgedEueKdNWbaMoW+cVPKWGuY2X7pIETQBsBm2TIJb4s/Y4hv/zGR8GyyHTVZsmX1BrW7tFWTpR16VZZdtql9T21eoTGs302QieE5b+k/iFfvXR6maaGUtLd32YA6QKGJ6WoTIVqhwkdBzGWgseMI6g31JrHQjprHw3mJq4CoDZhwNDCF1+IFtdjEvMf5fuGqcs+du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Y3tIDbVLXi3NQ/dtoqMDe6XbYhvnVBKbkhdOavc7gwCO6j34Pnfhtompw3Ax/DZB+/ZLV2d5PTos9hO0cCt2WU26gQx7dRm/ShykvZC14Vw=
|
|
@@ -26,11 +26,7 @@ module Sensu
|
|
|
26
26
|
'memory' => \
|
|
27
27
|
'Memory <%= value %>% |memory=<%= value %>',
|
|
28
28
|
'memory_per_cluster' => \
|
|
29
|
-
'Cluster Memory: <%= value %>% |memory=<%= value %>
|
|
30
|
-
'predict_disk_all' => \
|
|
31
|
-
"Disks to run out of space in the next <%= cfg['days'] %> days: <%= value %>",
|
|
32
|
-
'service' => \
|
|
33
|
-
"Service: <%= cfg['name'] %> (<%= cfg['state'] %>=<%= value %>)"
|
|
29
|
+
'Cluster Memory: <%= value %>% |memory=<%= value %>'
|
|
34
30
|
}.freeze
|
|
35
31
|
|
|
36
32
|
def render(template_name, vars)
|
|
@@ -75,33 +75,30 @@ module Sensu
|
|
|
75
75
|
check_cfg = check['cfg']
|
|
76
76
|
|
|
77
77
|
collect_metrics(check_name, check_cfg).each do |metric|
|
|
78
|
-
status = 0
|
|
79
|
-
|
|
80
78
|
# on service it will come with "state_required" flag
|
|
81
|
-
if
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
# normal threshold evaluation
|
|
92
|
-
status = evaluate(
|
|
93
|
-
metric['value'],
|
|
94
|
-
check_cfg['warn'],
|
|
95
|
-
check_cfg['crit']
|
|
96
|
-
)
|
|
97
|
-
end
|
|
79
|
+
status = if metric.key? 'status'
|
|
80
|
+
metric['status']
|
|
81
|
+
else
|
|
82
|
+
# normal threshold evaluation
|
|
83
|
+
evaluate(
|
|
84
|
+
metric['value'],
|
|
85
|
+
check_cfg['warn'],
|
|
86
|
+
check_cfg['crit']
|
|
87
|
+
)
|
|
88
|
+
end
|
|
98
89
|
|
|
99
90
|
template_variables = metric
|
|
100
91
|
template_variables['cfg'] = check_cfg
|
|
101
92
|
|
|
93
|
+
if metric.key? 'output'
|
|
94
|
+
output = metric['output']
|
|
95
|
+
else
|
|
96
|
+
output = @tmpl.render(check['check'], template_variables)
|
|
97
|
+
end
|
|
98
|
+
|
|
102
99
|
append_event(
|
|
103
|
-
"check_#{
|
|
104
|
-
|
|
100
|
+
"check_#{metric['name']}",
|
|
101
|
+
output,
|
|
105
102
|
status,
|
|
106
103
|
metric['source']
|
|
107
104
|
)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'sensu/plugins/utils/log'
|
|
2
|
+
require 'sensu/plugins/prometheus/checks'
|
|
2
3
|
|
|
3
4
|
module Sensu
|
|
4
5
|
module Plugins
|
|
@@ -8,6 +9,7 @@ module Sensu
|
|
|
8
9
|
# this class will be available as a final check.
|
|
9
10
|
class Metrics
|
|
10
11
|
include Sensu::Plugins::Utils::Log
|
|
12
|
+
include Sensu::Plugins::Prometheus::Checks
|
|
11
13
|
|
|
12
14
|
def initialize(prometheus_client)
|
|
13
15
|
@client = prometheus_client
|
|
@@ -36,59 +38,114 @@ module Sensu
|
|
|
36
38
|
# avaiable.
|
|
37
39
|
def disk(cfg)
|
|
38
40
|
mountpoint = "mountpoint=\"#{cfg['mount']}\""
|
|
41
|
+
disk_name = cfg['name'] || nice_disk_name(cfg['mount'])
|
|
39
42
|
query = @client.percent_query_free(
|
|
40
43
|
"node_filesystem_size{#{mountpoint}}",
|
|
41
44
|
"node_filesystem_avail{#{mountpoint}}"
|
|
42
45
|
)
|
|
43
|
-
prepare_metrics(
|
|
46
|
+
prepare_metrics("disk_#{disk_name}", @client.query(query))
|
|
44
47
|
end
|
|
45
48
|
|
|
46
49
|
# Query percentage of free space on file-systems, ignoring by default
|
|
47
50
|
# `tmpfs` or the regexp configured on check.
|
|
48
51
|
def disk_all(cfg)
|
|
52
|
+
results = []
|
|
49
53
|
ignored = cfg['ignore_fs'] || 'tmpfs'
|
|
50
54
|
ignore_fs = "fstype!~\"#{ignored}\""
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
|
|
56
|
+
queries = [
|
|
57
|
+
{
|
|
58
|
+
'used' => 'node_filesystem_size',
|
|
59
|
+
'free' => 'node_filesystem_avail',
|
|
60
|
+
'name' => 'disk'
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
'used' => 'node_filesystem_files',
|
|
64
|
+
'free' => 'node_filesystem_files_free',
|
|
65
|
+
'name' => 'inode'
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
queries.each do |q|
|
|
69
|
+
query = @client.percent_query_free(
|
|
70
|
+
"#{q['used']}{#{ignore_fs}}",
|
|
71
|
+
"#{q['free']}{#{ignore_fs}}"
|
|
72
|
+
)
|
|
73
|
+
@client.query(query).each do |result|
|
|
74
|
+
hostname = result['metric']['instance']
|
|
75
|
+
mountpoint = result['metric']['mountpoint']
|
|
76
|
+
disk_name = nice_disk_name(mountpoint)
|
|
77
|
+
percent = result['value'][1].to_i
|
|
78
|
+
results << { 'output' => "#{q['name'].capitalize}: #{mountpoint}, Usage: #{percent}% |#{q['name']}=#{percent}",
|
|
79
|
+
'name' => "#{q['name']}_#{disk_name}",
|
|
80
|
+
'source' => hostname }
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
results
|
|
56
84
|
end
|
|
57
85
|
|
|
58
86
|
# Queyr percentage of free inodes on check's configured mountpoint.
|
|
59
87
|
def inode(cfg)
|
|
60
88
|
mountpoint = "mountpoint=\"#{cfg['mount']}\""
|
|
89
|
+
disk_name = cfg['name'] || nice_disk_name(cfg['mount'])
|
|
61
90
|
query = @client.percent_query_free(
|
|
62
91
|
"node_filesystem_files{#{mountpoint}}",
|
|
63
92
|
"node_filesystem_files_free{#{mountpoint}}"
|
|
64
93
|
)
|
|
65
|
-
prepare_metrics(
|
|
94
|
+
prepare_metrics("inode_#{disk_name}", @client.query(query))
|
|
66
95
|
end
|
|
67
96
|
|
|
68
97
|
# Compose query to predict disk usage on the last day.
|
|
69
98
|
def predict_disk_all(cfg)
|
|
99
|
+
disks = []
|
|
70
100
|
days = cfg['days'].to_i
|
|
71
101
|
days_in_seconds = days.to_i * 86_400
|
|
72
102
|
filter = cfg['filter'] || {}
|
|
73
103
|
range_vector = cfg['sample_size'] || '24h'
|
|
104
|
+
exit_code = cfg['exit_code'] || 1
|
|
74
105
|
query = format(
|
|
75
106
|
'predict_linear(node_filesystem_avail%s[%s], %i) < 0',
|
|
76
107
|
filter,
|
|
77
108
|
range_vector,
|
|
78
109
|
days_in_seconds
|
|
79
110
|
)
|
|
80
|
-
|
|
111
|
+
@client.query(query).each do |result|
|
|
112
|
+
hostname = result['metric']['instance']
|
|
113
|
+
disk = result['metric']['mountpoint']
|
|
114
|
+
disks << "#{hostname}:#{disk}"
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
if disks.empty?
|
|
118
|
+
[{ 'status' => 0,
|
|
119
|
+
'output' => "No disks are predicted to run out of space in the next #{days} days",
|
|
120
|
+
'name' => 'predict_disk_all',
|
|
121
|
+
'source' => cfg['source'] }]
|
|
122
|
+
else
|
|
123
|
+
disks = disks.join(',')
|
|
124
|
+
[{ 'status' => exit_code.to_i,
|
|
125
|
+
'output' => "Disks predicted to run out of space in the next #{days} days: #{disks}",
|
|
126
|
+
'name' => 'predict_disk_all',
|
|
127
|
+
'source' => cfg['source'] }]
|
|
128
|
+
end
|
|
81
129
|
end
|
|
82
130
|
|
|
83
131
|
# Service metrics will contain it's "state" as "value".
|
|
84
132
|
def service(cfg)
|
|
85
|
-
|
|
133
|
+
results = []
|
|
134
|
+
defaults = {
|
|
135
|
+
'state' => 'active',
|
|
136
|
+
'state_required' => 1
|
|
137
|
+
}
|
|
86
138
|
cfg = defaults.merge(cfg)
|
|
87
139
|
query = format(
|
|
88
140
|
"node_systemd_unit_state{name='%s',state='%s'}",
|
|
89
141
|
cfg['name'], cfg['state']
|
|
90
142
|
)
|
|
91
|
-
prepare_metrics('
|
|
143
|
+
prepare_metrics("service_#{cfg['name']}", @client.query(query)).each do |metric|
|
|
144
|
+
metric['status'] = equals(metric['value'], cfg['state_required'])
|
|
145
|
+
metric['output'] = "Service: #{cfg['name']} (#{cfg['state']}=#{metric['value']})"
|
|
146
|
+
results << metric
|
|
147
|
+
end
|
|
148
|
+
results
|
|
92
149
|
end
|
|
93
150
|
|
|
94
151
|
# Query the percentage free memory.
|
|
@@ -113,7 +170,7 @@ module Sensu
|
|
|
113
170
|
@client.query(query).each do |result|
|
|
114
171
|
value = result['value'][1].to_f.round(2)
|
|
115
172
|
log.debug("[memory_per_cluster] value: '#{value}', source: '#{source}'")
|
|
116
|
-
metrics << { 'source' => source, 'value' => value }
|
|
173
|
+
metrics << { 'source' => source, 'value' => value, 'name' => "#{cluster}_memory" }
|
|
117
174
|
end
|
|
118
175
|
metrics
|
|
119
176
|
end
|
|
@@ -134,7 +191,7 @@ module Sensu
|
|
|
134
191
|
"[load_per_cluster] value: '#{value}', source: '#{source}'"
|
|
135
192
|
)
|
|
136
193
|
|
|
137
|
-
[{ 'source' => source, 'value' => value }]
|
|
194
|
+
[{ 'source' => source, 'value' => value, 'name' => "#{cluster}_load" }]
|
|
138
195
|
end
|
|
139
196
|
|
|
140
197
|
# Returns a single metric entry, with the sum of the total load on
|
|
@@ -157,7 +214,7 @@ module Sensu
|
|
|
157
214
|
"[load_per_cluster_minus_n] value: '#{value}', source: '#{source}'"
|
|
158
215
|
)
|
|
159
216
|
|
|
160
|
-
[{ 'source' => source, 'value' => value }]
|
|
217
|
+
[{ 'source' => source, 'value' => value, 'name' => "#{cluster}_load_minus_n" }]
|
|
161
218
|
end
|
|
162
219
|
|
|
163
220
|
# Current load per CPU.
|
|
@@ -180,7 +237,8 @@ module Sensu
|
|
|
180
237
|
)
|
|
181
238
|
metrics << {
|
|
182
239
|
'source' => source,
|
|
183
|
-
'value' => load_on_cpu
|
|
240
|
+
'value' => load_on_cpu,
|
|
241
|
+
'name' => 'load'
|
|
184
242
|
}
|
|
185
243
|
end
|
|
186
244
|
metrics
|
|
@@ -195,10 +253,18 @@ module Sensu
|
|
|
195
253
|
source = result['metric']['instance']
|
|
196
254
|
value = result['value'][1].to_i
|
|
197
255
|
log.debug("[#{metric_name}] value: '#{value}', source: '#{source}'")
|
|
198
|
-
metrics << { 'source' => source, 'value' => value }
|
|
256
|
+
metrics << { 'name' => metric_name, 'source' => source, 'value' => value }
|
|
199
257
|
end
|
|
200
258
|
metrics
|
|
201
259
|
end
|
|
260
|
+
|
|
261
|
+
def nice_disk_name(disk)
|
|
262
|
+
if disk == '/'
|
|
263
|
+
'root'
|
|
264
|
+
else
|
|
265
|
+
disk.gsub(%r{^/}, '').gsub(%r{/$}, '').gsub(%r{/}, '_')
|
|
266
|
+
end
|
|
267
|
+
end
|
|
202
268
|
end
|
|
203
269
|
end
|
|
204
270
|
end
|
data/test.sh
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/bin/bash -e
|
|
2
2
|
|
|
3
3
|
docker build -t saas/check_prometheus .
|
|
4
|
-
docker run --rm -e TRAVIS=$TRAVIS saas/check_prometheus rspec -c -f d
|
|
4
|
+
docker run --rm -e CODECOV_TOKEN=$CODECOV_TOKEN -e TRAVIS=$TRAVIS saas/check_prometheus rspec -c -f d
|
|
5
5
|
docker run --rm saas/check_prometheus rubocop
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sensu-plugins-prometheus-checks
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.1.
|
|
4
|
+
version: 3.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michael Russell
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2017-04-
|
|
12
|
+
date: 2017-04-26 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: bundler
|
|
@@ -192,9 +192,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
192
192
|
version: '0'
|
|
193
193
|
requirements: []
|
|
194
194
|
rubyforge_project:
|
|
195
|
-
rubygems_version: 2.
|
|
195
|
+
rubygems_version: 2.4.8
|
|
196
196
|
signing_key:
|
|
197
197
|
specification_version: 4
|
|
198
198
|
summary: Sensu plugin for monitoring servers by querying Prometheus
|
|
199
199
|
test_files: []
|
|
200
|
-
has_rdoc:
|