Skip to content

Commit

Permalink
delete old metrics in puma collector
Browse files Browse the repository at this point in the history
  • Loading branch information
Fivell committed Jul 9, 2019
1 parent 3095996 commit 809b382
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/prometheus_exporter/server/puma_collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

module PrometheusExporter::Server
class PumaCollector < TypeCollector

MAX_PUMA_METRIC_AGE = 30

PUMA_GAUGES = {
workers_total: "Number of puma workers.",
booted_workers_total: "Number of puma workers booted.",
Expand Down Expand Up @@ -47,7 +50,16 @@ def metrics
end

def collect(obj)
@puma_metrics << obj
now = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)

obj["created_at"] = now

@puma_metrics .delete_if do |current|
(obj["pid"] == current["pid"] && obj["hostname"] == current["hostname"]) ||
(current["created_at"] + MAX_PUMA_METRIC_AGE < now)
end

@puma_metrics << obj
end
end
end

0 comments on commit 809b382

Please sign in to comment.