Caddy v2 middleware metrics not exposed

1. The problem I’m having:

Somehow I am able to see admin metrics, runtime metics, reverse proxy metrics but not the middleware metrics. Until a few days ago the metrics were displayed just fine. I don´t know, what could have changed, except maybe for restarting caddy. I am calling the endpoint via http://localhost:2020/metrics. Any idea?

3. Caddy version:

v2.6.2

4. How I installed and ran Caddy:

a. System environment:

Debian 11 5.10.0-21-amd64

c. Service/unit/compose file:

;
; Ansible managed
;
; source: https://github.com/mholt/caddy/blob/master/dist/init/linux-systemd/caddy.service
; version: 6be0386
; changes: Set variables via Ansible

[Unit]
Description=Caddy HTTP/2 web server
Documentation=https://caddyserver.com/docs
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service
StartLimitIntervalSec=86400
StartLimitBurst=5

[Service]
Restart=on-failure

; User and group the process will run as.
User=www-data
Group=www-data

; Letsencrypt-issued certificates will be written to this directory.
Environment=CADDYPATH=/etc/ssl/caddy

ExecStart="/usr/local/bin/caddy" run --environ --config "/etc/caddy/config.json"
ExecReload="/usr/local/bin/caddy" reload --config "/etc/caddy/config.json"

; Limit the number of file descriptors; see `man systemd.exec` for more limit settings.
LimitNOFILE=1048576

; Use private /tmp and /var/tmp, which are discarded after caddy stops.
PrivateTmp=true
; Use a minimal /dev
PrivateDevices=true
; Hide /home, /root, and /run/user. Nobody will steal your SSH-keys.
ProtectHome=false
; Make /usr, /boot, /etc and possibly some more folders read-only.
ProtectSystem=full
; … except /etc/ssl/caddy, because we want Letsencrypt-certificates there.
;   This merely retains r/w access rights, it does not add any new. Must still be writable on the host!
ReadWriteDirectories=/etc/ssl/caddy /var/log/caddy

; The following additional security directives only work with systemd v229 or later.
; They further retrict privileges that can be gained by caddy.
; Note that you may have to add capabilities required by any plugins in use.
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_BIND_SERVICE
NoNewPrivileges=true

[Install]
WantedBy=multi-user.target

d. My complete Caddy config:

{
  "apps": {
    "http": {
      "servers": {
        "metrics": {
          "listen":[":2020"],
          "routes":[
            {
              "handle":[
                {
                  "handler":"metrics"
                }
              ]
            }
          ]
        },
        "apps": {...}
      }
    }
  }
}

You need to enable metrics on the HTTP server as well. See apps/http/servers/metrics. You just need to set it to an empty object.

In an earlier version, Caddy always had metrics enabled, but we realized it caused some significant performance problems due to problems with the implementation so we just shifted it to being opt-in for the HTTP app, since we don’t have the expertise to maintain the metrics code right now, unfortunately.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.