This repository provides code for a simple Prometheus metrics exporter for the Unbound DNS resolver.
This exporter connects to Unbounds control socket and sends the stats_noreset command, causing Unbound to return metrics as key-value pairs.
The metrics exporter converts Unbound metric names to Prometheus metric names and labels by using a set of regular expressions and AWK.
It does the same job as unbound_exporter by Let’s Encrypt, but using a very simple shell script, AWK and any web server with CGI support. If you use some tiny web server, you can get to less than 200 kiB on disk (and negligible memory usage) instead of 10 MiB unbound_exporter Go bloat.
The metrics are the same as produced by unbound_exporter, but without the thread label (it’s not a problem to implement it, I just find it unnecessary).
This means that you can use the same Grafana dashboards as with unbound_exporter.
First you need to enable Unbound remote-control interface. If you want a more detailed statistics, also enable extended-statistics.
server:
extended-statistics: yes
statistics-cumulative: no
remote-control:
control-enable: yes
control-interface: /run/unbound.control.sockThen use a web server that supports CGI 1.1 (e.g. thttpd, OpenWrt’s uhttpd, BusyBox httpd, Apache HTTP server) and let it serve metrics.cgi. Make sure that the web server (or dedicated user) running this script can access the control socket (/run/unbound.control.sock).
It can also be run as a standalone script (it’s a shell script after all).
thttpd is a tiny (just 120 kiB) and relatively fast HTTP server with CGI 1.1 support. It’s not a full-fledged web server, such as nginx or Apache HTTP server, but if you want to just run a simple CGI script accessible only from a private monitoring network, it’s a great choice.
-
Install
thttpdfrom your distro’s repository (see where’s available) or compile it yourself. -
Create a dedicated user for thttpd (e.g.
thttpd), if you don’t have it already. -
Add
thttpduser to theunboundgroup so it can access the control socket. -
Copy metrics.cgi to e.g.
/var/www/cgi-bin/thttpd, rename it tometricsand make it executable. -
Run
thttpd -p 9167 -d /var/www/cgi-bin/thttpd -u thttpd -c '*'(you should use an init script or unit file provided by your distribution though).
This project is licensed under MIT License. For the full text of the license, see the LICENSE file.