Skip to content

Instantly share code, notes, and snippets.

@V3ckt0r
Last active November 15, 2017 17:39
Show Gist options
  • Save V3ckt0r/809888842c56fcd6c500fed460242ce7 to your computer and use it in GitHub Desktop.
Save V3ckt0r/809888842c56fcd6c500fed460242ce7 to your computer and use it in GitHub Desktop.
Negroni with Prometheus
====server.go file====
func NewHandler() http.Handler {
mux := http.NewServeMux()
mux.Handle("/v1/", v1.NewHandler())
mux.Handle("/ping", HandlePing())
mux.Handle("/", HandlePing())
mux.Handle("/metrics", prometheus.HandlePrometheusMetrics())
return mux
}
func ListenAndServe(addr string, engine *core.Engine) error {
mux := NewHandler()
n := negroni.New()
n.Use(negroni.NewRecovery())
n.UseFunc(WithEngine(engine))
n.UseFunc(NewLogger(log.StandardLogger()))
n.UseHandler(mux)
return http.ListenAndServe(addr, n)
}
------------------
====prometheus.go file====
func HandlePrometheusMetrics() http.Handler {
exporter := NewExporter(scrapeURI)
prometheus.MustRegister(exporter)
prometheus.MustRegister(version.NewCollector("exporter"))
return promhttp.Handler()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment