aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2020-11-29 08:49:46 +0000
committerChristopher Baines <mail@cbaines.net>2020-11-29 08:49:46 +0000
commit826704723a04accc95c2a5a91b0254851d5cf7d0 (patch)
treef933b6de948236504e9855d3858ecd9161c07f9d
parent8980f39bafb3e59d6de17e7b311df4932e5b5182 (diff)
downloadprometheus-826704723a04accc95c2a5a91b0254851d5cf7d0.tar
prometheus-826704723a04accc95c2a5a91b0254851d5cf7d0.tar.gz
Support outputting docstrings
-rw-r--r--prometheus.scm64
1 files changed, 38 insertions, 26 deletions
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)))