Class: Yabeda::Prometheus::Mmap::Adapter
- Inherits:
-
BaseAdapter
- Object
- BaseAdapter
- Yabeda::Prometheus::Mmap::Adapter
- Defined in:
- lib/yabeda/prometheus/mmap/adapter.rb
Overview
Prometheus metrics collecion adapter
Instance Method Summary collapse
- #build_name(metric) ⇒ Object
- #build_tags(tags) ⇒ Object
- #debug! ⇒ Object
- #perform_counter_increment!(metric, tags, value) ⇒ Object
- #perform_gauge_set!(metric, tags, value) ⇒ Object
- #perform_histogram_measure!(metric, tags, value) ⇒ Object
- #register_counter!(metric) ⇒ Object
- #register_gauge!(metric) ⇒ Object
- #register_histogram!(metric) ⇒ Object
- #registry ⇒ Object
- #validate_metric!(metric) ⇒ Object
Instance Method Details
#build_name(metric) ⇒ Object
63 64 65 |
# File 'lib/yabeda/prometheus/mmap/adapter.rb', line 63 def build_name(metric) [metric.group, metric.name, metric.unit].compact.join('_').to_sym end |
#build_tags(tags) ⇒ Object
67 68 69 70 71 |
# File 'lib/yabeda/prometheus/mmap/adapter.rb', line 67 def () Array().each_with_object({}) do |tag, hash| hash[tag] = nil end end |
#debug! ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/yabeda/prometheus/mmap/adapter.rb', line 79 def debug! Yabeda.configure do group :yabeda_prometheus_mmap histogram :render_duration, tags: %i[], unit: :seconds, buckets: [0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10], comment: 'Time required to render all metrics in Prometheus format' end end |
#perform_counter_increment!(metric, tags, value) ⇒ Object
28 29 30 |
# File 'lib/yabeda/prometheus/mmap/adapter.rb', line 28 def perform_counter_increment!(metric, , value) registry.get(build_name(metric)).increment(, value) end |
#perform_gauge_set!(metric, tags, value) ⇒ Object
43 44 45 |
# File 'lib/yabeda/prometheus/mmap/adapter.rb', line 43 def perform_gauge_set!(metric, , value) registry.get(build_name(metric)).set(, value) end |
#perform_histogram_measure!(metric, tags, value) ⇒ Object
59 60 61 |
# File 'lib/yabeda/prometheus/mmap/adapter.rb', line 59 def perform_histogram_measure!(metric, , value) registry.get(build_name(metric)).observe(, value) end |
#register_counter!(metric) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/yabeda/prometheus/mmap/adapter.rb', line 18 def register_counter!(metric) validate_metric!(metric) registry.counter( build_name(metric), metric.comment, (metric.) ) end |
#register_gauge!(metric) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/yabeda/prometheus/mmap/adapter.rb', line 32 def register_gauge!(metric) validate_metric!(metric) registry.gauge( build_name(metric), metric.comment, (metric.), gauge_aggregation_mode(metric.aggregation) ) end |
#register_histogram!(metric) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/yabeda/prometheus/mmap/adapter.rb', line 47 def register_histogram!(metric) buckets = metric.buckets || ::Prometheus::Client::Histogram::DEFAULT_BUCKETS registry.histogram( build_name(metric), metric.comment, (metric.), buckets ) end |
#registry ⇒ Object
14 15 16 |
# File 'lib/yabeda/prometheus/mmap/adapter.rb', line 14 def registry @registry ||= ::Yabeda::Prometheus::Mmap.registry end |
#validate_metric!(metric) ⇒ Object
73 74 75 76 77 |
# File 'lib/yabeda/prometheus/mmap/adapter.rb', line 73 def validate_metric!(metric) return if metric.comment raise ArgumentError, 'Prometheus require metrics to have comments' end |