discourse / prometheus_exporter

A framework for collecting and aggregating prometheus metrics
MIT License
525 stars 153 forks source link

Add marking and sweeping time as Process stat #300

Open benoittgt opened 5 months ago

benoittgt commented 5 months ago

Add marking and sweeping time as GC stats. It was introduced in https://bugs.ruby-lang.org/issues/19437

I think we should also add GC.latest_gc_info[:major_by]. I can do it in another PR.

--- a/lib/prometheus_exporter/instrumentation/process.rb
+++ b/lib/prometheus_exporter/instrumentation/process.rb
@@ -65,6 +65,7 @@ module PrometheusExporter::Instrumentation
       metric[:allocated_objects_total] = stat[:total_allocated_objects]
       metric[:marking_time] = stat[:marking_time]
       metric[:sweeping_time] = stat[:sweeping_time]
+      metric[:last_major_by] = GC.latest_gc_info[:major_by]

We could store it as a last state like kube-state-metrics does for pod last state. It's a fast method. At the moment it's not possible because gauge are only numeric in prometheus_exporter.

cc @mtparet @byroot

SamSaffron commented 5 months ago

should we only add the matrics on Ruby versions that have it?

benoittgt commented 5 months ago

@SamSaffron Yes it's a good idea. I made the change. Do we want to test this?