Skip to content

Instantly share code, notes, and snippets.

@korchasa
Created September 30, 2020 09:04
Show Gist options
  • Save korchasa/2f8d8253f2f4e78ccff1837ae9fc7816 to your computer and use it in GitHub Desktop.
Save korchasa/2f8d8253f2f4e78ccff1837ae9fc7816 to your computer and use it in GitHub Desktop.
golang-prometheus-register-wide-labels
package main
import (
"github.com/prometheus/client_golang/prometheus"
"log"
"net/http"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
requestsTotal = prometheus.NewCounter(prometheus.CounterOpts{
Name: "counter",
Help: "The total number of requests",
})
)
func init() {
prometheus.DefaultRegisterer = prometheus.WrapRegistererWith(prometheus.Labels{"replica": "42"}, prometheus.DefaultRegisterer)
prometheus.MustRegister(requestsTotal)
}
func main() {
http.Handle("/metrics", promhttp.Handler())
log.Println("Listen on localhost:8888")
log.Fatal(http.ListenAndServe("localhost:8888", nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment