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].freeze
TAG_PLACEHOLDER =
'${tag}'

Instance Method Summary collapse

Constructor Details

#initialize ⇒ SplunkOutput

Returns a new instance of SplunkOutput.



74
75
76
77
# File 'lib/fluent/plugin/out_splunk.rb', line 74

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

Instance Method Details

#configure(conf) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/fluent/plugin/out_splunk.rb', line 79

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_api ⇒ Object



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

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

#write(chunk) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/fluent/plugin/out_splunk.rb', line 93

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(metric_labels, chunk.size_of_events)
  @metrics[:bytes_counter].increment(metric_labels, chunk.bytesize)
  @metrics[:write_records_histogram].observe(metric_labels, chunk.size_of_events)
  @metrics[:write_bytes_histogram].observe(metric_labels, chunk.bytesize)
  @metrics[:write_latency_histogram].observe(metric_labels, t)
end

#write_to_splunk(_chunk) ⇒ Object



107
108
109
# File 'lib/fluent/plugin/out_splunk.rb', line 107

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