Small clojure layer on top of Prometheus metrics
Include the lib
com.monkeyprojects/metrics {:mvn/version "0.1.0-SNAPSHOT"}
You can create a metrics registry, add gauges and counters. Then you can have Prometheus scrape it from and endpoint, or push it to an OTLP or Push gateway endpoint.
(require '[monkey.metrics.prometheus :as p])
;; Create new registry. It will contain the JVM metrics by default.
(def reg (p/make-registry))
;; Set up a gauge
(def g (p/make-gauge "test_gauge" reg))
;; Give it a value
(p/gauge-set g 100)
;; Scrape the registry
(p/scrape reg)
;; => "test_gauge 100
;; ..."
When creating a gauge or a counter, you can specify additional options as a map:
:labels: labels to be specified on the metric, as string/string map.:description:callback: see below.Gauges and counters either can be explicitly set using the set- functions, or you can
provide a callback. This callback is a zero-arity function that will be invoked on each
scrape operation.
(def c (p/make-counter "test_counter" reg {:callback (constantly 100)}))
(p/scrape reg)
;; => "test_counter 100"
Instead of scraping, you can also set up a client that periodically pushes to an OTLP endpoint.
(require '[monkey.metrics.otlp :as o])
(def c (o/make-client "http://some-otlp.endpoint.org"
reg
{:headers {"X-Auth-Token" "secret-token"}
:interval 10})) ; seconds
The client will push depending on the interval, which is 60 seconds by default.
Don't forget to .close the client when you're done with it.
Copyright (c) 2026 by Monkey Projects
Can you improve this documentation?Edit on Codeberg
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |