Skip to content

Instantly share code, notes, and snippets.

@jiekun
Last active August 11, 2024 04:20
Show Gist options
  • Select an option

  • Save jiekun/57114fb9552b6d180bca50cc36882be9 to your computer and use it in GitHub Desktop.

Select an option

Save jiekun/57114fb9552b6d180bca50cc36882be9 to your computer and use it in GitHub Desktop.
package main
import (
"github.com/VictoriaMetrics/metrics"
"net/http"
"time"
)
var (
fooHistogram = metrics.NewHistogram(`test_histogram_seconds{label_1="foo"}`)
barHistogram = metrics.NewHistogram(`test_histogram_seconds{label_1="bar"}`)
)
func main() {
for i := 0; i < 4; i++ {
go func() {
for {
fooHistogram.Update(1)
barHistogram.Update(2)
time.Sleep(10 * time.Millisecond)
}
}()
}
http.HandleFunc("/metrics", func(w http.ResponseWriter, req *http.Request) {
metrics.WritePrometheus(w, true)
})
http.ListenAndServe(":2112", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment