Browse Source

add gauge

main
Nicolas Massé 3 years ago
parent
commit
2856373a57
  1. 18
      main.go

18
main.go

@ -13,11 +13,14 @@ import (
"github.com/prometheus/common/expfmt" "github.com/prometheus/common/expfmt"
) )
func recordMetrics() { func recordMetrics(delay time.Duration) {
temp := 10
go func() { go func() {
for { for {
opsProcessed.Inc() 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", Name: "myapp_processed_ops_total",
Help: "The total number of processed events", Help: "The total number of processed events",
}) })
temperature = promauto.NewGauge(prometheus.GaugeOpts{
Name: "myapp_temperature",
Help: "The current room temperature",
})
) )
func main() { func main() {
if os.Args[1] == "scrape" { 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.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(":2112", nil) http.ListenAndServe(":2112", nil)

Loading…
Cancel
Save