Class: Fluent::Plugin::PrometheusOutputMetric
- Inherits:
-
Output
- Object
- Output
- Fluent::Plugin::PrometheusOutputMetric
- Includes:
- PrometheusLabelParser
- Defined in:
- lib/fluent/plugin/out_prometheus_metric.rb
Instance Method Summary collapse
- #configure(conf) ⇒ Object
-
#initialize ⇒ PrometheusOutputMetric
constructor
A new instance of PrometheusOutputMetric.
- #labels(labels, record, expander) ⇒ Object
- #multi_workers_ready? ⇒ Boolean
- #process(tag, es) ⇒ Object
Methods included from PrometheusLabelParser
Constructor Details
#initialize ⇒ PrometheusOutputMetric
Returns a new instance of PrometheusOutputMetric.
9 10 11 12 |
# File 'lib/fluent/plugin/out_prometheus_metric.rb', line 9 def initialize super @registry = ::Prometheus::Client.registry end |
Instance Method Details
#configure(conf) ⇒ Object
32 33 34 35 36 |
# File 'lib/fluent/plugin/out_prometheus_metric.rb', line 32 def configure(conf) super @labels = parse_labels_elements(conf) = Fluent::Plugin::Prometheus.(log) end |
#labels(labels, record, expander) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/fluent/plugin/out_prometheus_metric.rb', line 20 def labels(labels, record, ) label = {} labels.each do |k, v| if v.is_a?(String) label[k] = .(v) else label[k] = v.call(record) end end label end |
#multi_workers_ready? ⇒ Boolean
14 15 16 |
# File 'lib/fluent/plugin/out_prometheus_metric.rb', line 14 def multi_workers_ready? true end |
#process(tag, es) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/fluent/plugin/out_prometheus_metric.rb', line 38 def process(tag, es) placeholder_values = { 'tag' => tag, 'worker_id' => fluentd_worker_id, } = .build(placeholder_values) # Write out values in event stream to Registry es.each do |time, record| # Create metric if not exists begin desc = "fluentd message stream with tag: ${tag}" gauge = @registry.gauge(tag.to_sym, desc.sub!("${tag}", tag)) rescue ::Prometheus::Client::Registry::AlreadyRegisteredError gauge = @registry.get(tag.to_sym) end if @key.is_a?(String) value = record[@key] else value = @key.call(record) end if value gauge.set(labels(@labels, record, ), value) end end end |