Skip to content

Instantly share code, notes, and snippets.

@jamtur01
Created September 3, 2015 16:37
Show Gist options
  • Save jamtur01/ae24ae83a5ac6ac85361 to your computer and use it in GitHub Desktop.
Save jamtur01/ae24ae83a5ac6ac85361 to your computer and use it in GitHub Desktop.
Riemann metrics handler for Sensu
{
"riemann" : {
"riemann_host" : "localhost",
"port" : 5555
}
}
#!/usr/bin/env ruby
#
# Riemann handler
#
# This handler sends metrics to a Riemann server via
# TCP socket.
#
# This takes graphite-like metrics (sensu's default) and
# sends them to a Riemann server. It connects to Riemann via
# the Riemann Ruby client: https://github.com/aphyr/riemann-ruby-client.
#
# Riemann 'riemann_host', 'riemann_port' must be
# specified in a config file in /etc/sensu/conf.d.
# See riemann.json for an example.
#
# Author: James Turnbull <[email protected]>
#
# Released under the same terms as Sensu (the MIT license); see LICENSE
# for details.
#
require 'rubygems' if RUBY_VERSION < '1.9.0'
require 'sensu-handler'
require 'riemann/client'
class Riemann < Sensu::Handler
# override filters from Sensu::Handler. not appropriate for metric handlers
def filter; end
def handle
riemann_host = settings['riemann']['riemann_host']
riemann_port = settings['riemann']['riemann_port']
metrics = @event['check']['output']
check_name = @event['check']['name']
client_name = @event['client']['name']
client = Riemann::Client.new host: riemann_host, port: riemann_port, timeout: 5
begin
metrics.split("\n").each do |output_line|
(metric_name, metric_value, epoch_time) = output_line.split("\t")
client << {
host: client_name,
service: check_name,
tags: ["sensu"],
time: epoch_time,
description: metric_name,
metric: metric_value
}
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment