mirror of
https://github.com/coredns/coredns.git
synced 2025-11-02 10:13:14 -05:00
add host metrics (#3277)
* add host metrics Signed-off-by: yeya24 <yb532204897@gmail.com> * update hosts readme docs Signed-off-by: yeya24 <yb532204897@gmail.com>
This commit is contained in:
@@ -17,6 +17,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/coredns/coredns/plugin"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
// parseIP calls discards any v6 zone info, before calling net.ParseIP.
|
||||
@@ -135,6 +137,8 @@ func (h *Hostsfile) readHosts() {
|
||||
h.mtime = stat.ModTime()
|
||||
h.size = stat.Size()
|
||||
|
||||
hostsEntries.WithLabelValues().Set(float64(h.inline.Len() + h.hmap.Len()))
|
||||
hostsReloadTime.Set(float64(stat.ModTime().UnixNano()) / 1e9)
|
||||
h.Unlock()
|
||||
}
|
||||
|
||||
@@ -252,3 +256,19 @@ func (h *Hostsfile) LookupStaticAddr(addr string) []string {
|
||||
copy(hostsCp[len(hosts1):], hosts2)
|
||||
return hostsCp
|
||||
}
|
||||
|
||||
var (
|
||||
hostsEntries = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "hosts",
|
||||
Name: "entries_count",
|
||||
Help: "The combined number of entries in hosts and Corefile.",
|
||||
}, []string{})
|
||||
|
||||
hostsReloadTime = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "hosts",
|
||||
Name: "reload_timestamp_seconds",
|
||||
Help: "The timestamp of the last reload of hosts file.",
|
||||
})
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user