Yesterday I whipped a small daemon that publishes a seconds-until countdown metric to statsd: ngerakines/countdown-metrics-rs

There are lots of use cases, but the one I have is pretty simple: Tracking API key expiration. I have a handful of API keys and auth tokens that expire every 90 days. I want to know when they’re going to expire so I can rotate them. I also want to be able to share this information and make it easy for other people to both contribute to the rotation process and also track their own or other shared events.

One low-tech solution is to create a shared calendar and add events for each expiration. This is an OK solution for a small number of events, but it’s not great for a large number of events. It also requires a certain amount of overhide and time. To make a calendar useful, you need to set time aside to look at it periodically and on a regular basis. Personally, I’d rather be notified when something is about to expire.

With ngerakines/countdown-metrics-rs you use environment variables for configuration. The COUNTDOWNS_ environment variable prefix is used to create unique entries. Each environment variable that starts with that prefix has a simple RFC3339 date as the value. For example, if I wanted to track the expiration of a GitHub access token, I would use the following environment variable:

COUNTDOWNS_gh_pat=2023-04-20T08:05:18-04:00

The gauge metric countdown is then updated every several seconds with the number of seconds until the expiration date. The value is a simple integer, so that means that creating 10, 4, and 1 day alerts is as simple as comparing the value against 864000, 345600, and 86400.

This project is open source under the MIT license. Pull requests and feedback is welcome. The current release is v1.1.1 and it is available at all of the usual places: