Sha256: 7cb99150b38dd56ed74a244904b21238eab50d64d76ea8103789049dfdf9adc1

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

#!/usr/bin/env ruby
#
# Copyright 2011 Sonian, Inc <chefs@sonian.net>
#
# Released under the same terms as Sensu (the MIT license); see LICENSE
# for details.

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
    hostname = @event['client']['name'].split('.').first
    # #YELLOW
    check_name = @event['check']['name'].gsub(%r{[ \.]}, '_')
    metric = "sensu.events.#{hostname}.#{check_name}.occurrences"
    value = @event['action'] == 'create' ? @event['occurrences'] : 0

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

    begin
      timeout(3) do
        Librato::Metrics.submit metric.to_sym => { type: :counter, value: value, source: 'sensu' }
      end
    rescue Timeout::Error
      puts "librato -- timed out while sending metric #{metric}"
    rescue => error
      puts "librato -- failed to send metric #{metric} : #{error}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sensu-plugins-librato-1.0.0 bin/handler-librato-occurrences.rb