Module: PgqPrometheus::Config
- Defined in:
- lib/pgq_prometheus/config.rb
Constant Summary collapse
- ALLOWED_FROM =
[:queue, :consumer, nil]
Class Attribute Summary collapse
-
._metrics ⇒ Object
Returns the value of attribute _metrics.
-
.type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
- .register_counter(name, help, options = {}) ⇒ Object
- .register_gauge(name, help, options = {}) ⇒ Object
- .register_histogram(name, help, options = {}) ⇒ Object
- .register_metric(metric_class, name, help, options = {}) ⇒ Object
- .register_summary(name, help, options = {}) ⇒ Object
- .unregister_metric(name) ⇒ Object
Class Attribute Details
._metrics ⇒ Object
Returns the value of attribute _metrics.
10 11 12 |
# File 'lib/pgq_prometheus/config.rb', line 10 def _metrics @_metrics end |
.type ⇒ Object
Returns the value of attribute type.
10 11 12 |
# File 'lib/pgq_prometheus/config.rb', line 10 def type @type end |
Class Method Details
.register_counter(name, help, options = {}) ⇒ Object
62 63 64 |
# File 'lib/pgq_prometheus/config.rb', line 62 def self.register_counter(name, help, = {}) register_metric 'PrometheusExporter::Metric::Counter', name, help, end |
.register_gauge(name, help, options = {}) ⇒ Object
70 71 72 |
# File 'lib/pgq_prometheus/config.rb', line 70 def self.register_gauge(name, help, = {}) register_metric 'PrometheusExporter::Metric::Gauge', name, help, end |
.register_histogram(name, help, options = {}) ⇒ Object
78 79 80 81 82 |
# File 'lib/pgq_prometheus/config.rb', line 78 def self.register_histogram(name, help, = {}) buckets = .delete(:buckets) [:metric_args] ||= [buckets: buckets] register_metric 'PrometheusExporter::Metric::Histogram', name, help, end |
.register_metric(metric_class, name, help, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/pgq_prometheus/config.rb', line 18 def self.register_metric(metric_class, name, help, = {}) 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 = [:from] column = [:column] || name apply = [: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: [:metric_args] || [], labels: [:labels] || {}, from: from, apply: apply } end |
.register_summary(name, help, options = {}) ⇒ Object
88 89 90 91 92 |
# File 'lib/pgq_prometheus/config.rb', line 88 def self.register_summary(name, help, = {}) buckets = .delete(:quantiles) [:metric_args] ||= [quantiles: buckets] register_metric 'PrometheusExporter::Metric::Summary', name, help, end |
.unregister_metric(name) ⇒ Object
54 55 56 |
# File 'lib/pgq_prometheus/config.rb', line 54 def self.unregister_metric(name) _metrics.delete(name.to_sym) end |