<commit_before>#!/usr/bin/env ruby
#
# Copyright 2013 <NAME> (<EMAIL>)
#
# 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
    queue = Librato::Metrics::Queue.new
    @event['check']['output'].split("\n").each do |line|
      name, value, timestamp = line.split("\t")
      queue.add name => {:measure_time => timestamp.to_i, :value => value.to_i}
    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<commit_msg>FIX: allow any space character to be used as a separator in the metric's output<commit_after>#!/usr/bin/env ruby
#
# Copyright 2013 <NAME> (<EMAIL>)
#
# 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
    queue = Librato::Metrics::Queue.new
    @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_i}
    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
{'fraction_non_alphanumeric': 0.1357444809769845, 'fraction_numerical': 0.007515265382808831, 'mean_word_length': 3.409937888198758, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5306505', 'n_tokens_mistral': 693, 'n_tokens_neox': 670, 'n_words': 195}