clack-prometheus - Clack middleware to serve stats in Prometheus format.


This library provides a way to collect metrics in Prometheus. In addition to system metrics collected by, it also collects metrics on SBCL's garbage collection, using prometheus-gc system.

This library is used in 40ants-openrpc system to collect stats from JSON-RPC microservices.


You can install this library from Quicklisp, but you want to receive updates quickly, then install it from

(ql-dist:install-dist ""
                      :prompt nil)
(ql:quickload :clack-prometheus)


Here is a minimal example which creates a "hello-world" clack application and adds a /metrics route to it:

CL-USER> (defparameter *handler*
           (flet ((main-app (env)
                    (declare (ignore env))
                      (:content-type "text/plain")
                      ("Hello, Clack!"))))
              :port 9090)))

When you run this code, go to another terminal tab and run curl. On / path our hello world app will respond:

$ curl -s 'http://localhost:9090/'
Hello, Clack!

and on /metrics we'll see output in Prometheus format:

$ curl -s 'http://localhost:9090/metrics'
# TYPE sbcl_read_only_bytes gauge
# HELP sbcl_read_only_bytes SBCL Read-only space usage
sbcl_read_only_bytes 0
# TYPE sbcl_static_bytes gauge
# HELP sbcl_static_bytes SBCL Static space usage
sbcl_static_bytes 1744
# TYPE sbcl_dynamic_bytes gauge
# HELP sbcl_dynamic_bytes SBCL Dynamic space usage
sbcl_dynamic_bytes{object_type="other"} 27705408
sbcl_dynamic_bytes{object_type="instance"} 24370256
# TYPE process_resident_memory_bytes gauge
# HELP process_resident_memory_bytes Resident memory size in bytes.
process_resident_memory_bytes 244039680
# TYPE process_cpu_seconds counter
# HELP process_cpu_seconds Process CPU seconds.
process_cpu_seconds{time="stime"} 121.2
process_cpu_seconds{time="utime"} 300.51
# TYPE process_cpu_seconds_total counter
# HELP process_cpu_seconds_total Process CPU seconds total.
process_cpu_seconds_total 421.71





Mounts a Clack sub-application to serve stats in Prometheus format.

By default, app will respons on /metrics path but you can provide an alternative either directly as PATH argument or via PROMETHEUS_URI environment variable.

To customize metrics provided by the application, you can manually create a prometheus registry by calling to PROMETHEUS:MAKE-REGISTRY, add necessary counters, gauges, etc and then pass this registry as REGISTRY argument to the with-prometheus-stats function.