Wednesday, November 29, 2023

Prometheus and Grafana : Monitor BIND DNS server

 1.Pre-requisites
- BIND need to have been build with libxml2 support
# named -V | grep libxml2

2.Installed Bind Prometheus Exporter
-
Download the latest release of bind_exporter binary:

# curl -s https://api.github.com/repos/prometheus-community/bind_exporter/releases/latest | grep browser_download_url | grep linux-amd64 |  cut -d '"' -f 4 | wget -qi -
# tar xvf bind_exporter*.tar.gz
# sudo mv bind_exporter-*/bind_exporter /usr/local/bin
# bind_exporter --version

3. Configure BIND to open a statistics channel
- Edit the file /etc/named.conf to add

statistics-channels {
  inet 127.0.0.1 port 8053 allow { 127.0.0.1; };
};

4.Create Bind Exporter systemd service
- Add Prometheus system user account:
#sudo groupadd --system prometheus
#sudo useradd -s /sbin/nologin --system -g prometheus prometheus

- Create a systemd service unit file:
sudo tee /etc/systemd/system/bind_exporter.service<<EOF
[Unit]
Description=Prometheus
Documentation=https://github.com/digitalocean/bind_exporter
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=prometheus
Group=prometheus
ExecReload=/bin/kill -HUP \$MAINPID
ExecStart=/usr/local/bin/bind_exporter \
  --bind.pid-file=/var/run/named/named.pid \
  --bind.timeout=20s \
  --web.listen-address=0.0.0.0:9153 \
  --web.telemetry-path=/metrics \
  --bind.stats-url=http://localhost:8053/ \
  --bind.stats-groups=server,view,tasks

SyslogIdentifier=prometheus
Restart=always

[Install]
WantedBy=multi-user.target
EOF

- Reload systemd and start bind_exporter service
#sudo systemctl daemon-reload
#sudo systemctl restart bind_exporter.service

- Enable the service to start on boot:
#sudo systemctl enable bind_exporter.service

- Open the port on the firewall
#sudo firewall-cmd --add-port=9153/tcp --permanent
#sudo firewall-cmd --reload

5.Configure Prometheus Server
- Edit file prometheus.yml
#sudo vi /etc/prometheus/prometheus.yml

- Add the jobs definition

- job_name: dns-master
    static_configs:
      - targets: ['10.1.5.3:9153']
        labels:
          alias: dns-master

  - job_name: dns-slave1
    static_configs:
      - targets: ['10.1.5.4:9153']
        labels:
          alias: dns-slave

#sudo systemctl restart prometheus

6. Add Grafana Dashboard
- Use already created Grafana dashboard ID is 1666
- Import Bind Grafana Dashboard by navigating to Dashboard > Import

source : https://computingforgeeks.com/monitor-bind-dns-server-with-prometheus-grafana/?expand_article=1

Related Posts:

0 comments:

Post a Comment