Module: Fluent::Prometheus
Defined Under Namespace
Classes: AlreadyRegisteredError, Counter, Gauge, Histogram, Metric, Summary
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.parse_labels_elements(conf) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/fluent/plugin/prometheus.rb', line 8
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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/fluent/plugin/prometheus.rb', line 25
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::Prometheus::Summary.new(element, registry, labels)
when 'gauge'
metrics << Fluent::Prometheus::Gauge.new(element, registry, labels)
when 'counter'
metrics << Fluent::Prometheus::Counter.new(element, registry, labels)
when 'histogram'
metrics << Fluent::Prometheus::Histogram.new(element, registry, labels)
else
raise ConfigError, "type option must be 'counter', 'gauge', 'summary' or 'histogram'"
end
}
metrics
end
|
.placeholder_expander(log) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/fluent/plugin/prometheus.rb', line 46
def self.placeholder_expander(log)
if defined?(Fluent::Filter)
begin
require 'fluent/plugin/filter_record_transformer'
if defined?(Fluent::Plugin::RecordTransformerFilter::PlaceholderExpander)
return Fluent::Plugin::RecordTransformerFilter::PlaceholderExpander.new(log: log)
else
return Fluent::RecordTransformerFilter::PlaceholderExpander.new(log: log)
end
rescue LoadError => e
raise ConfigError, "cannot find filter_record_transformer plugin: #{e.message}"
end
else
begin
require 'fluent/plugin/out_record_reformer.rb'
return Fluent::RecordReformerOutput::PlaceholderExpander.new(log: log)
rescue LoadError => e
raise ConfigError, "cannot find fluent-plugin-record-reformer: #{e.message}"
end
end
end
|
Instance Method Details
71
72
73
74
75
|
# File 'lib/fluent/plugin/prometheus.rb', line 71
def configure(conf)
super
@placeholder_expander = Fluent::Prometheus.placeholder_expander(log)
@hostname = Socket.gethostname
end
|
#instrument(tag, es, metrics) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/fluent/plugin/prometheus.rb', line 77
def instrument(tag, es, metrics)
placeholder_values = {
'tag' => tag,
'hostname' => @hostname,
}
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
|