Skip to content

Instantly share code, notes, and snippets.

@dnd
Created September 11, 2015 23:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dnd/0acda0bbeae530e24863 to your computer and use it in GitHub Desktop.
Save dnd/0acda0bbeae530e24863 to your computer and use it in GitHub Desktop.
Sensu InfluxDB 0.9 UDP Line Protocol
{
"handlers": {
"metrics": {
"type": "set",
"handlers": ["influxdb_udp"]
},
"influxdb_udp": {
"type": "udp",
"mutator": "influxdb_line_protocol",
"socket": {
"host": "mgt-monitor-db1",
"port": 8090
}
}
}
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