From 2856373a5720473fbc71008952cd408364d50519 Mon Sep 17 00:00:00 2001 From: Nicolas MASSE Date: Sat, 25 Jun 2022 19:04:49 +0200 Subject: [PATCH] add gauge --- main.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 0473795..b887614 100644 --- a/main.go +++ b/main.go @@ -13,11 +13,14 @@ import ( "github.com/prometheus/common/expfmt" ) -func recordMetrics() { +func recordMetrics(delay time.Duration) { + temp := 10 go func() { for { opsProcessed.Inc() - time.Sleep(2 * time.Second) + temperature.Set(float64(temp)) + time.Sleep(delay) + temp += 1 } }() } @@ -27,12 +30,21 @@ var ( Name: "myapp_processed_ops_total", Help: "The total number of processed events", }) + temperature = promauto.NewGauge(prometheus.GaugeOpts{ + Name: "myapp_temperature", + Help: "The current room temperature", + }) ) func main() { if os.Args[1] == "scrape" { - recordMetrics() + recordMetrics(2 * time.Second) + + http.Handle("/metrics", promhttp.Handler()) + http.ListenAndServe(":2112", nil) + } else if os.Args[1] == "scrape2" { + recordMetrics(60 * time.Second) http.Handle("/metrics", promhttp.Handler()) http.ListenAndServe(":2112", nil)