sensu-extensions-statsd 0.0.1 → 1.0.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: 424c1976524eb35b794354e8ed81a0b1d5aa3342
4
- data.tar.gz: 6bff69108c15a02b257d9ca40353028861eb5877
3
+ metadata.gz: f29a535c461792227243d4fb537d64d1caa4b6ce
4
+ data.tar.gz: 591c81f2cc090ff22f206395928a120fa72b376e
5
5
  SHA512:
6
- metadata.gz: fe7847188110c91313a8197a6c2b330c73ae8f22830be67fb56295289545cb6bf04c3d5f914f4842f504487391d4d14f64828c7113daf9be9becde143a6481ca
7
- data.tar.gz: 40bbcb68a42d323e862af5b30e349de9ed9a4bcd68f140839677c0208a59fd09ecd98e1bf07430b9e66b6ff4bbec822eb7c9bb4a62ec8dc18fc0c1fd3b61c49c
6
+ metadata.gz: a8308e1dfd68422cd8bf1ca99735a053dc7ae0b080852361cf86490d46f3cdb85cae364746605cb74917896b73f588199c5e5ee0bdd9caf4c61f203f98e81fc0
7
+ data.tar.gz: 41505c23361ae902a5874f12b8e8adabcd02339a92fdd09cb6800e6b0cfe9dd965fdc7ad13cc9c398e30af875743aef0924d548e848fad98bd6f83b25f8d672b
data/CHANGELOG.md CHANGED
@@ -1,30 +1,15 @@
1
1
  # Change Log
2
2
 
