Help with writing textfiles
This commit is contained in:
parent
81d8dda118
commit
12d3d9de67
1 changed files with 22 additions and 0 deletions
|
|
@ -27,6 +27,7 @@
|
|||
#:export (make-metrics-registry
|
||||
metrics-registry-fetch-metric
|
||||
write-metrics
|
||||
write-textfile
|
||||
|
||||
make-counter-metric
|
||||
make-gauge-metric
|
||||
|
|
@ -409,3 +410,24 @@ so that it can receive and store the metric values."
|
|||
value))
|
||||
(metric-values metric))))
|
||||
(metrics-registry-metrics-hash registry)))
|
||||
|
||||
(define (write-textfile registry filename)
|
||||
"Write all metrics from the given @var{registry} to @var{filename}
|
||||
in the standard text based exposition format.
|
||||
|
||||
For the node exporter to read the file, the @var{filename} must end
|
||||
with .prom.
|
||||
|
||||
This procedure takes care of atomically replacing the file."
|
||||
(let* ((template (string-append filename ".XXXXXX"))
|
||||
(out (mkstemp! template)))
|
||||
(with-throw-handler #t
|
||||
(lambda ()
|
||||
(chmod out(logand #o666 (lognot (umask))))
|
||||
(write-metrics registry out)
|
||||
(close out)
|
||||
(rename-file template filename)
|
||||
#t)
|
||||
(lambda (key . args)
|
||||
(false-if-exception (delete-file template))))))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue