pomerium/internal/metrics/exporter.go
Bobby DeSimone 4d4293fc46
internal/logs: make non error conditions less scary in logs
internal/metrics: simplified struct definition with fmt -s.
internal/metrics: added full path to package name.
2019-06-17 08:40:18 +02:00

31 lines
963 B
Go

package metrics // import "github.com/pomerium/pomerium/internal/metrics"
import (
"net/http"
ocProm "contrib.go.opencensus.io/exporter/prometheus"
prom "github.com/prometheus/client_golang/prometheus"
"go.opencensus.io/stats/view"
)
//NewPromHTTPListener creates a prometheus exporter on ListenAddr
func NewPromHTTPListener(ListenAddr string) error {
return http.ListenAndServe(ListenAddr, newPromHTTPHandler())
}
// newPromHTTPHandler creates a new prometheus exporter handler for /metrics
func newPromHTTPHandler() http.Handler {
// TODO this is a cheap way to get thorough go process
// stats. It will not work with additional exporters.
// It should turn into an FR to the OC framework
var reg *prom.Registry
reg = prom.DefaultRegisterer.(*prom.Registry)
pe, _ := ocProm.NewExporter(ocProm.Options{
Namespace: "pomerium",
Registry: reg,
})
view.RegisterExporter(pe)
mux := http.NewServeMux()
mux.Handle("/metrics", pe)
return mux
}