Created
September 30, 2020 09:04
-
-
Save korchasa/2f8d8253f2f4e78ccff1837ae9fc7816 to your computer and use it in GitHub Desktop.
golang-prometheus-register-wide-labels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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