Last active
November 15, 2017 17:39
-
-
Save V3ckt0r/809888842c56fcd6c500fed460242ce7 to your computer and use it in GitHub Desktop.
Negroni with Prometheus
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
====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