pihole-exporter/internal/metrics/metrics.go

216 lines
6.5 KiB
Go
Raw Normal View History

2019-05-08 23:45:04 +02:00
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
2022-01-05 20:38:33 +01:00
log "github.com/sirupsen/logrus"
2019-05-08 23:45:04 +02:00
)
var (
2023-07-26 09:15:44 +02:00
// 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
)
2023-07-26 09:15:44 +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
)
2023-07-26 09:15:44 +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
)
2023-07-26 09:15:44 +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
)
2023-07-26 09:15:44 +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
)
2023-07-26 09:15:44 +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
)
2023-07-26 09:15:44 +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
)
2023-07-26 09:15:44 +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
)
2023-07-26 09:15:44 +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
)
2023-07-26 09:15:44 +02:00
// DNSQueriesAllTypes - The number of DNS queries made for all types by Pi-hole.
2019-05-09 21:11:31 +02:00
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"},
)
2023-07-26 09:15:44 +02:00
// Reply - The number of replies made for every types by Pi-hole.
2019-05-09 21:11:31 +02:00
Reply = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "reply",
Namespace: "pihole",
Help: "This represent the number of replies made for all types",
},
[]string{"hostname", "type"},
)
2023-07-26 09:15:44 +02:00
// TopQueries - The number of top queries made by Pi-hole by domain.
2019-05-09 21:11:31 +02:00
TopQueries = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "top_queries",
Namespace: "pihole",
2023-07-26 09:15:44 +02:00
Help: "This represent the number of top queries made by Pi-hole by domain",
2019-05-09 21:11:31 +02:00
},
[]string{"hostname", "domain"},
)
2023-07-26 09:15:44 +02:00
// TopAds - The number of top ads made by Pi-hole by domain.
2019-05-09 21:11:31 +02:00
TopAds = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "top_ads",
Namespace: "pihole",
2023-07-26 09:15:44 +02:00
Help: "This represent the number of top ads made by Pi-hole by domain",
2019-05-09 21:11:31 +02:00
},
[]string{"hostname", "domain"},
)
2023-07-26 09:15:44 +02:00
// TopSources - The number of top sources requests made by Pi-hole by source host.
2019-05-09 21:11:31 +02:00
TopSources = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "top_sources",
Namespace: "pihole",
2023-07-26 09:15:44 +02:00
Help: "This represent the number of top sources requests made by Pi-hole by source host",
2019-05-09 21:11:31 +02:00
},
[]string{"hostname", "source"},
)
2023-07-26 09:15:44 +02:00
// ForwardDestinations - The number of forward destinations requests made by Pi-hole by destination.
2019-05-09 21:11:31 +02:00
ForwardDestinations = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "forward_destinations",
Namespace: "pihole",
2023-07-26 09:15:44 +02:00
Help: "This represent the number of forward destinations requests made by Pi-hole by destination",
2019-05-09 21:11:31 +02:00
},
[]string{"hostname", "destination"},
)
2023-07-26 09:15:44 +02:00
// QueryTypes - The number of queries made by Pi-hole by type.
2019-05-09 21:11:31 +02:00
QueryTypes = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "querytypes",
Namespace: "pihole",
2023-07-26 09:15:44 +02:00
Help: "This represent the number of queries made by Pi-hole by type",
2019-05-09 21:11:31 +02:00
},
[]string{"hostname", "type"},
)
2023-07-26 09:15:44 +02:00
// Status - Is Pi-hole enabled?
2019-05-09 21:11:31 +02:00
Status = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "status",
Namespace: "pihole",
2023-07-26 09:15:44 +02:00
Help: "This if Pi-hole is enabled",
2019-05-09 21:11:31 +02:00
},
[]string{"hostname"},
2019-05-08 23:45:04 +02:00
)
2024-04-21 18:37:31 +02:00
// QueriesLast10min - Number of queries in the last full slot of 10 minutes
QueriesLast10min = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "queries_last_10min",
Namespace: "pihole",
Help: "Number of queries in the last full slot of 10 minutes",
},
[]string{"hostname"},
)
2019-05-08 23:45:04 +02:00
)
2023-07-26 09:15:44 +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)
2024-04-21 18:37:31 +02:00
initMetric("queries_last_10min", QueriesLast10min)
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)
2022-01-05 20:38:33 +01:00
log.Info("New Prometheus metric registered: ", name)
2019-05-08 23:45:04 +02:00
}