sensu-extensions-statsd 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -3
- data/README.md +2 -1
- data/lib/sensu/extensions/statsd.rb +75 -77
- metadata +23 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3690d2d8fba2db12035bf6a0fd96865e682ce7cc
|
4
|
+
data.tar.gz: a0cfe9cccde8e9be923555449dfc2528b3c300b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f92582be13f461bb0876a859cff9d857fa8f829f40ba33a474aee660de5953c23d45fb01963aabd1bbad36298ba8d79be345e7e2d26ce50330042108f54e121b
|
7
|
+
data.tar.gz: 315b55ff68d05e47c32b50de854bf11e15acad58412bfa9d4290d946775208b0190ccfa2b7c04c578bd622f740caaef3f8ce1e9a22eec10de87ee7681958e609
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,20 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [
|
3
|
+
## [2.0.0] - 2017-02-01
|
4
|
+
### Changed
|
5
|
+
- The definition of statsd.rb to include truncate_output as a configurable option.
|
6
|
+
(@TQaztec)
|
4
7
|
|
5
|
-
|
8
|
+
### Security
|
9
|
+
- update 'rubocop' dependency to '~> 0.51.0' per:
|
10
|
+
https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-8418.
|
11
|
+
(@TQaztec)
|
12
|
+
|
13
|
+
### Breaking Change
|
14
|
+
- Dropping ruby 2.0 support after updating rubocop dependency.
|
15
|
+
|
16
|
+
## [v1.0.0](https://github.com/sensu-extensions/sensu-extensions-statsd/tree/v1.0.0) (2017-03-21)
|
17
|
+
[Full Changelog](https://github.com/sensu-extensions/sensu-extensions-statsd/compare/v0.0.1...v1.0.0)
|
6
18
|
|
7
19
|
**Merged pull requests:**
|
8
20
|
|
@@ -12,4 +24,4 @@
|
|
12
24
|
## [v0.0.1](https://github.com/sensu-extensions/sensu-extensions-statsd/tree/v0.0.1) (2016-12-09)
|
13
25
|
|
14
26
|
|
15
|
-
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
27
|
+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ send to Graphite or another TSDB.
|
|
8
8
|
This StatsD implementation attempts to adhere to [Etsy's metric type
|
9
9
|
specifications](https://github.com/etsy/statsd/blob/master/docs/metric_types.md).
|
10
10
|
|
11
|
-
[![Build Status](https://travis-ci.org/sensu-extensions/sensu-extensions-statsd.svg?branch=master)](https://travis-ci.org/sensu/sensu-extensions-statsd)
|
11
|
+
[![Build Status](https://travis-ci.org/sensu-extensions/sensu-extensions-statsd.svg?branch=master)](https://travis-ci.org/sensu-extensions/sensu-extensions-statsd)
|
12
12
|
|
13
13
|
## Installation
|
14
14
|
|
@@ -70,6 +70,7 @@ implementation.
|
|
70
70
|
|reset_counters|boolean|true|If counters should be reset to 0 after flushing|
|
71
71
|
|reset_timers|boolean|true|If timers should be reset/cleared after flushing|
|
72
72
|
|handler|string|"graphite"|Handler to use for the Graphite metrics|
|
73
|
+
|truncate_output|boolean|true|If output should be truncated|
|
73
74
|
|
74
75
|
## Example
|
75
76
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'sensu/extension'
|
2
2
|
|
3
3
|
module Sensu
|
4
4
|
module Extension
|
@@ -10,33 +10,34 @@ module Sensu
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
class StatsD < Check
|
13
|
+
class StatsD < Check # rubocop:disable Metrics/ClassLength
|
14
14
|
def name
|
15
|
-
|
15
|
+
'statsd'
|
16
16
|
end
|
17
17
|
|
18
18
|
def description
|
19
|
-
|
19
|
+
'a statsd implementation'
|
20
20
|
end
|
21
21
|
|
22
|
-
def options
|
22
|
+
def options # rubocop:disable Metrics/MethodLength
|
23
23
|
return @options if @options
|
24
24
|
@options = {
|
25
|
-
:
|
26
|
-
:
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
34
|
-
:
|
35
|
-
:
|
36
|
-
:
|
37
|
-
:
|
38
|
-
:
|
39
|
-
:
|
25
|
+
bind: '127.0.0.1',
|
26
|
+
port: 8125,
|
27
|
+
flush_interval: 10,
|
28
|
+
send_interval: 30,
|
29
|
+
percentile: 90,
|
30
|
+
delete_gauges: false,
|
31
|
+
delete_counters: false,
|
32
|
+
delete_timers: false,
|
33
|
+
reset_gauges: false,
|
34
|
+
reset_counters: true,
|
35
|
+
reset_timers: true,
|
36
|
+
add_client_prefix: true,
|
37
|
+
path_prefix: 'statsd',
|
38
|
+
add_path_prefix: true,
|
39
|
+
handler: 'graphite',
|
40
|
+
truncate_output: true
|
40
41
|
}
|
41
42
|
@options.merge!(@settings[:statsd]) if @settings[:statsd].is_a?(Hash)
|
42
43
|
@options
|
@@ -44,12 +45,13 @@ module Sensu
|
|
44
45
|
|
45
46
|
def definition
|
46
47
|
{
|
47
|
-
:
|
48
|
-
:
|
49
|
-
:
|
50
|
-
:
|
51
|
-
:
|
52
|
-
:
|
48
|
+
type: 'metric',
|
49
|
+
name: name,
|
50
|
+
interval: options[:send_interval],
|
51
|
+
standalone: true,
|
52
|
+
output_format: 'graphite_plaintext',
|
53
|
+
handler: options[:handler],
|
54
|
+
truncate_output: options[:truncate_output]
|
53
55
|
}
|
54
56
|
end
|
55
57
|
|
@@ -66,10 +68,10 @@ module Sensu
|
|
66
68
|
end
|
67
69
|
|
68
70
|
def run
|
69
|
-
output =
|
71
|
+
output = ''
|
70
72
|
if @metrics
|
71
73
|
output << @metrics.join("\n") + "\n" unless @metrics.empty?
|
72
|
-
@logger.info(
|
74
|
+
@logger.info('statsd collected metrics', count: @metrics.count)
|
73
75
|
@metrics = []
|
74
76
|
end
|
75
77
|
yield output, 0
|
@@ -77,9 +79,9 @@ module Sensu
|
|
77
79
|
|
78
80
|
private
|
79
81
|
|
80
|
-
def clean(hash, delete=false, reset=false)
|
82
|
+
def clean(hash, delete = false, reset = false)
|
81
83
|
if delete
|
82
|
-
hash.delete_if do |
|
84
|
+
hash.delete_if do |_key, value|
|
83
85
|
value == 0 || value == []
|
84
86
|
end
|
85
87
|
end
|
@@ -90,66 +92,61 @@ module Sensu
|
|
90
92
|
end
|
91
93
|
end
|
92
94
|
|
93
|
-
def add_metric(*args)
|
95
|
+
def add_metric(*args) # rubocop:disable Metrics/MethodLength
|
94
96
|
value = args.pop
|
95
97
|
path = []
|
96
98
|
path << @settings[:client][:name] if options[:add_client_prefix]
|
97
99
|
path << options[:path_prefix] if options[:add_path_prefix]
|
98
|
-
path = (path + args).join(
|
100
|
+
path = (path + args).join('.')
|
99
101
|
if path !~ /^[A-Za-z0-9\._-]*$/
|
100
|
-
@logger.info(
|
101
|
-
|
102
|
-
|
103
|
-
:value => value
|
104
|
-
})
|
102
|
+
@logger.info('invalid statsd metric', reason: 'metric path must only consist of alpha-numeric characters, periods, underscores, and dashes',
|
103
|
+
path: path,
|
104
|
+
value: value)
|
105
105
|
else
|
106
|
-
@logger.debug(
|
107
|
-
|
108
|
-
|
109
|
-
})
|
110
|
-
@metrics << [path, value, Time.now.to_i].join(" ")
|
106
|
+
@logger.debug('adding statsd metric', path: path,
|
107
|
+
value: value)
|
108
|
+
@metrics << [path, value, Time.now.to_i].join(' ')
|
111
109
|
end
|
112
110
|
end
|
113
111
|
|
114
112
|
def flush!
|
115
113
|
@gauges.each do |name, value|
|
116
114
|
unless value == 0 && options[:delete_gauges]
|
117
|
-
add_metric(
|
115
|
+
add_metric('gauges', name, value)
|
118
116
|
end
|
119
117
|
end
|
120
118
|
clean(@gauges, options[:delete_gauges], options[:reset_gauges])
|
121
119
|
@counters.each do |name, value|
|
122
120
|
unless value == 0 && options[:delete_counters]
|
123
|
-
add_metric(
|
121
|
+
add_metric('counters', name, value.to_i)
|
124
122
|
end
|
125
123
|
end
|
126
124
|
clean(@counters, options[:delete_counters], options[:reset_counters])
|
127
125
|
@timers.each do |name, values|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
end
|
145
|
-
add_metric("timers", name, "lower", min)
|
146
|
-
add_metric("timers", name, "mean", mean)
|
147
|
-
add_metric("timers", name, "upper", max)
|
148
|
-
add_metric("timers", name, "upper_#{percentile}", max_at_threshold)
|
126
|
+
next if values.empty? && options[:delete_timers]
|
127
|
+
values.sort!
|
128
|
+
length = values.length
|
129
|
+
min = values.first || 0
|
130
|
+
max = values.last || 0
|
131
|
+
mean = min
|
132
|
+
max_at_threshold = min
|
133
|
+
percentile = options[:percentile]
|
134
|
+
if length > 1
|
135
|
+
threshold_index = ((100 - percentile) / 100.0) * length
|
136
|
+
threshold_count = length - threshold_index.round
|
137
|
+
valid_values = values.slice(0, threshold_count)
|
138
|
+
max_at_threshold = valid_values[-1]
|
139
|
+
sum = 0
|
140
|
+
valid_values.each { |v| sum += v }
|
141
|
+
mean = sum / valid_values.length
|
149
142
|
end
|
143
|
+
add_metric('timers', name, 'lower', min)
|
144
|
+
add_metric('timers', name, 'mean', mean)
|
145
|
+
add_metric('timers', name, 'upper', max)
|
146
|
+
add_metric('timers', name, "upper_#{percentile}", max_at_threshold)
|
150
147
|
end
|
151
148
|
clean(@timers, options[:delete_timers], options[:reset_timers])
|
152
|
-
@logger.debug(
|
149
|
+
@logger.debug('flushed statsd metrics')
|
153
150
|
end
|
154
151
|
|
155
152
|
def setup_flush_timers
|
@@ -158,29 +155,30 @@ module Sensu
|
|
158
155
|
end
|
159
156
|
end
|
160
157
|
|
161
|
-
|
158
|
+
# TODO: come back and refactor me
|
159
|
+
def setup_parser # rubocop:disable Metrics/MethodLength
|
162
160
|
parser = proc do |data|
|
163
161
|
begin
|
164
|
-
nv, type, raw_sample = data.strip.split(
|
165
|
-
name, raw_value = nv.split(
|
162
|
+
nv, type, raw_sample = data.strip.split('|')
|
163
|
+
name, raw_value = nv.split(':')
|
166
164
|
value = Float(raw_value)
|
167
|
-
sample = Float(raw_sample ? raw_sample.split(
|
165
|
+
sample = Float(raw_sample ? raw_sample.split('@').last : 1)
|
168
166
|
case type
|
169
|
-
when
|
170
|
-
if raw_value.start_with?(
|
167
|
+
when 'g'
|
168
|
+
if raw_value.start_with?('+')
|
171
169
|
@gauges[name] += value
|
172
|
-
elsif raw_value.start_with?(
|
170
|
+
elsif raw_value.start_with?('-')
|
173
171
|
@gauges[name] -= value.abs
|
174
172
|
else
|
175
173
|
@gauges[name] = value
|
176
174
|
end
|
177
|
-
when /^c/,
|
175
|
+
when /^c/, 'm'
|
178
176
|
@counters[name] += value * (1 / sample)
|
179
|
-
when
|
177
|
+
when 'ms', 'h', 't'
|
180
178
|
@timers[name] << value * (1 / sample)
|
181
179
|
end
|
182
180
|
rescue => error
|
183
|
-
@logger.error(
|
181
|
+
@logger.error('statsd parser error', error: error.to_s)
|
184
182
|
end
|
185
183
|
EM.next_tick do
|
186
184
|
@data.pop(&parser)
|
@@ -190,7 +188,7 @@ module Sensu
|
|
190
188
|
end
|
191
189
|
|
192
190
|
def setup_statsd_socket
|
193
|
-
@logger.debug(
|
191
|
+
@logger.debug('binding statsd tcp and udp sockets', options: options)
|
194
192
|
bind = options[:bind]
|
195
193
|
port = options[:port]
|
196
194
|
EM.start_server(bind, port, StatsDSimpleSocket) do |socket|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-extensions-statsd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sensu-Extensions and contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sensu-extension
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.6'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: github_changelog_generator
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -81,7 +81,21 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.51.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.51.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sensu-logger
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
101
|
- - ">="
|
@@ -95,7 +109,7 @@ dependencies:
|
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
112
|
+
name: sensu-settings
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
115
|
- - ">="
|
@@ -130,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
144
|
requirements:
|
131
145
|
- - ">="
|
132
146
|
- !ruby/object:Gem::Version
|
133
|
-
version:
|
147
|
+
version: 2.1.0
|
134
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
149
|
requirements:
|
136
150
|
- - ">="
|
@@ -138,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
152
|
version: '0'
|
139
153
|
requirements: []
|
140
154
|
rubyforge_project:
|
141
|
-
rubygems_version: 2.
|
155
|
+
rubygems_version: 2.5.2.1
|
142
156
|
signing_key:
|
143
157
|
specification_version: 4
|
144
158
|
summary: Check extension to run a StatsD implementation
|