Simplify Prometheus metric init
This commit is contained in:
parent
e8428677a4
commit
856c2fc514
2 changed files with 5 additions and 24 deletions
|
|
@ -22,26 +22,14 @@ func Handler(appConfig *models.Conf) func(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
var up *prometheus.GaugeVec
|
||||
|
||||
func NewMetrics() {
|
||||
up = promauto.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Namespace: "watch_your_lan",
|
||||
Name: "up",
|
||||
Help: "Whether the host is up (1 for yes, 0 for no)",
|
||||
}, []string{"ip", "iface", "name", "mac", "known"})
|
||||
}
|
||||
|
||||
func RemoveMetrics() {
|
||||
up = nil
|
||||
}
|
||||
var up = promauto.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Namespace: "watch_your_lan",
|
||||
Name: "up",
|
||||
Help: "Whether the host is up (1 for yes, 0 for no)",
|
||||
}, []string{"ip", "iface", "name", "mac", "known"})
|
||||
|
||||
// Add a Prometheus metric
|
||||
func Add(oneHist models.Host) {
|
||||
if up == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if oneHist.Name == "" {
|
||||
oneHist.Name = "unknown"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"log/slog"
|
||||
|
||||
"github.com/aceberg/WatchYourLAN/internal/db"
|
||||
"github.com/aceberg/WatchYourLAN/internal/prometheus"
|
||||
)
|
||||
|
||||
func updateRoutines() {
|
||||
|
|
@ -19,12 +18,6 @@ func updateRoutines() {
|
|||
|
||||
allHosts = db.Select("now")
|
||||
|
||||
if appConfig.PrometheusEnable {
|
||||
prometheus.NewMetrics()
|
||||
} else {
|
||||
prometheus.RemoveMetrics()
|
||||
}
|
||||
|
||||
quitScan = make(chan bool)
|
||||
go startScan(quitScan) // scan-routine.go
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue