- add metrics to file output

This commit is contained in:
Jordan Sissel 2012-02-08 12:03:48 -08:00
parent 47c4eff6bf
commit 30818a7a91

View file

@ -46,6 +46,9 @@ class LogStash::Outputs::File < LogStash::Outputs::Base
@last_stale_cleanup_cycle = now
flush_interval = @flush_interval.to_i
@stale_cleanup_interval = 10
@metric_flushes = @logger.metrics.timer(self, "flushes")
@metric_write_delay = @logger.metrics.timer(self, "write-delay")
@metric_write_bytes = @logger.metrics.histogram(self, "write-bytes")
end # def register
public
@ -58,10 +61,16 @@ class LogStash::Outputs::File < LogStash::Outputs::Base
# TODO(sissel): Check if we should rotate the file.
if @message_format
fd.write(event.sprintf(@message_format) + "\n")
output = event.sprintf(@message_format) + "\n"
else
fd.write(event.to_json + "\n")
output = event.to_json
end
@metric_write_delay.time do
fd.puts(output)
end
@metric_write_bytes.record(output.size)
flush(fd)
close_stale_files
end # def receive
@ -84,7 +93,9 @@ class LogStash::Outputs::File < LogStash::Outputs::Base
if flush_interval > 0
flush_pending_files
else
fd.flush
@metric_flushes.time do
fd.flush
end
end
end
@ -94,7 +105,9 @@ class LogStash::Outputs::File < LogStash::Outputs::Base
@logger.debug("Starting flush cycle")
@files.each do |path, fd|
@logger.debug("Flushing file", :path => path, :fd => fd)
fd.flush
@metric_flushes.time do
fd.flush
end
end
@last_flush_cycle = Time.now
end