module Invoca::Metrics::Prometheus

Public Class Methods

config() click to toggle source

Accessor for the existing Prometheus configuration

@raise [Invoca::Metrics::Prometheus::NotConfiguredError] @return [Invoca::Metrics::Prometheus::Configuration]

# File lib/invoca/metrics/prometheus.rb, line 44
def config
  @config or raise NotConfiguredError, 'Invoca::Metrics::Prometheus is trying to be used without being configured'
end
config_present?() click to toggle source

Helper method for checking if configuration is present

@return [Boolean]

# File lib/invoca/metrics/prometheus.rb, line 51
def config_present?
  @config.present?
end
configure() { |config| ... } click to toggle source

This method is used to configure Invoca::Metrics to export metrics to be pulled into Prometheus.

@yield [Invoca::Metrics::Prometheus::Configuration]

@void

# File lib/invoca/metrics/prometheus.rb, line 18
def configure
  @config = Invoca::Metrics::Prometheus::Configuration.new.tap { |config| yield config }.freeze

  # If there are any metrics at this point, it's likely that Prometheus metrics
  # were declared before invoca-metrics was loaded; walk the set of metrics in the
  # registry, resetting their PrometheusExporter::Metric objects
  metrics.metrics.values.each do |metric|
    case metric.type
    when :counter
      metric.reset_metric(@config.register_metric(:counter, metric.name, nil, { labels: metric.default_labels, graphite: metric.graphite }))
    when :gauge
      metric.reset_metric(@config.register_metric(:gauge, metric.name, nil, { labels: metric.default_labels, graphite: metric.graphite }))
    when :histogram
      metric.reset_metric(@config.register_metric(:histogram, metric.name, nil, { labels: metric.default_labels, graphite: metric.graphite, buckets: metric.buckets }))
    else
      warn("Metric type #{metric.type} not one of #{Invoca::Metrics::Prometheus::Configuration::AVAILABLE_METRIC_TYPES}.")
    end
  end

  @config
end
metrics() click to toggle source

This method is used to access the global list of all metrics that were registered

@return [Invoca::Metrics::Prometheus::MetricsRegistry]

# File lib/invoca/metrics/prometheus.rb, line 61
def metrics
  @metrics ||= MetricsRegistry.new
end