mirror of
https://github.com/eko/pihole-exporter.git
synced 2024-11-26 11:55:26 +01:00
Add queries_last_10min metric
This commit is contained in:
parent
d826a22fb7
commit
860c4b6491
@ -183,7 +183,7 @@ func (c Config) hostnameURL() string {
|
||||
|
||||
// PIHoleStatsURL returns the stats url
|
||||
func (c Config) PIHoleStatsURL() string {
|
||||
return c.hostnameURL() + "/admin/api.php?summaryRaw&overTimeData&topItems&recentItems&getQueryTypes&getForwardDestinations&getQuerySources&jsonForceObject"
|
||||
return c.hostnameURL() + "/admin/api.php?summaryRaw&overTimeData&topItems&recentItems&getQueryTypes&getForwardDestinations&getQuerySources&overTimeData10mins&jsonForceObject"
|
||||
}
|
||||
|
||||
// PIHoleLoginURL returns the login url
|
||||
|
@ -175,6 +175,16 @@ var (
|
||||
},
|
||||
[]string{"hostname"},
|
||||
)
|
||||
|
||||
// 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"},
|
||||
)
|
||||
)
|
||||
|
||||
// Init initializes all Prometheus metrics made available by Pi-hole exporter.
|
||||
@ -196,6 +206,7 @@ func Init() {
|
||||
initMetric("forward_destinations", ForwardDestinations)
|
||||
initMetric("querytypes", QueryTypes)
|
||||
initMetric("status", Status)
|
||||
initMetric("queries_last_10min", QueriesLast10min)
|
||||
}
|
||||
|
||||
func initMetric(name string, metric *prometheus.GaugeVec) {
|
||||
|
@ -160,6 +160,20 @@ func (c *Client) setMetrics(stats *Stats) {
|
||||
for queryType, value := range stats.QueryTypes {
|
||||
metrics.QueryTypes.WithLabelValues(c.config.PIHoleHostname, queryType).Set(value)
|
||||
}
|
||||
|
||||
// Pi-hole returns a map of unix epoch time with the number of queries in slots of 10 minutes.
|
||||
// The last epoch is the current in-progress time slot, with queries still being added.
|
||||
// We return the second latest epoch, which is definitive.
|
||||
var lastEpoch, secondLastEpoch int
|
||||
for timestamp := range stats.DomainsOverTime {
|
||||
if timestamp > lastEpoch {
|
||||
secondLastEpoch = lastEpoch
|
||||
lastEpoch = timestamp
|
||||
} else if timestamp > secondLastEpoch && timestamp != lastEpoch {
|
||||
secondLastEpoch = timestamp
|
||||
}
|
||||
}
|
||||
metrics.QueriesLast10min.WithLabelValues(c.config.PIHoleHostname).Set(float64(stats.DomainsOverTime[secondLastEpoch]))
|
||||
}
|
||||
|
||||
func (c *Client) getPHPSessionID() (string, error) {
|
||||
|
@ -38,6 +38,7 @@ type Stats struct {
|
||||
ForwardDestinations map[string]float64 `json:"forward_destinations"`
|
||||
QueryTypes map[string]float64 `json:"querytypes"`
|
||||
Status string `json:"status"`
|
||||
DomainsOverTime map[int]int `json:"domains_over_time"`
|
||||
}
|
||||
|
||||
// ToString method returns a string of the current statistics struct.
|
||||
|
Loading…
Reference in New Issue
Block a user