Class: LogStash::Outputs::Graphite
- Inherits:
-
Base
- Object
- Base
- LogStash::Outputs::Graphite
- Defined in:
- lib/logstash/outputs/graphite.rb
Overview
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: Some applications emit aggregated stats in the logs every 10 seconds. Using the grok filter and this output, it is possible to capture the metric values from the logs and emit them to Graphite.
Constant Summary collapse
- EXCLUDE_ALWAYS =
[ "@timestamp", "@version" ]
- DEFAULT_METRICS_FORMAT =
"*"- METRIC_PLACEHOLDER =
"*"
Instance Method Summary collapse
- #connect ⇒ Object
- #construct_metric_name(event, metric) ⇒ Object
- #receive(event) ⇒ Object
- #register ⇒ Object
Instance Method Details
#connect ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/logstash/outputs/graphite.rb', line 92 def connect # TODO(sissel): Test error cases. Catch exceptions. Find fortune and glory. Retire to yak farm. begin @socket = TCPSocket.new(@host, @port) rescue Errno::ECONNREFUSED => e @logger.warn("Connection refused to graphite server, sleeping...", :host => @host, :port => @port) sleep(@reconnect_interval) retry end end |
#construct_metric_name(event, metric) ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/logstash/outputs/graphite.rb', line 103 def construct_metric_name(event, metric) if @metrics_format sprinted = event.sprintf(@metrics_format) return sprinted.gsub(METRIC_PLACEHOLDER, metric) end metric end |
#receive(event) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/logstash/outputs/graphite.rb', line 112 def receive(event) # Graphite message format: metric value timestamp\n # compact to remove nil messages which produces useless \n = ( @fields_are_metrics \ ? (event, @include_metrics, @exclude_metrics) : (event, @metrics) ).compact if .empty? @logger.debug? && @logger.debug("Message is empty, not sending anything to Graphite", :messages => , :host => @host, :port => @port) else = .join("\n") @logger.debug? && @logger.debug("Sending carbon messages", :messages => , :host => @host, :port => @port) # Catch exceptions like ECONNRESET and friends, reconnect on failure. # TODO(sissel): Test error cases. Catch exceptions. Find fortune and glory. begin @socket.puts() rescue Errno::EPIPE, Errno::ECONNRESET, IOError => e @logger.warn("Connection to graphite server died", :exception => e, :host => @host, :port => @port) sleep(@reconnect_interval) connect retry if @resend_on_failure end end end |
#register ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/logstash/outputs/graphite.rb', line 79 def register @include_metrics.collect!{|regexp| Regexp.new(regexp)} @exclude_metrics.collect!{|regexp| Regexp.new(regexp)} if @metrics_format && !@metrics_format.include?(METRIC_PLACEHOLDER) @logger.warn("metrics_format does not include placeholder #{METRIC_PLACEHOLDER} .. falling back to default format: #{DEFAULT_METRICS_FORMAT.inspect}") @metrics_format = DEFAULT_METRICS_FORMAT end connect end |