module Prometheus module Client module Helper module MetricsProcessing def self.merge_metrics(metrics) metrics end def self.min(a, b) if a < b a else b end end def self.max(a, b) if a > b a else b end end def self.merge_samples(raw_samples, metric_type, multiprocess_mode) samples = {} raw_samples.each do |name, labels, value| key = { name: name, labels: labels } # without_pid = labels.delete(:pid) case metric_type when :gauge case multiprocess_mode when 'min' labels.delete(:pid) s = samples.fetch(key, value) samples[key] = min(s, value) when 'max' labels.delete(:pid) s = samples.fetch(key, value) samples[key] = max(s, value) when 'livesum' labels.delete(:pid) s = samples.fetch(key, 0.0) samples[key] = s + value else # all/liveall samples[key] = value end else labels.delete(:pid) # Counter, Histogram and Summary. s = samples.fetch(key, 0.0) samples[key] = s + value end end samples end end end end end