lib/pgq_prometheus/collector.rb in pgq_prometheus-0.2.1 vs lib/pgq_prometheus/collector.rb in pgq_prometheus-0.2.2
- old
+ new
@@ -3,10 +3,11 @@
require_relative 'config'
require 'prometheus_exporter/server'
module PgqPrometheus
class Collector < PrometheusExporter::Server::TypeCollector
+ MAX_METRIC_AGE = 30
def initialize
@data = []
@observers = {}
@@ -46,9 +47,13 @@
metrics.values
end
def collect(obj)
+ now = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
+
+ obj['created_at'] = now
+ @data.delete_if { |m| m['created_at'] + MAX_METRIC_AGE < now }
@data << obj
end
end
end