3
- This project adheres to [Semantic Versioning](http://semver.org/).
3
+ ## [Unreleased](https://github.com/sensu-extensions/sensu-extensions-statsd/tree/HEAD)
4
4
 
5
- This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/).
5
+ [Full Changelog](https://github.com/sensu-extensions/sensu-extensions-statsd/compare/v0.0.1...HEAD)
6
6
 
7
- ## [Unreleased]
7
+ **Merged pull requests:**
8
8
 
9
- ### Fixed
9
+ - Adhere to Etsy's specifications and behaviour [\#4](https://github.com/sensu-extensions/sensu-extensions-statsd/pull/4) ([portertech](https://github.com/portertech))
10
+ - Fix gauge implementation [\#3](https://github.com/sensu-extensions/sensu-extensions-statsd/pull/3) ([corro](https://github.com/corro))
10
11
 
11
- ### Added
12
+ ## [v0.0.1](https://github.com/sensu-extensions/sensu-extensions-statsd/tree/v0.0.1) (2016-12-09)
12
13
 
13
- ### Changed
14
14
 
15
- ## [1.0.0] - 2016-01-31
16
-
17
- ### Fixed
18
-
19
- ### Added
20
-
21
- ### Changed
22
-
23
- ## 0.0.1 - 2016-01-31
24
-
25
- ### Added
26
-
27
- - Initial release.
28
-
29
- [Unreleased]: https://github.com/sensu-extensions/sensu-extensions-template/compare/v1.0.0...HEAD
30
- [1.0.0]: https://github.com/sensu-extensions/sensu-extensions-template/compare/v0.0.1...v1.0.0
15
+ \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
data/README.md CHANGED
@@ -5,10 +5,19 @@ creates a StatsD TCP & UDP listener, receives StatsD metrics, parses
5
5
  them, and flushes them to the Graphite plaintext format for Sensu to
6
6
  send to Graphite or another TSDB.
7
7
 
8
+ This StatsD implementation attempts to adhere to [Etsy's metric type
9
+ specifications](https://github.com/etsy/statsd/blob/master/docs/metric_types.md).
10
+
11
+ [![Build Status](https://travis-ci.org/sensu-extensions/sensu-extensions-statsd.svg?branch=master)](https://travis-ci.org/sensu/sensu-extensions-statsd)
12
+
8
13
  ## Installation
9
14
 
15
+ This extension requires Sensu version >= 0.26.
16
+
17
+ On a Sensu client machine.
18
+
10
19
  ```
11
- sensu-install -e statsd
20
+ sensu-install -e statsd:1.0.0
12
21
  ```
13
22
 
14
23
  Edit `/etc/sensu/conf.d/extensions.json` to load it.
@@ -17,12 +26,18 @@ Edit `/etc/sensu/conf.d/extensions.json` to load it.
17
26
  {
18
27
  "extensions": {
19
28
  "statsd": {
20
- "version": "0.0.1"
29
+ "version": "1.0.0"
21
30
  }
22
31
  }
23
32
  }
24
33
  ```
25
34
 
35
+ Restart the Sensu client.
36
+
37
+ ``` shell
38
+ sudo service sensu-client restart
39
+ ```
40
+
26
41
  ## Configuration
27
42
 
28
43
  Edit `/etc/sensu/conf.d/statsd.json` to change its configuration.
@@ -35,14 +50,31 @@ Edit `/etc/sensu/conf.d/statsd.json` to change its configuration.
35
50
  }
36
51
  ```
37
52
 
38
- |param|type|default|description|
53
+ The following defaults make the integration behave like Etsy's StatsD
54
+ implementation.
55
+
56
+ |attribute|type|default|description|
39
57
  |----|----|----|---|
40
- |:bind|:string|"127.0.0.1"|IP to bind the StatsD sockets to|
41
- |:port|:integer|8125|Port to bind the StatsD sockets to|
42
- |:flush_interval|:integer|10|The StatsD flush interval|
43
- |:send_interval|:integer|30|How often Graphite metrics are sent to Sensu|
44
- |:percentile|:integer|90|The percentile to calculate for StatsD metrics|
45
- |:add_client_prefix|:boolean|true|If the Sensu client name should prefix the Graphite metric path|
46
- |:path_prefix|:string|"statsd"|The optional Graphite metric path prefix (after client name)|
47
- |:add_path_prefix|:boolean|true|If the path_prefix should be used|
48
- |:handler|:string|"graphite"|Handler to use for the Graphite metrics|
58
+ |bind|string|"127.0.0.1"|IP to bind the StatsD sockets to|
59
+ |port|integer|8125|Port to bind the StatsD sockets to|
60
+ |flush_interval|integer|10|The StatsD flush interval|
61
+ |send_interval|integer|30|How often Graphite metrics are sent to Sensu|
62
+ |percentile|integer|90|The percentile to calculate for StatsD metrics|
63
+ |add_client_prefix|boolean|true|If the Sensu client name should prefix the Graphite metric path|
64
+ |path_prefix|string|"statsd"|The optional Graphite metric path prefix (after client name)|
65
+ |add_path_prefix|boolean|true|If the path_prefix should be used|
66
+ |delete_gauges|boolean|false|If gauges that have not been updated should be deleted instead of flushed|
67
+ |delete_counters|boolean|false|If counters with a value of 0 should be deleted instead of flushed|
68
+ |delete_timers|boolean|false|If timers with a count of 0 should be deleted instead of flushed|
69
+ |reset_gauges|boolean|false|If gauges should be reset to 0 after flushing|
70
+ |reset_counters|boolean|true|If counters should be reset to 0 after flushing|
71
+ |reset_timers|boolean|true|If timers should be reset/cleared after flushing|
72
+ |handler|string|"graphite"|Handler to use for the Graphite metrics|
73
+
74
+ ## Example
75
+
76
+ Test the StatsD TCP socket:
77
+
78
+ ``` shell
79
+ echo "orders:1|c" | nc 127.0.0.1 8125
80
+ ```
@@ -27,6 +27,12 @@ module Sensu
27
27
  :flush_interval => 10,
28
28
  :send_interval => 30,
29
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,
30
36
  :add_client_prefix => true,
31
37
  :path_prefix => "statsd",
32
38
  :add_path_prefix => true,
@@ -71,6 +77,19 @@ module Sensu
71
77
 
72
78
  private
73
79
 
80
+ def clean(hash, delete=false, reset=false)
81
+ if delete
82
+ hash.delete_if do |key, value|
83
+ value == 0 || value == []
84
+ end
85
+ end
86
+ if reset
87
+ hash.each do |key, value|
88
+ hash[key] = (value.is_a?(Array) ? [] : 0)
89
+ end
90
+ end
91
+ end
92
+
74
93
  def add_metric(*args)
75
94
  value = args.pop
76
95
  path = []
@@ -94,36 +113,42 @@ module Sensu
94
113
 
95
114
  def flush!
96
115
  @gauges.each do |name, value|
97
- add_metric("gauges", name, value)
116
+ unless value == 0 && options[:delete_gauges]
117
+ add_metric("gauges", name, value)
118
+ end
98
119
  end
99
- @gauges.clear
120
+ clean(@gauges, options[:delete_gauges], options[:reset_gauges])
100
121
  @counters.each do |name, value|
101
- add_metric("counters", name, value)
122
+ unless value == 0 && options[:delete_counters]
123
+ add_metric("counters", name, value.to_i)
124
+ end
102
125
  end
103
- @counters.clear
126
+ clean(@counters, options[:delete_counters], options[:reset_counters])
104
127
  @timers.each do |name, values|
105
- values.sort!
106
- length = values.length
107
- min = values.first
108
- max = values.last
109
- mean = min
110
- max_at_threshold = min
111
- percentile = options[:percentile]
112
- if length > 1
113
- threshold_index = ((100 - percentile) / 100.0) * length
114
- threshold_count = length - threshold_index.round
115
- valid_values = values.slice(0, threshold_count)
116
- max_at_threshold = valid_values[-1]
117
- sum = 0
118
- valid_values.each { |v| sum += v }
119
- mean = sum / valid_values.length
128
+ unless values.empty? && options[:delete_timers]
129
+ values.sort!
130
+ length = values.length
131
+ min = values.first || 0
132
+ max = values.last || 0
133
+ mean = min
134
+ max_at_threshold = min
135
+ percentile = options[:percentile]
136
+ if length > 1
137
+ threshold_index = ((100 - percentile) / 100.0) * length
138
+ threshold_count = length - threshold_index.round
139
+ valid_values = values.slice(0, threshold_count)
140
+ max_at_threshold = valid_values[-1]
141
+ sum = 0
142
+ valid_values.each { |v| sum += v }
143
+ mean = sum / valid_values.length
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)
120
149
  end
121
- add_metric("timers", name, "lower", min)
122
- add_metric("timers", name, "mean", mean)
123
- add_metric("timers", name, "upper", max)
124
- add_metric("timers", name, "upper_#{percentile}", max_at_threshold)
125
150
  end
126
- @timers.clear
151
+ clean(@timers, options[:delete_timers], options[:reset_timers])
127
152
  @logger.debug("flushed statsd metrics")
128
153
  end
129
154
 
@@ -136,17 +161,23 @@ module Sensu
136
161
  def setup_parser
137
162
  parser = proc do |data|
138
163
  begin
139
- nv, type = data.strip.split("|")
140
- name, value = nv.split(":")
164
+ nv, type, raw_sample = data.strip.split("|")
165
+ name, raw_value = nv.split(":")
166
+ value = Float(raw_value)
167
+ sample = Float(raw_sample ? raw_sample.split("@").last : 1)
141
168
  case type
142
169
  when "g"
143
- @gauges[name] = Float(value)
170
+ if raw_value.start_with?("+")
171
+ @gauges[name] += value
172
+ elsif raw_value.start_with?("-")
173
+ @gauges[name] -= value.abs
174
+ else
175
+ @gauges[name] = value
176
+ end
144
177
  when /^c/, "m"
145
- _, raw_sample = type.split("@")
146
- sample = (raw_sample ? Float(raw_sample) : 1)
147
- @counters[name] += Integer(value) * (1 / sample)
148
- when "ms", "h"
149
- @timers[name] << Float(value)
178
+ @counters[name] += value * (1 / sample)
179
+ when "ms", "h", "t"
180
+ @timers[name] << value * (1 / sample)
150
181
  end
151
182
  rescue => error
152
183
  @logger.error("statsd parser error", :error => error.to_s)
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: 0.0.1
4
+ version: 1.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: 2016-12-09 00:00:00.000000000 Z
11
+ date: 2017-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-extension
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: github_changelog_generator
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Check extension to run a StatsD implementation
98
112
  email:
99
113
  - "<sensu-users@googlegroups.com>"