Class: PrometheusExporter::Server::Collector
- Inherits:
-
CollectorBase
- Object
- CollectorBase
- PrometheusExporter::Server::Collector
- Defined in:
- lib/prometheus_exporter/server/collector.rb
Constant Summary collapse
- MAX_PROCESS_METRIC_AGE =
60
- PROCESS_GAUGES =
{ heap_free_slots: "Free ruby heap slots", heap_live_slots: "Used ruby heap slots", v8_heap_size: "Total JavaScript V8 heap size (bytes)", v8_used_heap_size: "Total used JavaScript V8 heap size (bytes)", v8_physical_size: "Physical size consumed by V8 heaps", v8_heap_count: "Number of V8 contexts running", rss: "Total RSS used by process", }
- PROCESS_COUNTERS =
{ major_gc_count: "Major GC operations by process", minor_gc_count: "Minor GC operations by process", total_allocated_objects: "Total number of allocateds objects by process", }
Instance Method Summary collapse
-
#initialize ⇒ Collector
constructor
A new instance of Collector.
- #process(str) ⇒ Object
- #prometheus_metrics_text ⇒ Object
Constructor Details
#initialize ⇒ Collector
Returns a new instance of Collector.
23 24 25 26 27 28 |
# File 'lib/prometheus_exporter/server/collector.rb', line 23 def initialize @process_metrics = [] @metrics = {} @buffer = [] @mutex = Mutex.new end |
Instance Method Details
#process(str) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/prometheus_exporter/server/collector.rb', line 30 def process(str) obj = JSON.parse(str) @mutex.synchronize do if obj["type"] == "web" observe_web(obj) elsif obj["type"] == "process" observe_process(obj) else metric = @metrics[obj["name"]] if !metric metric = register_metric_unsafe(obj) end metric.observe(obj["value"], obj["keys"]) end end end |
#prometheus_metrics_text ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/prometheus_exporter/server/collector.rb', line 47 def prometheus_metrics_text @mutex.synchronize do val = @metrics.values.map(&:to_prometheus_text).join("\n") metrics = {} if @process_metrics.length > 0 val << "\n" @process_metrics.map do |m| metric_key = { pid: m["pid"], type: m["process_type"] } PROCESS_GAUGES.map do |k, help| k = k.to_s if v = m[k] g = metrics[k] ||= PrometheusExporter::Metric::Gauge.new(k, help) g.observe(v, metric_key) end end PROCESS_COUNTERS.map do |k, help| k = k.to_s if v = m[k] c = metrics[k] ||= PrometheusExporter::Metric::Counter.new(k, help) c.observe(v, metric_key) end end end val << metrics.values.map(&:to_prometheus_text).join("\n") end val end end |