Class: Fluent::Plugin::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.
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/fluent/plugin/prometheus.rb', line 219 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::Plugin::Prometheus::Metric.get(registry, element['name'].to_sym, :histogram, element['desc']) end end |
Instance Method Details
#instrument(record, expander, placeholders) ⇒ Object
239 240 241 242 243 244 245 246 247 248 |
# File 'lib/fluent/plugin/prometheus.rb', line 239 def instrument(record, , placeholders) if @key.is_a?(String) value = record[@key] else value = @key.call(record) end if value @histogram.observe(labels(record, , placeholders), value) end end |