Fail2ban Prometheus Exporter

${ Go tool to collect and export metrics on Fail2Ban }
2021-02-05

This is a small exporter project to collect various metrics on how fail2ban is running. The goal being to have that data available in Grafana to generate graphs and fire off alerts.

Metrics are collected using the same mechanism the fail2ban-client uses to connect to the fail2ban-server - a unix socket. This ensures metrics are always consistent with the output of the fail2ban-client.

Writing the code for this was a little tricky because I chose to read data directly from the socket instead of doing something like reading the output from the CLI.

But reading the data from the socket was challenging because the data is encoded using Python’s Pickle format, but my tool is written in Go. Fortunately I found a good Go library to help a lot with this! (go-pickle)

But doing it this way allows the exporter to run inside a docker container by just mounting the fail2ban-server socket into that container.


Read the project documentation for instructions on how to set it up!