Class: LogStash::Outputs::MetricCatcher

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/outputs/metriccatcher.rb

Overview

This output ships metrics to MetricCatcher, allowing you to utilize Coda Hale’s Metrics.

More info on MetricCatcher: github.com/clearspring/MetricCatcher

At Clearspring, we use it to count the response codes from Apache logs:

metriccatcher {
    host => "localhost"
    port => "1420"
    type => "apache-access"
    fields => [ "response" ]
    meter => [ "%{host}.apache.response.%{response}", "1" ]
}

Constant Summary

Constants included from Config::Mixin

Config::Mixin::CONFIGSORT

Instance Attribute Summary

Attributes included from Config::Mixin

#config, #original_params

Attributes inherited from Plugin

#logger, #params

Instance Method Summary collapse

Methods inherited from Base

#handle, #handle_worker, #initialize, #worker_setup, #workers_not_supported

Methods included from Config::Mixin

#config_init, included

Methods inherited from Plugin

#eql?, #finished, #finished?, #hash, #initialize, #inspect, lookup, #reload, #running?, #shutdown, #teardown, #terminating?, #to_s

Constructor Details

This class inherits a constructor from LogStash::Outputs::Base

Instance Method Details

#receive(event) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/logstash/outputs/metriccatcher.rb', line 85

def receive(event)
  return unless output?(event)

  @@metric_types.each do |metric_type|
    if instance_variable_defined?("@#{metric_type}")
      instance_variable_get("@#{metric_type}").each do |metric_name, metric_value|
        message = [{
          "name"      => event.sprintf(metric_name),
          "type"      => event.sprintf(metric_type),
          "value"     => event.sprintf(metric_value).to_f,
          "timestamp" => event.sprintf("%{+%s}.") + Time.now.usec.to_s
        }]

        @socket.send(message.to_json, 0, @host, @port)
      end # instance_variable_get("@#{metric_type}").each_slice
    end # if
  end # @metric_types.each
end

#registerObject



80
81
82
# File 'lib/logstash/outputs/metriccatcher.rb', line 80

def register
  @socket = UDPSocket.new
end