Created
January 5, 2018 15:34
-
-
Save conr/55abfe75e5f794075462778e2ee552a7 to your computer and use it in GitHub Desktop.
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 ( | |
"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