Created
September 11, 2015 23:19
-
-
Save dnd/0acda0bbeae530e24863 to your computer and use it in GitHub Desktop.
Sensu InfluxDB 0.9 UDP Line Protocol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"handlers": { | |
"metrics": { | |
"type": "set", | |
"handlers": ["influxdb_udp"] | |
}, | |
"influxdb_udp": { | |
"type": "udp", | |
"mutator": "influxdb_line_protocol", | |
"socket": { | |
"host": "mgt-monitor-db1", | |
"port": 8090 | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "sensu/extension" | |
module Sensu | |
module Extension | |
class InfluxDBLineProtocol < Mutator | |
def name | |
"influxdb_line_protocol" | |
end | |
def description | |
"returns check output formatted for InfluxDB's line protocol" | |
end | |
def run(event) | |
host = event[:client][:name] | |
metric = event[:check][:name] | |
output = event[:check][:output] | |
data = [] | |
output.split("\n").each do |result| | |
m = result.split | |
next unless m.count == 3 | |
key = m[0].split('.', 2)[1] | |
key.gsub!('.', '_') | |
value = m[1].to_f | |
time = m[2].ljust(19, '0') | |
data << "#{key},host=#{host},metric=#{metric} value=#{value} #{time}" | |
end | |
yield data.join("\n"), 0 | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment