Module: Fluent::Plugin::Prometheus
- Included in:
- PrometheusFilter, PrometheusOutput
- Defined in:
- lib/fluent/plugin/prometheus.rb
Defined Under Namespace
Classes: AlreadyRegisteredError, Counter, Gauge, Histogram, Metric, Summary
Class Method Summary collapse
- .parse_labels_elements(conf) ⇒ Object
- .parse_metrics_elements(conf, registry, labels = {}) ⇒ Object
- .placeholder_expander(log) ⇒ Object
Instance Method Summary collapse
Class Method Details
.parse_labels_elements(conf) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/fluent/plugin/prometheus.rb', line 10 def self.parse_labels_elements(conf) labels = conf.elements.select { |e| e.name == 'labels' } if labels.size > 1 raise ConfigError, "labels section must have at most 1" end base_labels = {} unless labels.empty? labels.first.each do |key, value| labels.first.has_key?(key) base_labels[key.to_sym] = value end end base_labels end |
.parse_metrics_elements(conf, registry, labels = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fluent/plugin/prometheus.rb', line 27 def self.parse_metrics_elements(conf, registry, labels = {}) metrics = [] conf.elements.select { |element| element.name == 'metric' }.each { |element| case element['type'] when 'summary' metrics << Fluent::Plugin::Prometheus::Summary.new(element, registry, labels) when 'gauge' metrics << Fluent::Plugin::Prometheus::Gauge.new(element, registry, labels) when 'counter' metrics << Fluent::Plugin::Prometheus::Counter.new(element, registry, labels) when 'histogram' metrics << Fluent::Plugin::Prometheus::Histogram.new(element, registry, labels) else raise ConfigError, "type option must be 'counter', 'gauge', 'summary' or 'histogram'" end } metrics end |
Instance Method Details
#configure(conf) ⇒ Object
53 54 55 56 57 |
# File 'lib/fluent/plugin/prometheus.rb', line 53 def configure(conf) super @placeholder_expander = Fluent::Plugin::Prometheus.(log) @hostname = Socket.gethostname end |
#instrument(tag, es, metrics) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/fluent/plugin/prometheus.rb', line 59 def instrument(tag, es, metrics) placeholder_values = { 'tag' => tag, 'hostname' => @hostname, 'worker_id' => fluentd_worker_id, } es.each do |time, record| placeholders = record.merge(placeholder_values) placeholders = @placeholder_expander.prepare_placeholders(placeholders) metrics.each do |metric| begin metric.instrument(record, @placeholder_expander, placeholders) rescue => e log.warn "prometheus: failed to instrument a metric.", error_class: e.class, error: e, tag: tag, name: metric.name router.emit_error_event(tag, time, record, e) end end end end |