Skip to content

Commit

Permalink
Support for millisecond resolution timestamps
Browse files Browse the repository at this point in the history
Add use_millis configuration option boolean which is used to set the timestamp format
  • Loading branch information
drewdogg committed Sep 7, 2016
1 parent c2941f5 commit ec019b4
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/logstash/outputs/opentsdb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,18 @@ class LogStash::Outputs::Opentsdb < LogStash::Outputs::Base
# coerced will zero (0)
config :metrics, :validate => :array, :required => true

# Use millisecond resolution for timestamp (supported by OpenTSDB version >=2.0).
# See http://opentsdb.net/docs/build/html/user_guide/writing.html#timestamps
config :use_millis, :validate => :boolean, :default => false

def register
if use_millis
# concatenate seconds and milliseconds into 13-digit timestamp
@time_format = "%{+%s}%{+SSS}"
else
@time_format = "%{+%s}"
end

connect
end # def register

Expand Down Expand Up @@ -63,7 +74,7 @@ def receive(event)
# The first part of the message
message = ['put',
event.sprintf(name),
event.sprintf("%{+%s}"),
event.sprintf(@time_format),
event.sprintf(value),
].join(" ")

Expand All @@ -81,6 +92,7 @@ def receive(event)

# TODO(sissel): Test error cases. Catch exceptions. Find fortune and glory.
begin
@logger.debug("Write message to opentsdb", :msg => message)
@socket.puts(message)
rescue Errno::EPIPE, Errno::ECONNRESET => e
@logger.warn("Connection to opentsdb server died",
Expand Down

0 comments on commit ec019b4

Please sign in to comment.