sensu-plugins-outlyer 0.5.0 → 0.6.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 +2 -1
- data/bin/outlyer-metrics.rb +68 -46
- data/lib/sensu-plugins-outlyer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a52cd273a16bb979d729d59b18b362fea57a28e2735b66b3a4b85cf210d8d4da
|
4
|
+
data.tar.gz: 57bbeafe4ee42dd5cdd9eebb8ce32382e10270b10cb8d048f3d967159d3851dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bcb06a1122343f198587265b870a38c1518a1cb52590f59c8f577fd97bfdd65fed132616e5ea8535d9f9086e4ab10add59e90ac4972e77d38092f138ee851da
|
7
|
+
data.tar.gz: d7ff052d31f96d246b5ba5d09f03df74797c30c76172176939a740abc5b4cf30f61eef459bff0e8ae32d479096fe600df6505fbf009ece055f7f829e6b8097de
|
data/CHANGELOG.md
CHANGED
@@ -3,10 +3,11 @@ 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.
|
6
|
+
## [0.6.0] - 2018-07-16
|
7
7
|
- Made debug flag boolean
|
8
8
|
- Added additional debug logging for troubleshooting
|
9
9
|
- Added Unit Tests
|
10
|
+
- Added new Graphite parsing method with filters
|
10
11
|
|
11
12
|
## [0.4.0] - 2018-07-13
|
12
13
|
- Added handling for client environments set as array of values
|
data/bin/outlyer-metrics.rb
CHANGED
@@ -75,10 +75,6 @@ class OutlyerMetrics < Sensu::Handler
|
|
75
75
|
@check_name = @event['check']['name']
|
76
76
|
@host = @event['client']['name'].strip.to_s
|
77
77
|
@environment = @event['client']['environment']
|
78
|
-
if @environment.kind_of?(Array)
|
79
|
-
# environment can be an array, so merge values with hyphens
|
80
|
-
@environment = @environment.join("-")
|
81
|
-
end
|
82
78
|
timestamp = @event['check']['executed'].to_i * 1000
|
83
79
|
|
84
80
|
if config[:debug]
|
@@ -91,7 +87,7 @@ class OutlyerMetrics < Sensu::Handler
|
|
91
87
|
else
|
92
88
|
parse_graphite_output(output)
|
93
89
|
end
|
94
|
-
|
90
|
+
|
95
91
|
# Add a service status metric
|
96
92
|
metrics.push(create_datapoint('service.status', check_status, timestamp, {service: "sensu.#{sanitize_value(@check_name)}"}))
|
97
93
|
# Post metrics to Outlyer
|
@@ -100,23 +96,21 @@ class OutlyerMetrics < Sensu::Handler
|
|
100
96
|
|
101
97
|
# Create a single data point
|
102
98
|
#
|
103
|
-
# @param name
|
104
|
-
# @param value
|
105
|
-
# @param time
|
106
|
-
# @param labels
|
99
|
+
# @param name [String] metric name
|
100
|
+
# @param value [Float] metric value
|
101
|
+
# @param time [Integer] epoch timestamp of metric in milliseconds
|
102
|
+
# @param labels [HashMap] (Optional) Additional labels to append to data point
|
103
|
+
# @param metric_host [String] (Optional) Set a host for the metric
|
107
104
|
#
|
108
|
-
def create_datapoint(name, value, time, labels =
|
105
|
+
def create_datapoint(name, value, time, labels = {}, metric_host=@host)
|
109
106
|
datapoint = {
|
110
|
-
host:
|
111
|
-
labels:
|
112
|
-
environment: @environment,
|
113
|
-
},
|
107
|
+
host: metric_host,
|
108
|
+
labels: labels,
|
114
109
|
name: name,
|
115
110
|
timestamp: time,
|
116
111
|
type: 'gauge',
|
117
112
|
value: value
|
118
113
|
}
|
119
|
-
datapoint[:labels].merge!(labels) unless labels.nil?
|
120
114
|
datapoint
|
121
115
|
end
|
122
116
|
|
@@ -160,49 +154,77 @@ class OutlyerMetrics < Sensu::Handler
|
|
160
154
|
def parse_graphite_output(output)
|
161
155
|
data = []
|
162
156
|
|
163
|
-
# Get
|
164
|
-
|
157
|
+
# Get Schemes to parse Graphite metrics if exists
|
158
|
+
schemes = nil
|
165
159
|
if settings['outlyer'].key?('schemes') && settings['outlyer']['schemes'] != nil
|
166
|
-
|
167
|
-
scheme = settings['outlyer']['schemes'][@check_name]
|
168
|
-
else
|
169
|
-
# Get default scheme if check specific scheme not defined
|
170
|
-
scheme = settings['outlyer']['schemes']['default']
|
171
|
-
end
|
160
|
+
schemes = settings['outlyer']['schemes']
|
172
161
|
end
|
173
162
|
|
174
163
|
# Parse the metric on each line in graphite format
|
175
164
|
output.split("\n").each do |metric|
|
176
165
|
m = metric.split
|
177
166
|
next unless m.count == 3
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
167
|
+
labels = {service: "sensu.#{sanitize_value(@check_name)}"}
|
168
|
+
metric_host = @host
|
169
|
+
|
170
|
+
# Check to see if we have a scheme filter that matches the metric name
|
171
|
+
template = nil
|
172
|
+
if schemes
|
173
|
+
schemes.each do |scheme|
|
174
|
+
filter = Regexp.new("^#{Regexp.escape(scheme['filter']).gsub('\*','[^\.]*?')}$")
|
175
|
+
if m[0] =~ filter
|
176
|
+
template = scheme['template']
|
177
|
+
if config[:debug]
|
178
|
+
puts "Template Found: '#{template}' with REGEX '#{filter.inspect}'"
|
179
|
+
end
|
180
|
+
break
|
181
|
+
end
|
192
182
|
end
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
183
|
+
|
184
|
+
# Found a template to parse metric
|
185
|
+
if template
|
186
|
+
metric_parts = m[0].split('.')
|
187
|
+
template_parts = template.split('.')
|
188
|
+
|
189
|
+
# Iterate through the template to parse the metric labels
|
190
|
+
template_parts.each_with_index do |val,index|
|
191
|
+
key = sanitize_value(val, 40)
|
192
|
+
value = sanitize_value(metric_parts[index])
|
193
|
+
if labels.key?(key)
|
194
|
+
# If value is spread over multiple parts re-append the value
|
195
|
+
labels[key] += ".#{value}"
|
196
|
+
else
|
197
|
+
labels.merge!(Hash[key,value])
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
# Now we have all the labels extracted, need to ensure a
|
202
|
+
# name was given and optional host
|
203
|
+
if labels.key?('name')
|
204
|
+
metric_name = labels['name']
|
205
|
+
labels.delete('name')
|
206
|
+
end
|
207
|
+
if labels.key?('host')
|
208
|
+
metric_host = labels['host']
|
209
|
+
labels.delete('host')
|
210
|
+
end
|
211
|
+
|
212
|
+
else
|
213
|
+
# If no template found, ignore metric and put warning in handler
|
214
|
+
# this avoids un-configured checks sending bad data to Outlyer
|
215
|
+
puts "No scheme was found that matches the metric '#{m[0]}.'"
|
216
|
+
puts "Please configure a scheme for the check '#{@check_name}' "\
|
217
|
+
"on the Sensu client '#{@host}'."
|
218
|
+
exit(2)
|
219
|
+
metric_name = sanitize_value(m[0])
|
198
220
|
end
|
221
|
+
else
|
222
|
+
metric_name = sanitize_value(m[0])
|
199
223
|
end
|
200
|
-
|
201
|
-
metric_name = sanitize_value(metric_parts.join('.'))
|
202
|
-
end
|
224
|
+
|
203
225
|
value = m[1].to_f
|
204
226
|
time = m[2].to_i * 1000
|
205
|
-
point = create_datapoint(metric_name, value, time, labels)
|
227
|
+
point = create_datapoint(metric_name, value, time, labels, metric_host)
|
206
228
|
data.push(point)
|
207
229
|
end
|
208
230
|
data
|