Simplify Prometheus metric init

This commit is contained in:
Gabe Cook 2025-03-17 10:59:02 -05:00
parent e8428677a4
commit 856c2fc514
No known key found for this signature in database
GPG key ID: 3197318BDE319B8D
2 changed files with 5 additions and 24 deletions

View file

@ -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"
}

View file

@ -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
}