Class: LogStash::Codecs::Graphite
- Defined in:
- lib/logstash/codecs/graphite.rb
Overview
This codec will encode and decode Graphite formated lines.
Constant Summary collapse
- EXCLUDE_ALWAYS =
[ "@timestamp", "@version" ]
- DEFAULT_METRICS_FORMAT =
"*"
- METRIC_PLACEHOLDER =
"*"
Constants included from LogStash::Config::Mixin
LogStash::Config::Mixin::CONFIGSORT
Instance Attribute Summary
Attributes included from LogStash::Config::Mixin
Attributes inherited from Plugin
Instance Method Summary collapse
- #decode(data) ⇒ Object
- #encode(event) ⇒ Object
-
#initialize(params = {}) ⇒ Graphite
constructor
A new instance of Graphite.
Methods inherited from Base
#clone, #flush, #on_event, #teardown
Methods included from LogStash::Config::Mixin
Methods inherited from Plugin
#eql?, #finished, #finished?, #hash, #inspect, lookup, #reload, #running?, #shutdown, #teardown, #terminating?, #to_s
Constructor Details
Instance Method Details
#decode(data) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/logstash/codecs/graphite.rb', line 63 def decode(data) @lines.decode(data) do |event| name, value, time = event["message"].split(" ") yield LogStash::Event.new(name => value.to_f, "@timestamp" => Time.at(time.to_i).gmtime) end # @lines.decode end |
#encode(event) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/logstash/codecs/graphite.rb', line 80 def encode(event) # Graphite message format: metric value timestamp\n = [] = event.sprintf("%{+%s}") if @fields_are_metrics @logger.debug("got metrics event", :metrics => event.to_hash) event.to_hash.each do |metric,value| next if EXCLUDE_ALWAYS.include?(metric) next unless @include_metrics.empty? || @include_metrics.any? { |regexp| metric.match(regexp) } next if @exclude_metrics.any? {|regexp| metric.match(regexp)} << "#{construct_metric_name(metric)} #{event.sprintf(value.to_s).to_f} #{}" end # data.to_hash.each else @metrics.each do |metric, value| @logger.debug("processing", :metric => metric, :value => value) metric = event.sprintf(metric) next unless @include_metrics.any? {|regexp| metric.match(regexp)} next if @exclude_metrics.any? {|regexp| metric.match(regexp)} << "#{construct_metric_name(event.sprintf(metric))} #{event.sprintf(value).to_f} #{}" end # @metrics.each end # if @fields_are_metrics if .empty? @logger.debug("Message is empty, not emiting anything.", :messages => ) else = .join("\n") + "\n" @logger.debug("Emiting carbon messages", :messages => ) @on_event.call() end # if messages.empty? end |