diff --git a/README.md b/README.md index 73b42cf..75d73fc 100644 --- a/README.md +++ b/README.md @@ -371,6 +371,8 @@ end | Counter | `major_gc_ops_total` | Major GC operations by process | | Counter | `minor_gc_ops_total` | Minor GC operations by process | | Counter | `allocated_objects_total` | Total number of allocated objects by process | +| Gauge | `marking_time` | Marking time spent | +| Gauge | `sweeping_time` | Sweeping time spent | _Metrics marked with * are only collected when `MiniRacer` is defined._ diff --git a/lib/prometheus_exporter/instrumentation/process.rb b/lib/prometheus_exporter/instrumentation/process.rb index 4ec4bfd..fe1c172 100644 --- a/lib/prometheus_exporter/instrumentation/process.rb +++ b/lib/prometheus_exporter/instrumentation/process.rb @@ -63,6 +63,8 @@ def collect_gc_stats(metric) metric[:major_gc_ops_total] = stat[:major_gc_count] metric[:minor_gc_ops_total] = stat[:minor_gc_count] metric[:allocated_objects_total] = stat[:total_allocated_objects] + metric[:marking_time] = stat[:mark_time] + metric[:sweeping_time] = stat[:sweep_time] end def collect_v8_stats(metric) diff --git a/lib/prometheus_exporter/server/process_collector.rb b/lib/prometheus_exporter/server/process_collector.rb index 6a3a008..a651f0c 100644 --- a/lib/prometheus_exporter/server/process_collector.rb +++ b/lib/prometheus_exporter/server/process_collector.rb @@ -13,6 +13,8 @@ class ProcessCollector < TypeCollector v8_physical_size: "Physical size consumed by V8 heaps.", v8_heap_count: "Number of V8 contexts running.", rss: "Total RSS used by process.", + marking_time: "Time spent in GC marking.", + sweeping_time: "Time spent in GC sweeping.", } PROCESS_COUNTERS = { diff --git a/test/server/process_collector_test.rb b/test/server/process_collector_test.rb index 1a6aa64..cb14980 100644 --- a/test/server/process_collector_test.rb +++ b/test/server/process_collector_test.rb @@ -26,14 +26,16 @@ def base_data "rss" => 3000, "major_gc_ops_total" => 4000, "minor_gc_ops_total" => 4001, - "allocated_objects_total" => 4002 + "allocated_objects_total" => 4002, + "marking_time" => 4003, + "sweeping_time" => 4004, } end def test_metrics_collection collector.collect(base_data) - assert_equal 10, collector.metrics.size + assert_equal 12, collector.metrics.size assert_equal [ 'heap_free_slots{pid="1000",hostname="localhost"} 1000', 'heap_live_slots{pid="1000",hostname="localhost"} 1001', @@ -42,30 +44,32 @@ def test_metrics_collection 'v8_physical_size{pid="1000",hostname="localhost"} 2003', 'v8_heap_count{pid="1000",hostname="localhost"} 2004', 'rss{pid="1000",hostname="localhost"} 3000', + 'marking_time{pid="1000",hostname="localhost"} 4003', + 'sweeping_time{pid="1000",hostname="localhost"} 4004', 'major_gc_ops_total{pid="1000",hostname="localhost"} 4000', 'minor_gc_ops_total{pid="1000",hostname="localhost"} 4001', - 'allocated_objects_total{pid="1000",hostname="localhost"} 4002' + 'allocated_objects_total{pid="1000",hostname="localhost"} 4002', ], collector_metric_lines end def test_metrics_deduplication collector.collect(base_data) - assert_equal 10, collector.metrics.size - assert_equal 10, collector_metric_lines.size + assert_equal 12, collector.metrics.size + assert_equal 12, collector_metric_lines.size collector.collect(base_data) - assert_equal 10, collector.metrics.size - assert_equal 10, collector_metric_lines.size + assert_equal 12, collector.metrics.size + assert_equal 12, collector_metric_lines.size collector.collect(base_data.merge({ "hostname" => "localhost2" })) - assert_equal 10, collector.metrics.size - assert_equal 20, collector_metric_lines.size + assert_equal 12, collector.metrics.size + assert_equal 24, collector_metric_lines.size end def test_metrics_expiration stub_monotonic_clock(0) do collector.collect(base_data) - assert_equal 10, collector.metrics.size + assert_equal 12, collector.metrics.size end stub_monotonic_clock(max_metric_age + 1) do