Caddy /metrics gives 404

1. Caddy version (caddy version):

v2.1.1 h1:X9k1+ehZPYYrSqBvf/ocUgdLSRIuiNiMo7CvyGUQKeA=

2. How I run Caddy:

a. System environment:

Ubuntu 20.04

b. Command:

curl localhost:2020/load -H 'Content-Type: application/json' -H 'Origin: 54.190.94.186' -d @final_with_headers.json

c. Service/unit/compose file:

Paste full file contents here.
Make sure backticks stay on their own lines,
and the post looks nice in the preview pane.

d. My complete Caddyfile or JSON config:

{
    "admin": {
        "disabled": false,
        "enforce_origin": true,
        "listen": ":2020",
        "origins": [
            "localhost:2020",
            "1.2.3.4"
        ]
    },
    "apps": {
        "http": {
            "servers": {
                "srv0": {
                    "listen": [
                        ":443"
                    ],
                    "routes": [
                        {
                            "handle": [
                                {
                                    "handler": "headers",
                                    "response": {
                                        "set": {
                                            "Referrer-Policy": [
                                                "same-origin"
                                            ],
                                            "X-Content-Type-Options": [
                                                "nosniff"
                                            ],
                                            "X-Frame-Options": [
                                                "DENY"
                                            ],
                                            "X-Xss-Protection": [
                                                "1; mode=block"
                                            ]
                                        }
                                    }
                                },
                                {
                                    "handler": "subroute",
                                    "routes": [
                                        {
                                            "handle": [
                                                {
                                                    "handler": "vars",
                                                    "root": "/var/www/html/webapp/"
                                                }
                                            ]
                                        },
                                        {
                                            "handle": [
                                                {
                                                    "handler": "rewrite",
                                                    "uri": "{http.matchers.file.relative}"
                                                }
                                            ],
                                            "match": [
                                                {
                                                    "file": {
                                                        "try_files": [
                                                            "{http.request.uri.path}",
                                                            "{http.request.uri.path}/",
                                                            "/index.html"
                                                        ]
                                                    }
                                                }
                                            ]
                                        },
                                        {
                                            "handle": [
                                                {
                                                    "encodings": {
                                                        "gzip": {},
                                                        "zstd": {}
                                                    },
                                                    "handler": "encode"
                                                },
                                                {
                                                    "handler": "file_server",
                                                    "hide": [
                                                        "Caddyfile"
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            }
        },
        "tls": {
            "automation": {
                "on_demand": {
                    "ask": "https://example.io/custom-domain/ssl-allowed/"
                },
                "policies": [
                    {
                        "on_demand": true
                    }
                ]
            }
        }
    }
}

3. The problem I’m having:

I want to setup metrics with Prometheus and Grafana. When I try to access the metrics using the following endpoint

curl localhost:2020/metrics -H 'Origin: 1.2.3.4'

It gives 404 error

4. Error messages and/or full log output:

404 page not found

5. What I already tried:

6. Links to relevant resources:

As per the caddy documentation, /metrics endpoint is default exposed

That’s a super old version. Please upgrade to the latest, v2.4.3. Your version is from before metrics support was added to Caddy, which was in v2.2.0.

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