From 856c2fc514df9114de818d73acfe6a379bc7bb6f Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Mon, 17 Mar 2025 10:59:02 -0500 Subject: [PATCH] Simplify Prometheus metric init --- internal/prometheus/prometheus.go | 22 +++++----------------- internal/web/routines-upd.go | 7 ------- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/internal/prometheus/prometheus.go b/internal/prometheus/prometheus.go index 5b83dfd..86d686c 100644 --- a/internal/prometheus/prometheus.go +++ b/internal/prometheus/prometheus.go @@ -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" } diff --git a/internal/web/routines-upd.go b/internal/web/routines-upd.go index 7a015f7..06eaed7 100644 --- a/internal/web/routines-upd.go +++ b/internal/web/routines-upd.go @@ -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 }