Grafana, Prometheus, and AdGuardHome DNS, using Docker.

Technology

Goal

To use my existing Grafana instance to visual data from AdguardHome DNS which uses a Prometheus database for metric storage and the AdguardExporter software application which scrapes the Adguard API and pushes the data to Prometheus.

The order the components are set up aren’t important but it makes sense to setup the database before setting up the exporter that populates it or the Grafana instance that consumes the Prometheus database.

Prometheus

Prometheus is an open-source systems monitoring and alerting toolkit originally built at SoundCloud. Since its inception in 2012, many companies and organizations have adopted Prometheus, and the project has a very active developer and user community. It is now a standalone open source project and maintained independently of any company.

https://prometheus.io/docs/introduction/overview

Links

  • Prometheus Installation using Docker
    • The above is the documentation on doing so from the Prometheus folks.
    • We are using docker but will be using the simplest approach; What we will do should not be used for a production environment and is meant for learning purposes.
  • Prometheus Docker Image on DockerHub: prom/prometheus

Running the docker Prometheus container

docker run --name prometheus -d -p 9090:9090 prom/prometheus

Update Prometheus configuration to scrape the AdGuard exporter

Update the prometheus.yaml configuration the container is using. In this example, update the file inside the container.

To create a shell in the container:

sudo docker exec -it prometheus sh

The path to Prometheus configuration file in the container is: /etc/prometheus/prometheus.yaml.

Add the adguard job_name to the scrape_configs section and the scrape target (AdguardExporter in this this case.) to the static_configs

scrape_configs:
  - job_name: 'adguard'
  static_configs:
  - targets: ['192.168.2.221:9617']

Then restart the container when you’re ready to have to scraping populate the database.

sudo docker container restart prometheus

A full example of a default prometheus.yaml with the above updates for AdguardExporter.

# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'
  - job_name: 'adguard'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9090']
    - targets: ['192.168.2.221:9617']

Grafana

Grafana® allows you to query, visualize, alert on and understand your metrics no matter where they are stored. Create, explore, and share dashboards with your team and foster a data driven culture.

https://grafana.com/grafana/

Grafana Adguard Dashboard

-Dashboard ID: 13330

AdGuard Exporter

Prometheus exporter for AdguardHome’s Raspberry PI ad blocker. It is based on the famous pihole-exporter.

AdGuard Exporter | Github

Using Docker The exporter has been made available as a docker image. You can simply run it by the following command and pass the configuration with environment variables.

Note the:

-e 'adguard_port=' \ #optional if adguard is not using port 80 (http)/443 (https)

No need to include it if you’re using the default ports, set it accordingly if not.

docker run \
-e 'adguard_protocol=http' \
-e 'adguard_hostname=ADGUARD_SERVER_NAME_OR_IP_GOES_HERE' \
-e 'adguard_username=ADGUARD_USERNAME_GOES_HERE' \
-e 'adguard_password=ADGUARD_PASSWORD_GOES_HERE' \
-e 'adguard_port=' \ #optional if adguard is not using port 80 (http)/443 (https)
-e 'interval=10s' \
-e 'log_limit=10000' \
-e 'server_port=9617' \
-p 9617:9617 \
--name adguard-exporter \
-d \
ebrianne/adguard-exporter:latest