- 首先編譯bind_exporter,編譯方式參見bind_exporter
- 創建一個systemd配置文件來運行bind_exporter
vi /etc/systemd/system/bind_exporter.service
內容如下,注意此處的用戶和組使用與named程序相同的用戶和組“named”。--web.listen-address為對外暴露的metric地址和端口,Prometheus從此處抓取bind_exporter的metrics;--bind.stats-url為本地bind服務綁定的地址和IP
[Unit] Description=bind_exporter Documentation=https://github.com/digitalocean/bind_exporter Wants=network-online.target After=network-online.target [Service] Type=simple User=named Group=named ExecReload=/bin/kill -HUP $MAINPID ExecStart=/opt/bind_exporter/bind_exporter \ --bind.pid-file=/var/run/named/named.pid \ --bind.timeout=20s \ --web.listen-address=0.0.0.0:9119 \ --web.telemetry-path=/metrics \ --bind.stats-url=http://localhost:53/ \ --bind.stats-groups=server,view,tasks SyslogIdentifier=bind_exporter Restart=always [Install] WantedBy=multi-user.target
- 加載並啟動bind_export
systemctl daemon-reload
systemctl restart bind_exporter.service
- 在/etc/named.conf中添加如下內容,注意“statistics-channels”是與“options”並列的,而不是位於“options”內部
statistics-channels { inet 127.0.0.1 port 53 allow { 127.0.0.1; }; };
重新啟動named
service named restart
- 在Prometheus的yml文件中添加如下job,重新啟動Prometheus即可
- job_name: dns-master static_configs: - targets: ['10.85.6.66:9119'] labels: alias: dns-master
在Prometheus的targets中可以看到新加的內容
可以通過“curl http://10.85.6.66:9119/metrics”來獲取bind_exporter支持的metrics以及方法,最常用的方法為“bind_up”,用於查看一個bind服務是否啟動,值1表示啟動成功
參考:
https://grafana.com/dashboards/1666
https://computingforgeeks.com/how-to-monitor-bind-dns-server-with-prometheus-and-grafana/