Class: Monitoring::PrometheusMonitoringRegistry

Inherits:
BaseMonitoringRegistry show all
Defined in:
lib/fluent/plugin/monitoring.rb

Overview

Prometheus implementation of the monitoring registry, that uses the default registry in the official Prometheus client library.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseMonitoringRegistry

#export

Constructor Details

#initialize(_project_id, _monitored_resource, _gcm_service_address) ⇒ PrometheusMonitoringRegistry

Returns a new instance of PrometheusMonitoringRegistry.



71
72
73
74
75
# File 'lib/fluent/plugin/monitoring.rb', line 71

def initialize(_project_id, _monitored_resource, _gcm_service_address)
  super
  require 'prometheus/client'
  @registry = Prometheus::Client.registry
end

Class Method Details

.nameObject



67
68
69
# File 'lib/fluent/plugin/monitoring.rb', line 67

def self.name
  'prometheus'
end

Instance Method Details

#counter(name, _labels, docstring) ⇒ Object

Exception-driven behavior to avoid synchronization errors.



78
79
80
81
82
83
84
85
86
# File 'lib/fluent/plugin/monitoring.rb', line 78

def counter(name, _labels, docstring)
  # When we upgrade to Prometheus client 0.10.0 or higher, pass the
  # labels in the metric constructor. The 'labels' field in
  # Prometheus client 0.9.0 has a different function and will not
  # work as intended.
  return PrometheusCounter.new(@registry.counter(name, docstring))
rescue Prometheus::Client::Registry::AlreadyRegisteredError
  return PrometheusCounter.new(@registry.get(name))
end