sensu-extensions-influxdb 2.0.1 → 2.1.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 +5 -1
- data/README.md +29 -0
- data/lib/sensu/extensions/influxdb.rb +95 -51
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9b9d4e486f175a41c065e234e5257a8aafa5bc0
|
4
|
+
data.tar.gz: af0d09f36ab6f138dc2dd31f2d01c4532e35122e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4df67566cb2640965af7566f2ebe63f62c18dc978b5a9dce9c54c9f6e5f1348946a14c261fd7b83210f16c8d7a16aae2a8c48095b36263115394307ebb9840c6
|
7
|
+
data.tar.gz: cad7f8bbbf41fdcd2c2ca78169185412904f3b2da043f8d68eabae341728ff54c387a7ddbb5760c6ce4296d93c9cac103f7ad5f1bcd8295ea30c00c1d3b7dee0
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -175,6 +175,35 @@ measurement = app.downloads, tags = platform => iOS;device => iPad , value = 92,
|
|
175
175
|
|
176
176
|
The event output tags will be merged with client and check definition tags and sent to InfluxDB as usual.
|
177
177
|
|
178
|
+
# Multiple handlers
|
179
|
+
|
180
|
+
If you need to have multiple handlers, eg. for different precision, proxy mode, writing to different influx databases, this can be done by configuring **additional_handlers**:
|
181
|
+
|
182
|
+
```
|
183
|
+
{
|
184
|
+
"influxdb-extension": {
|
185
|
+
"hostname": "influxdb",
|
186
|
+
"port": 8086,
|
187
|
+
"database": "metrics",
|
188
|
+
"username": "sensu",
|
189
|
+
"password": "sensu",
|
190
|
+
"buffer_size": 1000,
|
191
|
+
"buffer_max_age": 10,
|
192
|
+
"additional_handlers": ["events", "events_nano"]
|
193
|
+
},
|
194
|
+
"events": {
|
195
|
+
"proxy_mode": true,
|
196
|
+
"precision": "s"
|
197
|
+
},
|
198
|
+
"events_nano": {
|
199
|
+
"proxy_mode": true,
|
200
|
+
"precision": "n"
|
201
|
+
}
|
202
|
+
}
|
203
|
+
```
|
204
|
+
|
205
|
+
Settings for the additional handlers will be merged with the **influxdb-extension** settings, so you only need to specify the settings you want to change for that handler.
|
206
|
+
|
178
207
|
# Performance
|
179
208
|
|
180
209
|
The extension will buffer up points until it reaches the configured **buffer_size** length or **buffer_max_age**, and then post all the points in the buffer to InfluxDB.
|
@@ -18,60 +18,104 @@ module Sensu::Extension
|
|
18
18
|
"Transforms and sends metrics to InfluxDB"
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
21
|
+
@@default_config = {
|
22
|
+
:hostname => "127.0.0.1",
|
23
|
+
:port => "8086",
|
24
|
+
:ssl => false,
|
25
|
+
:precision => "s",
|
26
|
+
:protocol => "http",
|
27
|
+
:buffer_size => 100,
|
28
|
+
:buffer_max_age => 10,
|
29
|
+
:proxy_mode => false
|
30
|
+
}
|
31
|
+
|
32
|
+
def create_config(name, defaults)
|
33
|
+
if settings[name].nil?
|
34
|
+
Raise ArgumentError "no configuration for #{name} provided. exiting..."
|
35
|
+
end
|
36
|
+
config = defaults.merge(settings[name])
|
37
|
+
@logger.debug("Config for #{name} created: #{config}")
|
38
|
+
validate_config(name, config)
|
39
|
+
|
40
|
+
hostname = config[:hostname]
|
41
|
+
port = config[:port]
|
42
|
+
database = config[:database]
|
43
|
+
ssl = config[:ssl]
|
44
|
+
ssl_ca_file = config[:ssl_ca_file]
|
45
|
+
ssl_verify = if config.key?(:ssl_verify) then config[:ssl_verify] else true end
|
46
|
+
precision = config[:precision]
|
47
|
+
retention_policy = config[:retention_policy]
|
33
48
|
rp_queryparam = if retention_policy.nil? then "" else "&rp=#{retention_policy}" end
|
34
49
|
protocol = if ssl then "https" else "http" end
|
35
|
-
username =
|
36
|
-
password =
|
50
|
+
username = config[:username]
|
51
|
+
password = config[:password]
|
37
52
|
auth_queryparam = if username.nil? or password.nil? then "" else "&u=#{username}&p=#{password}" end
|
38
|
-
|
39
|
-
|
40
|
-
|
53
|
+
buffer_size = config[:buffer_size]
|
54
|
+
buffer_max_age = config[:buffer_max_age]
|
55
|
+
proxy_mode = config[:proxy_mode]
|
41
56
|
|
42
57
|
string = "#{protocol}://#{hostname}:#{port}/write?db=#{database}&precision=#{precision}#{rp_queryparam}#{auth_queryparam}"
|
43
|
-
|
44
|
-
|
58
|
+
uri = URI(string)
|
59
|
+
http = Net::HTTP::new(uri.host, uri.port)
|
45
60
|
if ssl
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
61
|
+
http.ssl_version = :TLSv1
|
62
|
+
http.use_ssl = true
|
63
|
+
http.verify_mode = if ssl_verify then OpenSSL::SSL::VERIFY_PEER else OpenSSL::SSL::VERIFY_NONE end
|
64
|
+
http.ca_file = ssl_ca_file
|
50
65
|
end
|
51
|
-
@buffer = []
|
52
|
-
@buffer_flushed = Time.now.to_i
|
53
66
|
|
54
|
-
@
|
67
|
+
@handlers ||= Hash.new
|
68
|
+
@handlers[name] = {
|
69
|
+
"http" => http,
|
70
|
+
"uri" => uri,
|
71
|
+
"buffer" => [],
|
72
|
+
"buffer_flushed" => Time.now.to_i,
|
73
|
+
"buffer_size" => buffer_size,
|
74
|
+
"buffer_max_age" => buffer_max_age,
|
75
|
+
"proxy_mode" => proxy_mode
|
76
|
+
}
|
77
|
+
|
78
|
+
@logger.info("#{name}: successfully initialized handler: hostname: #{hostname}, port: #{port}, database: #{database}, uri: #{uri.to_s}, username: #{username}, buffer_size: #{buffer_size}, buffer_max_age: #{buffer_max_age}")
|
79
|
+
return config
|
80
|
+
end
|
81
|
+
|
82
|
+
def post_init
|
83
|
+
main_config = create_config(@@extension_name, @@default_config)
|
84
|
+
if settings[name].key?(:additional_handlers)
|
85
|
+
settings[name][:additional_handlers].each {|h| create_config(h, main_config)}
|
86
|
+
end
|
55
87
|
end
|
56
88
|
|
57
89
|
def run(event)
|
58
90
|
begin
|
91
|
+
@logger.debug("event: #{event}")
|
92
|
+
event = JSON.parse(event)
|
59
93
|
|
60
|
-
|
61
|
-
|
94
|
+
handler = @handlers[@@extension_name]
|
95
|
+
unless event["check"]["handlers"].nil?
|
96
|
+
event["check"]["handlers"].each {|x|
|
97
|
+
if @handlers.has_key?(x)
|
98
|
+
@logger.debug("found additional handler: #{x}")
|
99
|
+
handler = @handlers[x]
|
100
|
+
break
|
101
|
+
end
|
102
|
+
}
|
103
|
+
end
|
104
|
+
|
105
|
+
if buffer_too_old?(handler) or buffer_too_big?(handler)
|
106
|
+
flush_buffer(handler)
|
62
107
|
end
|
63
108
|
|
64
|
-
event = JSON.parse(event)
|
65
109
|
output = event["check"]["output"]
|
66
110
|
|
67
|
-
if not
|
111
|
+
if not handler["proxy_mode"]
|
68
112
|
client_tags = event["client"]["tags"] || Hash.new
|
69
113
|
check_tags = event["check"]["tags"] || Hash.new
|
70
114
|
tags = create_tags(client_tags.merge(check_tags))
|
71
115
|
end
|
72
116
|
|
73
117
|
output.split(/\r\n|\n/).each do |point|
|
74
|
-
if not
|
118
|
+
if not handler["proxy_mode"]
|
75
119
|
measurement, field_value, timestamp = point.split(/\s+/)
|
76
120
|
|
77
121
|
if not is_number?(timestamp)
|
@@ -93,8 +137,8 @@ module Sensu::Extension
|
|
93
137
|
point = "#{measurement}#{tags} value=#{field_value} #{timestamp}"
|
94
138
|
end
|
95
139
|
|
96
|
-
|
97
|
-
@logger.debug("#{@@extension_name}: stored point in buffer (#{
|
140
|
+
handler["buffer"].push(point)
|
141
|
+
@logger.debug("#{@@extension_name}: stored point in buffer (#{handler['buffer'].length}/#{handler['buffer_size']})")
|
98
142
|
end
|
99
143
|
yield 'ok', 0
|
100
144
|
rescue => e
|
@@ -123,39 +167,39 @@ module Sensu::Extension
|
|
123
167
|
end
|
124
168
|
end
|
125
169
|
|
126
|
-
def send_to_influxdb(
|
127
|
-
|
170
|
+
def send_to_influxdb(handler)
|
171
|
+
payload = handler["buffer"].join("\n")
|
172
|
+
request = Net::HTTP::Post.new(handler['uri'].request_uri)
|
128
173
|
request.body = payload
|
129
174
|
|
130
|
-
@logger.debug("#{@@extension_name}: writing payload #{payload} to endpoint #{
|
131
|
-
response =
|
175
|
+
@logger.debug("#{@@extension_name}: writing payload #{payload} to endpoint #{handler['uri'].to_s}")
|
176
|
+
response = handler["http"].request(request)
|
132
177
|
@logger.debug("#{@@extension_name}: influxdb http response code = #{response.code}, body = #{response.body}")
|
133
178
|
end
|
134
179
|
|
135
|
-
def flush_buffer
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
@buffer_flushed = Time.now.to_i
|
180
|
+
def flush_buffer(handler)
|
181
|
+
send_to_influxdb(handler)
|
182
|
+
handler["buffer"] = []
|
183
|
+
handler["buffer_flushed"] = Time.now.to_i
|
140
184
|
end
|
141
185
|
|
142
|
-
def buffer_too_old?
|
143
|
-
buffer_age = Time.now.to_i -
|
144
|
-
buffer_age >=
|
186
|
+
def buffer_too_old?(handler)
|
187
|
+
buffer_age = Time.now.to_i - handler["buffer_flushed"]
|
188
|
+
buffer_age >= handler["buffer_max_age"]
|
145
189
|
end
|
146
190
|
|
147
|
-
def buffer_too_big?
|
148
|
-
|
191
|
+
def buffer_too_big?(handler)
|
192
|
+
handler["buffer"].length >= handler["buffer_size"]
|
149
193
|
end
|
150
194
|
|
151
|
-
def validate_config(config)
|
195
|
+
def validate_config(name, config)
|
152
196
|
if config.nil?
|
153
|
-
raise ArgumentError, "no configuration for #{
|
197
|
+
raise ArgumentError, "no configuration for #{name} provided. exiting..."
|
154
198
|
end
|
155
199
|
|
156
200
|
["hostname", "database"].each do |required_setting|
|
157
|
-
if config
|
158
|
-
raise ArgumentError, "required setting #{required_setting} not provided to extension. this should be provided as json element with key #{
|
201
|
+
if config.has_key?(required_setting)
|
202
|
+
raise ArgumentError, "required setting #{required_setting} not provided to extension. this should be provided as json element with key #{name}. exiting..."
|
159
203
|
end
|
160
204
|
end
|
161
205
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-extensions-influxdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johnny Horvi
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-05-
|
12
|
+
date: 2017-05-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sensu-extension
|
@@ -108,7 +108,8 @@ files:
|
|
108
108
|
- README.md
|
109
109
|
- CHANGELOG.md
|
110
110
|
homepage: https://github.com/jhrv/sensu-influxdb-extension
|
111
|
-
licenses:
|
111
|
+
licenses:
|
112
|
+
- MIT
|
112
113
|
metadata: {}
|
113
114
|
post_install_message:
|
114
115
|
rdoc_options: []
|