Class: Fluent::Prometheus::Histogram
- Defined in:
- lib/fluent/plugin/prometheus.rb
Instance Attribute Summary
Attributes inherited from Metric
Instance Method Summary collapse
-
#initialize(element, registry, labels) ⇒ Histogram
constructor
A new instance of Histogram.
- #instrument(record, expander, placeholders) ⇒ Object
Methods inherited from Metric
Constructor Details
#initialize(element, registry, labels) ⇒ Histogram
Returns a new instance of Histogram.
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/fluent/plugin/prometheus.rb', line 194 def initialize(element, registry, labels) super if @key.nil? raise ConfigError, "histogram metric requires 'key' option" end begin if element['buckets'] buckets = element['buckets'].split(/,/).map(&:strip).map do |e| e[/\A\d+.\d+\Z/] ? e.to_f : e.to_i end @histogram = registry.histogram(element['name'].to_sym, element['desc'], {}, buckets) else @histogram = registry.histogram(element['name'].to_sym, element['desc']) end rescue ::Prometheus::Client::Registry::AlreadyRegisteredError @histogram = Fluent::Prometheus::Metric.get(registry, element['name'].to_sym, :histogram, element['desc']) end end |
Instance Method Details
#instrument(record, expander, placeholders) ⇒ Object
214 215 216 217 218 |
# File 'lib/fluent/plugin/prometheus.rb', line 214 def instrument(record, , placeholders) if record[@key] @histogram.observe(labels(record, , placeholders), record[@key]) end end |