This implements a Caddy v2 module that exposes metrics in the Prometheus format.
To use this module, you must build a Caddy binary with the module compiled in. Use xcaddy for this.
The simplest use could be in a Caddyfile like:
{
order prometheus first
}
localhost
prometheus
Here is an example that tracks metrics for Caddy's reverse_proxy
module as well:
{
"apps": {
"http": {
"servers": {
"srv0": {
"listen": [
":443"
],
"routes": [
{
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "prometheus"
},
{
"handler": "reverse_proxy",
"upstreams": [
{
"dial": "10.0.0.1:80"
},
{
"dial": "10.0.0.2:80"
}
]
}
]
}
]
}
],
"match": [
{
"host": [
"redacted.mycompany.com"
]
}
],
"terminal": true
}
]
}
}
}
}
}
Then, when using a Caddy server with this module enabled:
$ curl localhost/
$ curl localhost:9180/metrics
...
caddy_http_response_size_bytes_sum{code="418",method="get"} 42
...
-
In order to make "path" metrics to be processed, we had to copy and make some changes to the promhttp lib. It is unlikelly that the original project will accept those changes, so we kept the copy on this same project. See files promhttp*
-
Thanks to Prometheus promhttp. See original code at https://github.com/prometheus/client_golang/tree/master/prometheus/promhttp
-
Thanks to https://github.com/damnever/caddyprom for the insights on how to add "path" as metric labels
Copyright (c) 2020 Dave Henderson