lib/logstash_writer.rb in logstash_writer-0.0.1 vs lib/logstash_writer.rb in logstash_writer-0.0.2
- old
+ new
@@ -77,11 +77,11 @@
received: metrics_registry.counter(:"#{metrics_prefix}_events_received_total", "The number of logstash events which have been submitted for delivery"),
sent: metrics_registry.counter(:"#{metrics_prefix}_events_written_total", "The number of logstash events which have been delivered to the logstash server"),
queue_size: metrics_registry.gauge(:"#{metrics_prefix}_queue_size", "The number of events currently in the queue to be sent"),
dropped: metrics_registry.counter(:"#{metrics_prefix}_events_dropped_total", "The number of events which have been dropped from the queue"),
- lag: metrics_registry.gauge(:"#{metrics_prefix}_last_sent_event_timestamp", "When the last event successfully sent to logstash was originally received"),
+ lag: metrics_registry.gauge(:"#{metrics_prefix}_last_sent_event_time_seconds", "When the last event successfully sent to logstash was originally received"),
connected: metrics_registry.gauge(:"#{metrics_prefix}_connected_to_server", "Boolean flag indicating whether we are currently connected to a logstash server"),
connect_exception: metrics_registry.counter(:"#{metrics_prefix}_connect_exceptions_total", "The number of exceptions that have occurred whilst attempting to connect to a logstash server"),
write_exception: metrics_registry.counter(:"#{metrics_prefix}_write_exceptions_total", "The number of exceptions that have occurred whilst attempting to write an event to a logstash server"),
@@ -113,11 +113,11 @@
unless e.is_a?(Hash)
raise ArgumentError, "Event must be a hash"
end
unless e.has_key?(:@timestamp) || e.has_key?("@timestamp")
- e[:@timestamp] = Time.now.utc.strftime("%FT%TZ")
+ e[:@timestamp] = Time.now.utc.strftime("%FT%T.%NZ")
end
unless e.has_key?(:_id) || e.has_key?("_id")
# This is the quickest way I've found to get a long, random string.
# We don't need any sort of cryptographic or unpredictability
@@ -241,9 +241,15 @@
@metrics[:write_loop_ok].set({}, 1)
error_wait = INITIAL_RETRY_WAIT
end
rescue StandardError => ex
@logger.error("LogstashWriter") { (["Exception in write_loop: #{ex.message} (#{ex.class})"] + ex.backtrace).join("\n ") }
+ # If there was some sort of error, there's a non-trivial chance the
+ # socket has gone *boom*, so let's invalidate it and go around again
+ if @current_socket
+ @current_socket.close
+ @current_socket = nil
+ end
@queue_mutex.synchronize { @queue.unshift(event) if event }
@metrics[:write_loop_exception].increment(class: ex.class.to_s)
@metrics[:write_loop_ok].set({}, 0)
sleep error_wait
# Increase the error wait timeout for next time, up to a maximum