This is a script written in Python intended to run alongside a certbot instance and export statistics for monitoring purposes. It assumes the existence of certbot in the PATH plus read access to /etc/letsencrypt
.
It tracks stuff like: number of certs, number of SANs, expiry time, seconds until expiry, and the status of the certificate per ACME.
Prometheus is a monitoring system and time-series database.
It works by pulling or scraping numerical metrics from an HTTP endpoint (or "exporter"), and then ingesting and keeping track of them over time. You can then build queries and alerting rules from this data.
An exporter set up as a scrape target may be local or remote. Prometheus is a great backend for a visualization and analytics software such as Grafana.
To see it in action, run certbot_exporter.py
and navigate to http://127.0.0.1:8556 in your browser.
Ensure that prometheus_client
is installed via pip.
I'd also recommend running this persistently as a systemd service. For example:
[Unit]
Description=certbot Prometheus exporter
After=network.target certbot.service
[Service]
ExecStart=/usr/bin/python3 /usr/local/bin/certbot_exporter.py
KillMode=process
User=nobody
Group=nobody
Restart=on-failure
[Install]
WantedBy=multi-user.target
``
Thanks for sharing!
There is a little logic failure in the exporter script. The while loop in line 81 will never stop sleeping. Once certbot has rotated a certificate it will never report the new expiry date.