module PgqPrometheus::Config
Constants
- ALLOWED_FROM
Attributes
_metrics[RW]
type[RW]
Public Class Methods
register_counter(name, help, options = {})
click to toggle source
@param name [Symbol, String] @param help [String] @param options [String] keys :from, :column, :apply @raise ArgumentError
# File lib/pgq_prometheus/config.rb, line 62 def self.register_counter(name, help, options = {}) register_metric 'PrometheusExporter::Metric::Counter', name, help, options end
register_gauge(name, help, options = {})
click to toggle source
@param name [Symbol, String] @param help [String] @param options [String] keys :from, :column, :apply @raise ArgumentError
# File lib/pgq_prometheus/config.rb, line 70 def self.register_gauge(name, help, options = {}) register_metric 'PrometheusExporter::Metric::Gauge', name, help, options end
register_histogram(name, help, options = {})
click to toggle source
@param name [Symbol, String] @param help [String] @param options [String] keys :from, :column, :apply @raise ArgumentError
# File lib/pgq_prometheus/config.rb, line 78 def self.register_histogram(name, help, options = {}) buckets = options.delete(:buckets) options[:metric_args] ||= [buckets: buckets] register_metric 'PrometheusExporter::Metric::Histogram', name, help, options end
register_metric(metric_class, name, help, options = {})
click to toggle source
@param metric_class [Class<Object>, String] @param name [Symbol, String] @param help [String] @param options [String] keys :from, :column, :apply @raise ArgumentError
# File lib/pgq_prometheus/config.rb, line 18 def self.register_metric(metric_class, name, help, options = {}) raise ArgumentError, 'metric_class must be present' if metric_class.nil? name = name.to_sym raise ArgumentError, "metric #{name} already defined - unregister it" if _metrics.key?(name) from = options[:from] column = options[:column] || name apply = options[:apply] unless ALLOWED_FROM.include?(from) raise ArgumentError, "invalid :from, allowed: #{ALLOWED_FROM.map(&:inspect).join(', ')}" end if apply.nil? case from when :queue apply = proc { |queue_info| queue_info[column.to_sym] } when :consumer apply = proc { |consumer_info, _queue_info| consumer_info[column.to_sym] } else raise ArgumentError, 'require :apply block for metric without :from' end end _metrics[name] = { metric_class: metric_class, help: help, metric_args: options[:metric_args] || [], labels: options[:labels] || {}, from: from, apply: apply } end
register_summary(name, help, options = {})
click to toggle source
@param name [Symbol, String] @param help [String] @param options [String] keys :from, :column, :apply @raise ArgumentError
# File lib/pgq_prometheus/config.rb, line 88 def self.register_summary(name, help, options = {}) buckets = options.delete(:quantiles) options[:metric_args] ||= [quantiles: buckets] register_metric 'PrometheusExporter::Metric::Summary', name, help, options end
unregister_metric(name)
click to toggle source
@param name [Symbol, String]
# File lib/pgq_prometheus/config.rb, line 54 def self.unregister_metric(name) _metrics.delete(name.to_sym) end