eko / pihole-exporter

A Prometheus exporter for PI-Hole's Raspberry PI ad blocker
MIT License
924 stars 106 forks source link

Scraping multiple endpoints not clear using multiple piholes. #116

Open jobenvil opened 2 years ago

jobenvil commented 2 years ago

Asumming that:

docker run -d -i \
    --restart=unless-stopped \
    --name pihole-exporter-4-all \
    -e 'PIHOLE_HOSTNAME="192.168.178.70,192.168.178.80,192.168.178.120"' \
    -e 'PIHOLE_API_TOKEN=jkdfjösdahföjhasdöfhöasdjfhöasjdfhöjasdhföjhasdöfjhasödfhöasjdfh' \
    -e 'INTERVAL=30s' \
    -e 'PORT=9617' \
    -e 'PIHOLE_PORT=9000' \
    -e 'PIHOLE_PROTOCOL=http' \
    -p 9617:9617 \
    ekofr/pihole-exporter:v0.1.1

How I query the metrics behind for the three piholes 192.168.178.70, 192.168.178.80, 192.168.178.120 ?

I just know curl 192.168.178.70:9617/metrics what is performed by prometheus but doing that I'm just getting the first host metrics certainly.

Using linux amd64.

rowansmithau commented 2 years ago

i went looking for this info as well, but i am running via cli/systemd, sharing for others benefit

./pihole_exporter -pihole_hostname 192.168.1.1,192.168.1.2 -pihole_api_token 0fb7661d28e233fa7c3626cbc3f69c63df078466696e901c6cc836d35f01eb56,0fb7661d28e233fa7c3626cbc3f69c63df024466696e901c6cc365d35f01eb56

use a comma to separate the ip's/hostnames, and then also a comma to separate api token

jobenvil commented 2 years ago

Do you expose then one (i.e. 9617) or two listening ports(i.e. 9617,9618)? (in docker with -e 'PORT=9617' \ or -e 'PORT=9617,9618' \ ) later on, on same docker run command making accessible ports for the host -p 9617:9617 \ or -p 9617:9617 -p 9618:9618 \)

rowansmithau commented 2 years ago

I'm not using docker, I built from source and run the app via systemd and use one instance to connect to two piholes. In Prometheus I only have one data source configured, so I expect the same logic would apply for docker, i.e. just 9617

jobenvil commented 2 years ago

Exactly, that was the point I want to clarify. If you have configured just one data source, how looks like the aggregation for the metrics (curl http://localhost:9167/metrics) which is ingested by prometheus?

Example with just one port and hostname:

...
...
# TYPE pihole_querytypes gauge
pihole_querytypes{hostname="192.168.178.70",type="A (IPv4)"} 99.28
pihole_querytypes{hostname="192.168.178.70",type="AAAA (IPv6)"} 0
pihole_querytypes{hostname="192.168.178.70",type="ANY"} 0
pihole_querytypes{hostname="192.168.178.70",type="DNSKEY"} 0
pihole_querytypes{hostname="192.168.178.70",type="DS"} 0
pihole_querytypes{hostname="192.168.178.70",type="HTTPS"} 0
pihole_querytypes{hostname="192.168.178.70",type="MX"} 0
pihole_querytypes{hostname="192.168.178.70",type="NAPTR"} 0
pihole_querytypes{hostname="192.168.178.70",type="NS"} 0
pihole_querytypes{hostname="192.168.178.70",type="OTHER"} 0
pihole_querytypes{hostname="192.168.178.70",type="PTR"} 0.12
pihole_querytypes{hostname="192.168.178.70",type="RRSIG"} 0
pihole_querytypes{hostname="192.168.178.70",type="SOA"} 0
pihole_querytypes{hostname="192.168.178.70",type="SRV"} 0.6
pihole_querytypes{hostname="192.168.178.70",type="SVCB"} 0
pihole_querytypes{hostname="192.168.178.70",type="TXT"} 0
...
...
promhttp_metric_handler_requests_total{code="200"} 25124
promhttp_metric_handler_requests_total{code="500"} 0
promhttp_metric_handler_requests_total{code="503"} 0

Thanks.

rowansmithau commented 2 years ago

it looks exactly like your example, the hostname is included which is how grafana then separates it. you get two sets of results, one for each hostname/ip:

~% curl -s localhost:9617/metrics | grep pihole_querytypes
# HELP pihole_querytypes This represent the number of queries made by PI-Hole by type
# TYPE pihole_querytypes gauge
pihole_querytypes{hostname="192.168.50.20",type="A (IPv4)"} 39.94
pihole_querytypes{hostname="192.168.50.20",type="AAAA (IPv6)"} 38.06
pihole_querytypes{hostname="192.168.50.20",type="ANY"} 0
pihole_querytypes{hostname="192.168.50.20",type="DNSKEY"} 0.78
pihole_querytypes{hostname="192.168.50.20",type="DS"} 3.81
pihole_querytypes{hostname="192.168.50.20",type="HTTPS"} 1.85
pihole_querytypes{hostname="192.168.50.20",type="MX"} 0.06
pihole_querytypes{hostname="192.168.50.20",type="NAPTR"} 0
pihole_querytypes{hostname="192.168.50.20",type="NS"} 0.3
pihole_querytypes{hostname="192.168.50.20",type="OTHER"} 0
pihole_querytypes{hostname="192.168.50.20",type="PTR"} 12.9
pihole_querytypes{hostname="192.168.50.20",type="RRSIG"} 0
pihole_querytypes{hostname="192.168.50.20",type="SOA"} 0.1
pihole_querytypes{hostname="192.168.50.20",type="SRV"} 0.18
pihole_querytypes{hostname="192.168.50.20",type="SVCB"} 0
pihole_querytypes{hostname="192.168.50.20",type="TXT"} 2.01
pihole_querytypes{hostname="192.168.50.21",type="A (IPv4)"} 38.38
pihole_querytypes{hostname="192.168.50.21",type="AAAA (IPv6)"} 39.01
pihole_querytypes{hostname="192.168.50.21",type="ANY"} 0
pihole_querytypes{hostname="192.168.50.21",type="DNSKEY"} 0.85
pihole_querytypes{hostname="192.168.50.21",type="DS"} 4.35
pihole_querytypes{hostname="192.168.50.21",type="HTTPS"} 8.63
pihole_querytypes{hostname="192.168.50.21",type="MX"} 0.07
pihole_querytypes{hostname="192.168.50.21",type="NAPTR"} 0
pihole_querytypes{hostname="192.168.50.21",type="NS"} 1.14
pihole_querytypes{hostname="192.168.50.21",type="OTHER"} 0
pihole_querytypes{hostname="192.168.50.21",type="PTR"} 6.24
pihole_querytypes{hostname="192.168.50.21",type="RRSIG"} 0
pihole_querytypes{hostname="192.168.50.21",type="SOA"} 0.22
pihole_querytypes{hostname="192.168.50.21",type="SRV"} 0.15
pihole_querytypes{hostname="192.168.50.21",type="SVCB"} 0
pihole_querytypes{hostname="192.168.50.21",type="TXT"} 0.97