sensu-plugin 2.2.0 → 2.3.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/lib/sensu-plugin.rb +1 -1
- data/lib/sensu-plugin/metric/cli.rb +66 -0
- data/test/external_metric_test.rb +39 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a61eebfc31a5b1110afdbc0931b0f24fae2be0b6
|
4
|
+
data.tar.gz: c55bce147df126c8b799f788ccfceeac5b252e53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25436cf2246717c5c24b9101878d8de2f107198db84744e8f7338445de53b3dc1032af7a2006766d403ac556f7e8cdbfd40f57d619e4dd6c69dd5f9a037c34c6
|
7
|
+
data.tar.gz: 24e159cf2077552ec1cf46e6e973126b533560ff497a9f0168c66dc4b8f89a1f334f0ccb1d1dd7672032b8bd89a7b18ea94b493c59acf680cc575a508bbda716
|
data/lib/sensu-plugin.rb
CHANGED
@@ -17,6 +17,14 @@ module Sensu
|
|
17
17
|
end
|
18
18
|
|
19
19
|
class Graphite < Sensu::Plugin::CLI
|
20
|
+
# Outputs metrics using the Statsd datagram format
|
21
|
+
#
|
22
|
+
# @param args [Array<String, Int>] list of arguments
|
23
|
+
# @note the argument order should be:
|
24
|
+
# `metric_path`: Mandatory, name for the metric,
|
25
|
+
# `value`: Mandatory, metric value
|
26
|
+
# `timestamp`: Optional, unix timestamp, defaults to current time
|
27
|
+
# @return [String] formated metric data
|
20
28
|
def output(*args)
|
21
29
|
return if args.empty?
|
22
30
|
if args[0].is_a?(Exception) || args[1].nil?
|
@@ -29,7 +37,16 @@ module Sensu
|
|
29
37
|
end
|
30
38
|
|
31
39
|
class Statsd < Sensu::Plugin::CLI
|
40
|
+
# Outputs metrics using the Statsd datagram format
|
41
|
+
#
|
42
|
+
# @param args [Array<String, Int>] list of arguments
|
43
|
+
# @note the argument order should be:
|
44
|
+
# `metric_name`: Mandatory, name for the metric,
|
45
|
+
# `value`: Mandatory, metric value
|
46
|
+
# `type`: Optional, metric type- `c` for counter, `g` for gauge, `ms` for timer, `s` for set
|
47
|
+
# @return [String] formated metric data
|
32
48
|
def output(*args)
|
49
|
+
return if args.empty?
|
33
50
|
if args[0].is_a?(Exception) || args[1].nil?
|
34
51
|
puts args[0].to_s
|
35
52
|
else
|
@@ -38,6 +55,55 @@ module Sensu
|
|
38
55
|
end
|
39
56
|
end
|
40
57
|
end
|
58
|
+
|
59
|
+
class Dogstatsd < Sensu::Plugin::CLI
|
60
|
+
# Outputs metrics using the DogStatsd datagram format
|
61
|
+
#
|
62
|
+
# @param args [Array<String, Int>] list of arguments
|
63
|
+
# @note the argument order should be:
|
64
|
+
# `metric_name`: Mandatory, name for the metric,
|
65
|
+
# `value`: Mandatory, metric value
|
66
|
+
# `type`: Optional, metric type- `c` for counter, `g` for gauge, `ms` for timer, `h` for histogram, `s` for set
|
67
|
+
# `tags`: Optional, a comma separated key:value string `tag1:value1,tag2:value2`
|
68
|
+
# @return [String] formated metric data
|
69
|
+
def output(*args)
|
70
|
+
return if args.empty?
|
71
|
+
if args[0].is_a?(Exception) || args[1].nil?
|
72
|
+
puts args[0].to_s
|
73
|
+
else
|
74
|
+
type = args[2] || 'kv'
|
75
|
+
tags = args[3] ? "##{args[3]}" : nil
|
76
|
+
puts [args[0..1].join(':'), type, tags].compact.join('|')
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class Influxdb < Sensu::Plugin::CLI
|
82
|
+
# Outputs metrics using the InfluxDB line protocol format
|
83
|
+
#
|
84
|
+
# @param args [Array<String, Int>] list of arguments
|
85
|
+
# @note the argument order should be:
|
86
|
+
# `measurement_name`: Mandatory, name for the InfluxDB measurement,
|
87
|
+
# `fields`: Mandatory, either an integer or a comma separated key=value string `field1=value1,field2=value2`
|
88
|
+
# `tags`: Optional, a comma separated key=value string `tag1=value1,tag2=value2`
|
89
|
+
# `timestamp`: Optional, unix timestamp, defaults to current time
|
90
|
+
# @return [String] formated metric data
|
91
|
+
def output(*args)
|
92
|
+
return if args.empty?
|
93
|
+
if args[0].is_a?(Exception) || args[1].nil?
|
94
|
+
puts args[0].to_s
|
95
|
+
else
|
96
|
+
fields = if args[1].is_a?(Integer)
|
97
|
+
"value=#{args[1]}"
|
98
|
+
else
|
99
|
+
args[1]
|
100
|
+
end
|
101
|
+
measurement = [args[0], args[2]].compact.join(',')
|
102
|
+
ts = args[3] || Time.now.to_i
|
103
|
+
puts [measurement, fields, ts].join(' ')
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
41
107
|
end
|
42
108
|
end
|
43
109
|
end
|
@@ -23,7 +23,10 @@ class TestGraphiteMetricExternal < MiniTest::Test
|
|
23
23
|
|
24
24
|
def test_multi
|
25
25
|
lines = run_script.split("\n")
|
26
|
-
assert lines.size == 2
|
26
|
+
assert lines.size == 2
|
27
|
+
lines.each do |line|
|
28
|
+
assert line.split("\s").size == 3
|
29
|
+
end
|
27
30
|
end
|
28
31
|
end
|
29
32
|
|
@@ -43,3 +46,38 @@ class TestStatsdMetricExternal < MiniTest::Test
|
|
43
46
|
end
|
44
47
|
end
|
45
48
|
end
|
49
|
+
|
50
|
+
class TestDogstatsdMetricExternal < MiniTest::Test
|
51
|
+
include SensuPluginTestHelper
|
52
|
+
|
53
|
+
def setup
|
54
|
+
set_script 'external/dogstatsd-output'
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_dogstatsd
|
58
|
+
lines = run_script.split("\n")
|
59
|
+
assert lines.size == 2
|
60
|
+
assert lines.last.split('|').last.split(',').size == 2
|
61
|
+
lines.each do |line|
|
62
|
+
assert line.split('|').size >= 2
|
63
|
+
assert line.split('|').first.split(':').size == 2
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class TestInfluxdbMetricExternal < MiniTest::Test
|
69
|
+
include SensuPluginTestHelper
|
70
|
+
|
71
|
+
def setup
|
72
|
+
set_script 'external/influxdb-output'
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_dogstatsd
|
76
|
+
lines = run_script.split("\n")
|
77
|
+
assert lines.size == 3
|
78
|
+
lines.each do |line|
|
79
|
+
assert line.split("\s").size == 3
|
80
|
+
assert line.split("\s").first.split(',').size == 3
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Decklin Foster
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-08-
|
12
|
+
date: 2017-08-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|