Skip to content

Instantly share code, notes, and snippets.

@jiekun
Created July 25, 2024 04:33
Show Gist options
  • Save jiekun/57114fb9552b6d180bca50cc36882be9 to your computer and use it in GitHub Desktop.
Save jiekun/57114fb9552b6d180bca50cc36882be9 to your computer and use it in GitHub Desktop.
package main
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"net/http"
"time"
)
var (
testHistogramVec = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: "test_histogram_seconds",
Help: "example metrics",
}, []string{"label_1"})
)
func main() {
prometheus.Register(testHistogramVec)
for i := 0; i < 1; i++ {
go func() {
for {
testHistogramVec.With(prometheus.Labels{
"label_1": "value_1",
}).Observe(1)
time.Sleep(time.Second)
}
}()
}
http.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(":2112", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment