From 826704723a04accc95c2a5a91b0254851d5cf7d0 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sun, 29 Nov 2020 08:49:46 +0000 Subject: Support outputting docstrings --- prometheus.scm | 64 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 26 deletions(-) (limited to 'prometheus.scm') diff --git a/prometheus.scm b/prometheus.scm index 024f578..d6889e1 100644 --- a/prometheus.scm +++ b/prometheus.scm @@ -367,30 +367,42 @@ so that it can receive and store the metric values." (hash-for-each (lambda (name metric) - (hash-for-each - (lambda (label-values value) - (simple-format - port - "~A~A~A ~A\n" - (or (and=> (metrics-registry-namespace registry) - (lambda (namespace) - (string-append namespace "_"))) - "") - name - (if (null? label-values) - "" - (string-append - "{" - (string-join (map - (match-lambda - ((label . value) - (simple-format - #f - "~A=\"~A\"" - label value))) - label-values) - ",") - "}")) - value)) - (metric-values metric))) + (let ((full-name + (string-append + (or (and=> (metrics-registry-namespace registry) + (lambda (namespace) + (string-append namespace "_"))) + "") + name))) + + (and=> (metric-docstring metric) + (lambda (docstring) + (simple-format + port + "# HELP ~A ~A\n" + full-name + docstring))) + + (hash-for-each + (lambda (label-values value) + (simple-format + port + "~A~A ~A\n" + full-name + (if (null? label-values) + "" + (string-append + "{" + (string-join (map + (match-lambda + ((label . value) + (simple-format + #f + "~A=\"~A\"" + label value))) + label-values) + ",") + "}")) + value)) + (metric-values metric)))) (metrics-registry-metrics-hash registry))) -- cgit v1.2.3