Caddy and support for Datadog or statsd

I’d like to monitor 2xx, 3xx, 4xx and 5xx responses from Caddy. In the case there is an abnormal distribution, like too many 5xx replies and the backend likely down, I’d like to raise an alert through Datadog.

I am not expert on Caddy plugin architecture. I found this old caddy-datadog plugin. My first attempt to include it was successfully complied, but I am getting:

run: adapting config using caddyfile: /etc/caddy/Caddyfile:60: unrecognized directive: datadog

… so my assumption is that maybe this plugin is for Caddy 1.x and no longer works with Caddy 2.x.

  • Is my assumption correct?
  • Or am I doing something else incorrect?
  • Are there alternative ways to get response statistics from Caddy to Datadog / stats / dogstatsd?

My Caddy configuration for caddy-datadog can be found here. My Caddy live website is here.

That’s right. Plugins for Caddy v1 are not compatible with Caddy v2.

Caddy v2 was a complete rewrite, and uses a different system for plugins.

Maybe using prometheus-style metrics? These are built-in to Caddy v2, also supporting the openmetrics format:

Quick google search brings me to this integration with Datadog, which is probably what you need:

Thank you francislavoie. With your tips, I managed to get OpenMetrics endpoint to feed to Datadog.

I am now trying to figure out how to pull 5xx reply count out from Caddy metrics.

I think this might do it, but I am not sure:

curl|grep -i caddy_http_request_duration_seconds_count
caddy_http_request_duration_seconds_count{code="200",handler="reverse_proxy",method="GET",server="srv1"} 647
caddy_http_request_duration_seconds_count{code="200",handler="subroute",method="GET",server="srv0"} 255
caddy_http_request_duration_seconds_count{code="200",handler="subroute",method="GET",server="srv1"} 1291
caddy_http_request_duration_seconds_count{code="301",handler="reverse_proxy",method="GET",server="srv1"} 2
caddy_http_request_duration_seconds_count{code="301",handler="subroute",method="GET",server="srv1"} 4
caddy_http_request_duration_seconds_count{code="304",handler="reverse_proxy",method="GET",server="srv1"} 21
caddy_http_request_duration_seconds_count{code="304",handler="subroute",method="GET",server="srv1"} 42
caddy_http_request_duration_seconds_count{code="401",handler="reverse_proxy",method="GET",server="srv1"} 1
caddy_http_request_duration_seconds_count{code="401",handler="subroute",method="GET",server="srv1"} 2
caddy_http_request_duration_seconds_count{code="404",handler="reverse_proxy",method="GET",server="srv1"} 107
caddy_http_request_duration_seconds_count{code="404",handler="reverse_proxy",method="POST",server="srv1"} 23
caddy_http_request_duration_seconds_count{code="404",handler="subroute",method="GET",server="srv1"} 143
caddy_http_request_duration_seconds_count{code="404",handler="subroute",method="POST",server="srv1"} 23
caddy_http_request_duration_seconds_count{code="500",handler="reverse_proxy",method="GET",server="srv1"} 1
caddy_http_request_duration_seconds_count{code="500",handler="subroute",method="GET",server="srv1"} 1

Would there be any way to have a human-readable label for these? I think I should be able to set srv1 to something meaningful, but I have do not know how.

My Caddyfile.

1 Like

Making some nice progress with Datadog dashboard:

1 Like

Yeah, that looks fine to me. Dashboard seems to be basically what you were looking for I guess :+1:

The server label here is the name of the “server” in the JSON config which is generated from the Caddyfile.

Basically a “server” is the port that Caddy listens on, so all “sites” (domains/hostnames) will share the same server if they’re all served on port 443 (for HTTPS).

There’s no way to change the label in the Caddyfile, and there isn’t really any benefit to do so, really. The primary utility for changing it would be if you were using JSON config directly and the config API to manipulate Caddy’s config at runtime, cause then you could name the server something consistent for your API calls to use.

You can run caddy adapt --pretty --config /path/to/Caddyfile to see what the JSON config looks like, including seeing the server labels generated.


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