Class: PhobosPrometheus::Collector::Histogram
- Inherits:
-
Object
- Object
- PhobosPrometheus::Collector::Histogram
- Includes:
- Helper
- Defined in:
- lib/phobos_prometheus/collector/histogram.rb
Overview
Collector class to track histogram events
Constant Summary collapse
- BUCKETS =
Buckets in ms for histogram
[5, 10, 25, 50, 100, 250, 500, 750, 1500, 3000, 5000].freeze
Instance Attribute Summary collapse
-
#histogram ⇒ Object
readonly
Returns the value of attribute histogram.
Attributes included from Helper
Class Method Summary collapse
Instance Method Summary collapse
- #fetch_bucket_size(bucket_name) ⇒ Object
- #init_metrics(prometheus_label) ⇒ Object
-
#initialize(instrumentation:, bucket_name:) ⇒ Histogram
constructor
A new instance of Histogram.
- #update_metrics(event_label, event) ⇒ Object
Methods included from Helper
#safely_update_metrics, #setup_collector_module, #subscribe_metrics
Constructor Details
#initialize(instrumentation:, bucket_name:) ⇒ Histogram
24 25 26 27 28 |
# File 'lib/phobos_prometheus/collector/histogram.rb', line 24 def initialize(instrumentation:, bucket_name:) @metrics_prefix = @instrumentation = @registry = @histogram = nil @buckets = fetch_bucket_size(bucket_name) || BUCKETS setup_collector_module(instrumentation: instrumentation) end |
Instance Attribute Details
#histogram ⇒ Object (readonly)
Returns the value of attribute histogram.
8 9 10 |
# File 'lib/phobos_prometheus/collector/histogram.rb', line 8 def histogram @histogram end |
Class Method Details
.create(config) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/phobos_prometheus/collector/histogram.rb', line 13 def self.create(config) instrumentation = config[:instrumentation] bucket_name = config[:bucket_name] raise(InvalidConfigurationError, 'Histogram requires :bucket_name and :instrumentation') \ unless instrumentation && bucket_name new( instrumentation: instrumentation, bucket_name: bucket_name ) end |
Instance Method Details
#fetch_bucket_size(bucket_name) ⇒ Object
30 31 32 |
# File 'lib/phobos_prometheus/collector/histogram.rb', line 30 def fetch_bucket_size(bucket_name) PhobosPrometheus.config.buckets.find { |bucket| bucket.name == bucket_name }.bins end |
#init_metrics(prometheus_label) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/phobos_prometheus/collector/histogram.rb', line 34 def init_metrics(prometheus_label) @histogram = @registry.histogram( :"#{@metrics_prefix}_#{prometheus_label}_duration", "The duration spent (in ms) consuming #{@instrumentation} events.", {}, @buckets ) end |
#update_metrics(event_label, event) ⇒ Object
43 44 45 |
# File 'lib/phobos_prometheus/collector/histogram.rb', line 43 def update_metrics(event_label, event) @histogram.observe(event_label, event.duration) end |