Skip to content

Instantly share code, notes, and snippets.

@conr
Created January 5, 2018 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conr/55abfe75e5f794075462778e2ee552a7 to your computer and use it in GitHub Desktop.
Save conr/55abfe75e5f794075462778e2ee552a7 to your computer and use it in GitHub Desktop.
package main
import (
"log"
"net/http"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
requests = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "requests_total",
Help: "Number of requests.",
},
)
)
func init() {
// Metrics have to be registered to be exposed:
prometheus.MustRegister(requests)
}
func main() {
http.HandleFunc("/",
func(w http.ResponseWriter, r *http.Request) {
requests.Inc()
})
// The Handler function provides a default handler to expose metrics
// via an HTTP server. "/metrics" is the usual endpoint for that.
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(":8080", nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment