2019-05-08 23:45:04 +02:00
# PI-Hole Prometheus Exporter
2020-05-05 14:24:41 +02:00
![Build/Push (master) ](https://github.com/eko/pihole-exporter/workflows/Build/Push%20(master )/badge.svg)
2019-05-09 11:28:35 +02:00
[![GoDoc ](https://godoc.org/github.com/eko/pihole-exporter?status.png )](https://godoc.org/github.com/eko/pihole-exporter)
[![GoReportCard ](https://goreportcard.com/badge/github.com/eko/pihole-exporter )](https://goreportcard.com/report/github.com/eko/pihole-exporter)
2019-05-08 23:45:04 +02:00
This is a Prometheus exporter for [PI-Hole ](https://pi-hole.net/ )'s Raspberry PI ad blocker.
2019-05-09 21:31:16 +02:00
![Grafana dashboard ](https://raw.githubusercontent.com/eko/pihole-exporter/master/dashboard.jpg )
2019-06-01 12:48:33 +02:00
Grafana dashboard is [available here ](https://grafana.com/dashboards/10176 ) on the Grafana dashboard website and also [here ](https://raw.githubusercontent.com/eko/pihole-exporter/master/grafana/dashboard.json ) on the GitHub repository.
2019-05-09 21:49:34 +02:00
2019-05-08 23:45:04 +02:00
## Prerequisites
* [Go ](https://golang.org/doc/ )
## Installation
2019-05-09 11:28:35 +02:00
### Download binary
2019-05-09 21:31:16 +02:00
You can download the latest version of the binary built for your architecture here:
2019-05-09 11:28:35 +02:00
* Architecture **i386** [
[Linux ](https://github.com/eko/pihole-exporter/releases/latest/download/pihole_exporter-linux-386 ) /
[Windows ](https://github.com/eko/pihole-exporter/releases/latest/download/pihole_exporter-windows-386.exe )
]
* Architecture **amd64** [
[Darwin ](https://github.com/eko/pihole-exporter/releases/latest/download/pihole_exporter-darwin-amd64 ) /
[Linux ](https://github.com/eko/pihole-exporter/releases/latest/download/pihole_exporter-linux-amd64 ) /
[Windows ](https://github.com/eko/pihole-exporter/releases/latest/download/pihole_exporter-windows-amd64.exe )
]
* Architecture **arm** [
2020-12-31 08:53:26 +01:00
[Darwin ](https://github.com/eko/pihole-exporter/releases/latest/download/pihole_exporter-darwin-arm64 ) /
2019-05-09 11:28:35 +02:00
[Linux ](https://github.com/eko/pihole-exporter/releases/latest/download/pihole_exporter-linux-arm )
]
2019-05-26 10:49:58 +02:00
### Using Docker
The exporter is also available as a [Docker image ](https://hub.docker.com/r/ekofr/pihole-exporter ).
You can run it using the following example and pass configuration environment variables:
```
2019-05-28 21:57:52 +02:00
$ docker run \
-e 'PIHOLE_HOSTNAME=192.168.1.2' \
-e 'PIHOLE_PASSWORD=mypassword' \
2019-07-17 08:25:43 +02:00
-e 'PORT=9617' \
2020-04-11 15:43:47 +02:00
-p 9617:9617 \
2019-05-28 21:57:52 +02:00
ekofr/pihole-exporter:latest
2019-05-26 10:49:58 +02:00
```
2020-04-07 00:31:30 +02:00
Or use PiHole's `WEBPASSWORD` as an API token instead of the password
```bash
$ API_TOKEN=$(awk -F= -v key="WEBPASSWORD" '$1==key {print $2}' /etc/pihole/setupVars.conf)
$ docker run \
-e 'PIHOLE_HOSTNAME=192.168.1.2' \
2020-04-27 00:38:28 +02:00
-e "PIHOLE_API_TOKEN=$API_TOKEN" \
2020-04-07 00:31:30 +02:00
-e 'PORT=9617' \
ekofr/pihole-exporter:latest
```
2020-06-06 00:03:29 +02:00
If you are running pi-hole behind https, you must both set the `PIHOLE_PROTOCOL` environment variable
as well as include your ssl certificates to the docker image as it does not have any baked in:
```
$ docker run \
-e 'PIHOLE_PROTOCOL=https' \
-e 'PIHOLE_HOSTNAME=192.168.1.2' \
-e 'PIHOLE_PASSWORD=mypassword' \
-e 'PORT=9617' \
-v '/etc/ssl/certs:/etc/ssl/certs:ro' \
-p 9617:9617 \
ekofr/pihole-exporter:latest
```
2021-12-18 00:25:23 +01:00
A single instance of pihole-exporter can monitor multiple pi-holes instances.
To do so, you can specify a list of hostnames, protocols, passwords/API tokens and ports by separating them with commas in their respective environment variable:
```
$ docker run \
-e 'PIHOLE_PROTOCOL="http,http,http" \
-e 'PIHOLE_HOSTNAME="192.168.1.2,192.168.1.3,192.168.1.4"' \
-e "PIHOLE_API_TOKEN="$API_TOKEN1,$API_TOKEN2,$API_TOKEN3" \
-e "PIHOLE_PORT="8080,8081,8080" \
-e 'PORT=9617' \
ekofr/pihole-exporter:latest
```
If port, protocol and API token/password is the same for all instances, you can specify them only once:
```
$ docker run \
-e 'PIHOLE_PROTOCOL=",http" \
-e 'PIHOLE_HOSTNAME="192.168.1.2,192.168.1.3,192.168.1.4"' \
-e "PIHOLE_API_TOKEN="$API_TOKEN" \
-e "PIHOLE_PORT="8080" \
-e 'PORT=9617' \
ekofr/pihole-exporter:latest
```
2019-05-09 21:11:31 +02:00
### From sources
2019-05-09 21:31:16 +02:00
Optionally, you can download and build it from the sources. You have to retrieve the project sources by using one of the following way:
2019-05-09 21:11:31 +02:00
```bash
$ go get -u github.com/eko/pihole-exporter
# or
$ git clone https://github.com/eko/pihole-exporter.git
```
2019-05-26 10:49:58 +02:00
Install the needed vendors:
```
$ GO111MODULE=on go mod vendor
```
2019-05-09 21:11:31 +02:00
Then, build the binary (here, an example to run on Raspberry PI ARM architecture):
```bash
$ GOOS=linux GOARCH=arm GOARM=7 go build -o pihole_exporter .
```
2019-05-08 23:45:04 +02:00
## Usage
In order to run the exporter, type the following command (arguments are optional):
2020-04-07 00:31:30 +02:00
Using a password
2019-05-08 23:45:04 +02:00
```bash
$ ./pihole_exporter -pihole_hostname 192.168.1.10 -pihole_password azerty
2020-04-07 00:31:30 +02:00
```
Or use PiHole's `WEBPASSWORD` as an API token instead of the password
2019-05-09 11:28:35 +02:00
2020-04-07 00:31:30 +02:00
```bash
$ API_TOKEN=$(awk -F= -v key="WEBPASSWORD" '$1==key {print $2}' /etc/pihole/setupVars.conf)
2020-04-27 00:38:28 +02:00
$ ./pihole_exporter -pihole_hostname 192.168.1.10 -pihole_api_token $API_TOKEN
2020-04-07 00:31:30 +02:00
```
```bash
2019-05-09 21:11:31 +02:00
2019/05/09 20:19:52 ------------------------------------
2019/05/09 20:19:52 - PI-Hole exporter configuration -
2019/05/09 20:19:52 ------------------------------------
2019/05/09 20:19:52 PIHoleHostname : 192.168.1.10
2019/05/09 20:19:52 PIHolePassword : azerty
2019-07-17 08:25:43 +02:00
2019/05/09 20:19:52 Port : 9617
2022-01-05 22:07:23 +01:00
2019/05/09 20:19:52 Timeout : 5s
2019-05-09 21:11:31 +02:00
2019/05/09 20:19:52 ------------------------------------
2019/05/09 20:19:52 New Prometheus metric registered: domains_blocked
2019/05/09 20:19:52 New Prometheus metric registered: dns_queries_today
2019/05/09 20:19:52 New Prometheus metric registered: ads_blocked_today
2019/05/09 20:19:52 New Prometheus metric registered: ads_percentag_today
2019/05/09 20:19:52 New Prometheus metric registered: unique_domains
2019/05/09 20:19:52 New Prometheus metric registered: queries_forwarded
2019/05/09 20:19:52 New Prometheus metric registered: queries_cached
2019/05/09 20:19:52 New Prometheus metric registered: clients_ever_seen
2019/05/09 20:19:52 New Prometheus metric registered: unique_clients
2019/05/09 20:19:52 New Prometheus metric registered: dns_queries_all_types
2019/05/09 20:19:52 New Prometheus metric registered: reply
2019/05/09 20:19:52 New Prometheus metric registered: top_queries
2019/05/09 20:19:52 New Prometheus metric registered: top_ads
2019/05/09 20:19:52 New Prometheus metric registered: top_sources
2019/05/09 20:19:52 New Prometheus metric registered: forward_destinations
2019/05/09 20:19:52 New Prometheus metric registered: querytypes
2019/05/09 20:19:52 New Prometheus metric registered: status
2019/05/09 20:19:52 Starting HTTP server
2019/05/09 20:19:54 New tick of statistics: 648 ads blocked / 66796 total DNS querie
2019-05-09 11:28:35 +02:00
...
2019-05-08 23:45:04 +02:00
```
2019-05-10 14:44:04 +02:00
Once the exporter is running, you also have to update your `prometheus.yml` configuration to let it scrape the exporter:
```yaml
scrape_configs:
- job_name: 'pihole'
static_configs:
2019-07-17 08:25:43 +02:00
- targets: ['localhost:9617']
2019-05-10 14:44:04 +02:00
```
2019-05-09 21:11:31 +02:00
## Available CLI options
2019-05-08 23:45:04 +02:00
```bash
2022-01-05 22:07:23 +01:00
# Hostname of the host(s) where PI-Hole is installed
2019-05-08 23:45:04 +02:00
-pihole_hostname string (optional) (default "127.0.0.1")
# Password defined on the PI-Hole interface
-pihole_password string (optional)
2022-01-05 22:07:23 +01:00
# Timeout to connect and retrieve data from a Pi-Hole instance
-timeout duration (optional) (default 5s)
2020-04-07 00:31:30 +02:00
# WEBPASSWORD / api token defined on the PI-Hole interface at `/etc/pihole/setupVars.conf`
2020-04-27 00:38:28 +02:00
-pihole_api_token string (optional)
2020-04-07 00:31:30 +02:00
2019-05-08 23:45:04 +02:00
# Port to be used for the exporter
2019-07-17 08:25:43 +02:00
-port string (optional) (default "9617")
2019-05-08 23:45:04 +02:00
```
2019-05-09 21:11:31 +02:00
## Available Prometheus metrics
| Metric name | Description |
|:----------------------------:|-------------------------------------------------------------------------------------------|
| pihole_domains_being_blocked | This represent the number of domains being blocked |
| pihole_dns_queries_today | This represent the number of DNS queries made over the current day |
| pihole_ads_blocked_today | This represent the number of ads blocked over the current day |
| pihole_ads_percentage_today | This represent the percentage of ads blocked over the current day |
| pihole_unique_domains | This represent the number of unique domains seen |
| pihole_queries_forwarded | This represent the number of queries forwarded |
| pihole_queries_cached | This represent the number of queries cached |
| pihole_clients_ever_seen | This represent the number of clients ever seen |
| pihole_unique_clients | This represent the number of unique clients seen |
| pihole_dns_queries_all_types | This represent the number of DNS queries made for all types |
| pihole_reply | This represent the number of replies made for all types |
| pihole_top_queries | This represent the number of top queries made by PI-Hole by domain |
| pihole_top_ads | This represent the number of top ads made by PI-Hole by domain |
| pihole_top_sources | This represent the number of top sources requests made by PI-Hole by source host |
| pihole_forward_destinations | This represent the number of forward destinations requests made by PI-Hole by destination |
| pihole_querytypes | This represent the number of queries made by PI-Hole by type |
| pihole_status | This represent if PI-Hole is enabled |
2019-11-01 17:04:00 +01:00
2019-11-03 10:53:37 +01:00
## Pihole-Exporter Helm Chart
2019-11-01 17:04:00 +01:00
[Link ](https://github.com/SiM22/pihole-exporter-helm-chart )
This is a simple Helm Chart to deploy the exporter in a kubernetes cluster.