diff options
-rw-r--r-- | prometheus.scm | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/prometheus.scm b/prometheus.scm index 04f24d8..447ba08 100644 --- a/prometheus.scm +++ b/prometheus.scm @@ -44,7 +44,9 @@ metric-set metric-observe - call-with-duration-metric)) + call-with-duration-metric + + get-gc-metrics-updater)) (define-record-type <metrics-registry> (make-metrics-registry-record metrics-hash namespace) @@ -558,3 +560,28 @@ This procedure takes care of atomically replacing the file." (lambda (key . args) (false-if-exception (delete-file template)))))) +(define (get-gc-metrics-updater registry) + (define metrics + `((gc-time-taken + . ,(make-gauge-metric registry "guile_gc_time_taken")) + (heap-size + . ,(make-gauge-metric registry "guile_heap_size")) + (heap-free-size + . ,(make-gauge-metric registry "guile_heap_free_size")) + (heap-total-allocated + . ,(make-gauge-metric registry "guile_heap_total_allocated")) + (heap-allocated-since-gc + . ,(make-gauge-metric registry "guile_allocated_since_gc")) + (protected-objects + . ,(make-gauge-metric registry "guile_gc_protected_objects")) + (gc-times + . ,(make-gauge-metric registry "guile_gc_times")))) + + (lambda () + (let ((stats (gc-stats))) + (for-each + (match-lambda + ((name . metric) + (let ((value (assq-ref stats name))) + (metric-set metric value)))) + metrics)))) |