Class: Fluent::Plugin::SplunkOutput

Inherits:
BufferedOutput
  • Object
show all
Defined in:
lib/fluent/plugin/out_splunk.rb

Direct Known Subclasses

SplunkHecOutput, SplunkIngestApiOutput

Constant Summary collapse

KEY_FIELDS =
%w[index host source sourcetype metric_name metric_value time].freeze
TAG_PLACEHOLDER =
'${tag}'

Instance Method Summary collapse

Constructor Details

#initializeSplunkOutput

Returns a new instance of SplunkOutput.



77
78
79
80
# File 'lib/fluent/plugin/out_splunk.rb', line 77

def initialize
  super
  @registry = ::Prometheus::Client.registry
end

Instance Method Details

#configure(conf) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/fluent/plugin/out_splunk.rb', line 82

def configure(conf)
  super
  check_conflict
  @api = construct_api
  prepare_key_fields
  configure_fields(conf)
  configure_metrics(conf)

  # @formatter_configs is from formatter helper
  @formatters = @formatter_configs.map do |section|
    MatchFormatter.new section.usage, formatter_create(usage: section.usage)
  end
end

#construct_apiObject



114
115
116
# File 'lib/fluent/plugin/out_splunk.rb', line 114

def construct_api
  raise NotImplementedError("Child class should implement 'construct_api'")
end

#write(chunk) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/fluent/plugin/out_splunk.rb', line 96

def write(chunk)
  log.trace { "#{self.class}: Received new chunk, size=#{chunk.read.bytesize}" }

  t = Benchmark.realtime do
    write_to_splunk(chunk)
  end

  @metrics[:record_counter].increment(labels: metric_labels, by: chunk.size_of_events)
  @metrics[:bytes_counter].increment(labels: metric_labels, by: chunk.bytesize)
  @metrics[:write_records_histogram].observe(chunk.size_of_events, labels: metric_labels)
  @metrics[:write_bytes_histogram].observe(chunk.bytesize, labels: metric_labels, )
  @metrics[:write_latency_histogram].observe(t, labels: metric_labels, )
end

#write_to_splunk(_chunk) ⇒ Object



110
111
112
# File 'lib/fluent/plugin/out_splunk.rb', line 110

def write_to_splunk(_chunk)
  raise NotImplementedError("Child class should implement 'write_to_splunk'")
end