2019-05-08 23:45:04 +02:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// DomainsBlocked - The number of domains being blocked by PI-Hole.
|
2019-05-09 21:11:31 +02:00
|
|
|
DomainsBlocked = prometheus.NewGaugeVec(
|
2019-05-08 23:45:04 +02:00
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "domains_being_blocked",
|
|
|
|
Namespace: "pihole",
|
|
|
|
Help: "This represent the number of domains being blocked",
|
|
|
|
},
|
2019-05-09 21:11:31 +02:00
|
|
|
[]string{"hostname"},
|
2019-05-08 23:45:04 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// DNSQueriesToday - The number of DNS requests made over PI-Hole over the current day.
|
2019-05-09 21:11:31 +02:00
|
|
|
DNSQueriesToday = prometheus.NewGaugeVec(
|
2019-05-08 23:45:04 +02:00
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "dns_queries_today",
|
|
|
|
Namespace: "pihole",
|
|
|
|
Help: "This represent the number of DNS queries made over the current day",
|
|
|
|
},
|
2019-05-09 21:11:31 +02:00
|
|
|
[]string{"hostname"},
|
2019-05-08 23:45:04 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// AdsBlockedToday - The number of ads blocked by PI-Hole over the current day.
|
2019-05-09 21:11:31 +02:00
|
|
|
AdsBlockedToday = prometheus.NewGaugeVec(
|
2019-05-08 23:45:04 +02:00
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "ads_blocked_today",
|
|
|
|
Namespace: "pihole",
|
|
|
|
Help: "This represent the number of ads blocked over the current day",
|
|
|
|
},
|
2019-05-09 21:11:31 +02:00
|
|
|
[]string{"hostname"},
|
2019-05-08 23:45:04 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// AdsPercentageToday - The percentage of ads blocked by PI-Hole over the current day.
|
2019-05-09 21:11:31 +02:00
|
|
|
AdsPercentageToday = prometheus.NewGaugeVec(
|
2019-05-08 23:45:04 +02:00
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "ads_percentage_today",
|
|
|
|
Namespace: "pihole",
|
|
|
|
Help: "This represent the percentage of ads blocked over the current day",
|
|
|
|
},
|
2019-05-09 21:11:31 +02:00
|
|
|
[]string{"hostname"},
|
2019-05-08 23:45:04 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// UniqueDomains - The number of unique domains seen by PI-Hole.
|
2019-05-09 21:11:31 +02:00
|
|
|
UniqueDomains = prometheus.NewGaugeVec(
|
2019-05-08 23:45:04 +02:00
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "unique_domains",
|
|
|
|
Namespace: "pihole",
|
|
|
|
Help: "This represent the number of unique domains seen",
|
|
|
|
},
|
2019-05-09 21:11:31 +02:00
|
|
|
[]string{"hostname"},
|
2019-05-08 23:45:04 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// QueriesForwarded - The number of queries forwarded by PI-Hole.
|
2019-05-09 21:11:31 +02:00
|
|
|
QueriesForwarded = prometheus.NewGaugeVec(
|
2019-05-08 23:45:04 +02:00
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "queries_forwarded",
|
|
|
|
Namespace: "pihole",
|
|
|
|
Help: "This represent the number of queries forwarded",
|
|
|
|
},
|
2019-05-09 21:11:31 +02:00
|
|
|
[]string{"hostname"},
|
2019-05-08 23:45:04 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// QueriesCached - The number of queries cached by PI-Hole.
|
2019-05-09 21:11:31 +02:00
|
|
|
QueriesCached = prometheus.NewGaugeVec(
|
2019-05-08 23:45:04 +02:00
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "queries_cached",
|
|
|
|
Namespace: "pihole",
|
|
|
|
Help: "This represent the number of queries cached",
|
|
|
|
},
|
2019-05-09 21:11:31 +02:00
|
|
|
[]string{"hostname"},
|
2019-05-08 23:45:04 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// ClientsEverSeen - The number of clients ever seen by PI-Hole.
|
2019-05-09 21:11:31 +02:00
|
|
|
ClientsEverSeen = prometheus.NewGaugeVec(
|
2019-05-08 23:45:04 +02:00
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "clients_ever_seen",
|
|
|
|
Namespace: "pihole",
|
|
|
|
Help: "This represent the number of clients ever seen",
|
|
|
|
},
|
2019-05-09 21:11:31 +02:00
|
|
|
[]string{"hostname"},
|
2019-05-08 23:45:04 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// UniqueClients - The number of unique clients seen by PI-Hole.
|
2019-05-09 21:11:31 +02:00
|
|
|
UniqueClients = prometheus.NewGaugeVec(
|
2019-05-08 23:45:04 +02:00
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "unique_clients",
|
|
|
|
Namespace: "pihole",
|
|
|
|
Help: "This represent the number of unique clients seen",
|
|
|
|
},
|
2019-05-09 21:11:31 +02:00
|
|
|
[]string{"hostname"},
|
2019-05-08 23:45:04 +02:00
|
|
|
)
|
|
|
|
|
2019-05-09 21:11:31 +02:00
|
|
|
// DNSQueriesAllTypes - The number of DNS queries made for all types by PI-Hole.
|
|
|
|
DNSQueriesAllTypes = prometheus.NewGaugeVec(
|
2019-05-08 23:45:04 +02:00
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "dns_queries_all_types",
|
|
|
|
Namespace: "pihole",
|
|
|
|
Help: "This represent the number of DNS queries made for all types",
|
|
|
|
},
|
2019-05-09 21:11:31 +02:00
|
|
|
[]string{"hostname"},
|
|
|
|
)
|
|
|
|
|
|
|
|
// Reply - The number of replies made for every types by PI-Hole.
|
|
|
|
Reply = prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "reply",
|
|
|
|
Namespace: "pihole",
|
|
|
|
Help: "This represent the number of replies made for all types",
|
|
|
|
},
|
|
|
|
[]string{"hostname", "type"},
|
|
|
|
)
|
|
|
|
|
|
|
|
// TopQueries - The number of top queries made by PI-Hole by domain.
|
|
|
|
TopQueries = prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "top_queries",
|
|
|
|
Namespace: "pihole",
|
|
|
|
Help: "This represent the number of top queries made by PI-Hole by domain",
|
|
|
|
},
|
|
|
|
[]string{"hostname", "domain"},
|
|
|
|
)
|
|
|
|
|
|
|
|
// TopAds - The number of top ads made by PI-Hole by domain.
|
|
|
|
TopAds = prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "top_ads",
|
|
|
|
Namespace: "pihole",
|
|
|
|
Help: "This represent the number of top ads made by PI-Hole by domain",
|
|
|
|
},
|
|
|
|
[]string{"hostname", "domain"},
|
|
|
|
)
|
|
|
|
|
|
|
|
// TopSources - The number of top sources requests made by PI-Hole by source host.
|
|
|
|
TopSources = prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "top_sources",
|
|
|
|
Namespace: "pihole",
|
|
|
|
Help: "This represent the number of top sources requests made by PI-Hole by source host",
|
|
|
|
},
|
|
|
|
[]string{"hostname", "source"},
|
|
|
|
)
|
|
|
|
|
|
|
|
// ForwardDestinations - The number of forward destinations requests made by PI-Hole by destination.
|
|
|
|
ForwardDestinations = prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "forward_destinations",
|
|
|
|
Namespace: "pihole",
|
|
|
|
Help: "This represent the number of forward destinations requests made by PI-Hole by destination",
|
|
|
|
},
|
|
|
|
[]string{"hostname", "destination"},
|
|
|
|
)
|
|
|
|
|
|
|
|
// QueryTypes - The number of queries made by PI-Hole by type.
|
|
|
|
QueryTypes = prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "querytypes",
|
|
|
|
Namespace: "pihole",
|
|
|
|
Help: "This represent the number of queries made by PI-Hole by type",
|
|
|
|
},
|
|
|
|
[]string{"hostname", "type"},
|
|
|
|
)
|
|
|
|
|
|
|
|
// Status - Is PI-Hole enabled?
|
|
|
|
Status = prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Name: "status",
|
|
|
|
Namespace: "pihole",
|
|
|
|
Help: "This if PI-Hole is enabled",
|
|
|
|
},
|
|
|
|
[]string{"hostname"},
|
2019-05-08 23:45:04 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2019-05-09 21:11:31 +02:00
|
|
|
// Init initializes all Prometheus metrics made available by PI-Hole exporter.
|
2019-05-08 23:45:04 +02:00
|
|
|
func Init() {
|
2019-05-09 21:11:31 +02:00
|
|
|
initMetric("domains_blocked", DomainsBlocked)
|
|
|
|
initMetric("dns_queries_today", DNSQueriesToday)
|
|
|
|
initMetric("ads_blocked_today", AdsBlockedToday)
|
|
|
|
initMetric("ads_percentag_today", AdsPercentageToday)
|
|
|
|
initMetric("unique_domains", UniqueDomains)
|
|
|
|
initMetric("queries_forwarded", QueriesForwarded)
|
|
|
|
initMetric("queries_cached", QueriesCached)
|
|
|
|
initMetric("clients_ever_seen", ClientsEverSeen)
|
|
|
|
initMetric("unique_clients", UniqueClients)
|
|
|
|
initMetric("dns_queries_all_types", DNSQueriesAllTypes)
|
|
|
|
initMetric("reply", Reply)
|
|
|
|
initMetric("top_queries", TopQueries)
|
|
|
|
initMetric("top_ads", TopAds)
|
|
|
|
initMetric("top_sources", TopSources)
|
|
|
|
initMetric("forward_destinations", ForwardDestinations)
|
|
|
|
initMetric("querytypes", QueryTypes)
|
|
|
|
initMetric("status", Status)
|
2019-05-08 23:45:04 +02:00
|
|
|
}
|
|
|
|
|
2019-05-09 21:11:31 +02:00
|
|
|
func initMetric(name string, metric *prometheus.GaugeVec) {
|
2019-05-08 23:45:04 +02:00
|
|
|
prometheus.MustRegister(metric)
|
2019-05-09 21:11:31 +02:00
|
|
|
log.Printf("New Prometheus metric registered: %s", name)
|
2019-05-08 23:45:04 +02:00
|
|
|
}
|