Created
September 3, 2015 16:37
-
-
Save jamtur01/ae24ae83a5ac6ac85361 to your computer and use it in GitHub Desktop.
Riemann metrics handler for Sensu
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
{ | |
"riemann" : { | |
"riemann_host" : "localhost", | |
"port" : 5555 | |
} | |
} |
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
#!/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