forked from elastic/logstash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add '%{+%s}' to event sprintf so you can get the unix epoch.
(Joda's DateTime doesn't support it otherwise from date formatting) - Add graphite output. Still needs fault tolerance added, though. https://logstash.jira.com/browse/LOGSTASH-126
- Loading branch information
1 parent
9c07293
commit 197b1c6
Showing
2 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require "logstash/outputs/base" | ||
require "logstash/namespace" | ||
require "socket" | ||
|
||
# This output allows you to pull metrics from your logs and ship them to | ||
# graphite. Graphite is an open source tool for storing and graphing metrics. | ||
# | ||
# An example use case: At loggly, some of our applications emit aggregated | ||
# stats in the logs every 10 seconds. Using the grok filter and this output, | ||
# I can capture the metric values from the logs and emit them to graphite. | ||
# | ||
# TODO(sissel): Figure out how to manage multiple metrics coming from the same | ||
# event. | ||
class LogStash::Outputs::Graphite < LogStash::Outputs::Base | ||
config_name "graphite" | ||
|
||
# The address of the graphite server. | ||
config :host, :validate => :string, :default => "localhost" | ||
|
||
# The port to connect on your graphite server. | ||
config :port, :validate => :number, :default => 2003 | ||
|
||
# The metric to use. This supports dynamic strings like %{@source_host} | ||
# TODO(sissel): This should probably be an array. | ||
config :metric, :validate => :string, :required => true | ||
|
||
# The value to use. This supports dynamic strings like %{bytes} | ||
# It will be coerced to a floating point value. Values which cannot be | ||
# coerced will zero (0) | ||
config :value, :validate => :string, :required => true | ||
|
||
def register | ||
# TODO(sissel): Retry on failure. | ||
@socket = connect | ||
end # def register | ||
|
||
def connect | ||
# TODO(sissel): Test error cases. Catch exceptions. Find fortune and glory. | ||
socket = TCPSocket.new(@host, @port) | ||
end # def connect | ||
|
||
public | ||
def receive(event) | ||
# Graphite message format: metric value timestamp\n | ||
message = [event.sprintf(@metric), event.sprintf(@value).to_f, | ||
event.sprintf("%{+%s}")].join(" ") | ||
# TODO(sissel): Test error cases. Catch exceptions. Find fortune and glory. | ||
@socket.puts(message) | ||
|
||
# TODO(sissel): retry on failure TODO(sissel): Make 'retry on failure' | ||
# tunable; sometimes it's OK to drop metrics. | ||
end # def receive | ||
end # class LogStash::Outputs::Statsd |