Class: Fluent::Plugin::SplunkOutput

Inherits:
Output
  • 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.



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

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

Instance Method Details

#configure(conf) ⇒ Object



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

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



117
118
119
# File 'lib/fluent/plugin/out_splunk.rb', line 117

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

#shutdownObject



95
96
97
# File 'lib/fluent/plugin/out_splunk.rb', line 95

def shutdown
  super
end

#write(chunk) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/fluent/plugin/out_splunk.rb', line 99

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)
  @metrics[:bytes_counter].increment(labels: metric_labels, by: chunk.bytesize)
  @metrics[:write_records_histogram].observe(chunk.size, 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



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

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