Sha256: 67b1c365744749a7aed29adb8eea6a973b82bd11658adb5546f3c8cca700074f

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

#!/usr/bin/env ruby
#
# Copyright 2013 FunGo Studios (team@fungostudios.com)
#
# Depends on librato-metrics gem
# gem install librato-metrics
#
# 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 'librato/metrics'

class LibratoMetrics < Sensu::Handler
  # override filters from Sensu::Handler. not appropriate for metric handlers
  def filter
  end

  def handle
    source = settings['librato']['use_sensu_client_hostname_as_source'] ? @event['client']['name'] : nil
    queue = Librato::Metrics::Queue.new source: source
    @event['check']['output'].split("\n").each do |line|
      name, value, timestamp = line.split(/\s+/)
      queue.add name => { measure_time: timestamp.to_i, value: value.to_f }
    end

    Librato::Metrics.authenticate settings['librato']['email'], settings['librato']['api_key']

    begin
      timeout(3) do
        queue.submit
      end
    rescue Timeout::Error
      puts 'librato -- timed out while sending metrics'
    rescue => error
      puts "librato -- failed to send metrics : #{error.message}"
      puts "  #{error.backtrace.join("\n\t")}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sensu-plugins-librato-0.0.1 bin/handler-metrics-librato.rb