caddy-ratelimit icon indicating copy to clipboard operation
caddy-ratelimit copied to clipboard

Thoughts about metrics for the module

Open malyusha opened this issue 9 months ago • 2 comments

First of all - thanks for the module, it definitely makes life easier!

I'm going to use this module at a custom caddy build with some modifications. I've noticed that the module is missing metrics, thus I'm currently considering two options:

  1. Fork the module and customize it for our needs
  2. Create a PR with metrics implemented

Would really appreciate it if you could check on some metrics below. Some of them may be unnecessary, or maybe you could add some more. Thanks in advance!

The metrics I'd like to add are:

rate_limit_declined_requests_total

Total number of requests for which rate limit was applied (Declined with HTTP 429 status code returned).

Type

Gauge

Labels

  • zone - Zone name
  • key (optional) - The key of rate limited requests

rate_limit_requests_total

Total number of requests that passed through Rate Limit module (both declined & processed).

Type

Gauge

Labels

  • has_zone - Whether request matched any zone or not.

rate_limit_process_time_seconds

A time taken to process rate limiting for each request. (I don't know whether we can use default Caddy module metrics here.)

Type

Histogram

Labels

  • has_zone - Whether request matched any zone or not.

rate_limit_keys_total

Total number of keys that each RL zone contains. (This metric is collected in the background for each zone.)

Type

Gauge

Labels

  • zone - Zone name

rate_limit_config

Shows configuration of the rate limiter module. Reported only once on bootstrap as configuration is not dynamically configurable.

Type

Counter

Labels

  • zone - Zone name
  • max_events - Max events allowed for a key in zone
  • window - Time window of the zone for a specific key.

malyusha avatar Mar 17 '25 08:03 malyusha

Thanks for bringing this up! I would be happy to add metrics, but I just don't know how. 😅

Would you like to submit a PR?

I'm hoping they will integrate with the existing Caddy metrics that we already emit.

mholt avatar Mar 17 '25 13:03 mholt

@mholt Thanks for the quick response!

Yep, I'll try to create a PR soon

malyusha avatar Mar 17 '25 14:03 malyusha