class Invoca::Metrics::Prometheus::DeclareMetrics::Dsl
Attributes
declared_metrics[R]
prometheus_exporter_config[R]
source[R]
Public Class Methods
new(source)
click to toggle source
# File lib/invoca/metrics/prometheus/declare_metrics/dsl.rb, line 16 def initialize(source) @source = source @declared_metrics = [] if Invoca::Metrics::Prometheus.config_present? @prometheus_exporter_config = Invoca::Metrics::Prometheus.config end end
Public Instance Methods
counter(name, labels: {}, graphite: nil, help: nil)
click to toggle source
# File lib/invoca/metrics/prometheus/declare_metrics/dsl.rb, line 24 def counter(name, labels: {}, graphite: nil, help: nil) # TODO: We can drop the 'to_s' when we stop supporting ruby 2.6 if !name.to_s.end_with?("_total") warn("#{source} counter #{name.inspect} should end in \"_total\" so that Grafana can tell that it is a counter.") end metric = if Invoca::Metrics::Prometheus.config_present? prometheus_exporter_config.register_metric(:counter, name, help, { labels: labels, graphite: graphite }) end add_metric(Counter.new(name, :counter, source, metric, labels: labels, graphite: graphite)) end
gauge(name, labels: {}, graphite: nil, help: nil)
click to toggle source
# File lib/invoca/metrics/prometheus/declare_metrics/dsl.rb, line 44 def gauge(name, labels: {}, graphite: nil, help: nil) metric = if Invoca::Metrics::Prometheus.config_present? prometheus_exporter_config.register_metric(:gauge, name, help, { labels: labels, graphite: graphite }) end add_metric(Gauge.new(name, :gauge, source, metric, labels: labels, graphite: graphite)) end
histogram(name, buckets:, labels: {}, graphite: nil, help: nil)
click to toggle source
# File lib/invoca/metrics/prometheus/declare_metrics/dsl.rb, line 36 def histogram(name, buckets:, labels: {}, graphite: nil, help: nil) metric = if Invoca::Metrics::Prometheus.config_present? prometheus_exporter_config.register_metric(:histogram, name, help, { labels: labels, graphite: graphite, buckets: buckets }) end add_metric(Histogram.new(name, :histogram, source, metric, buckets: buckets, labels: labels, graphite: graphite)) end
Private Instance Methods
add_metric(metric)
click to toggle source
# File lib/invoca/metrics/prometheus/declare_metrics/dsl.rb, line 54 def add_metric(metric) @declared_metrics << metric end