This commit is contained in:
Andrew Morgan 2018-05-23 10:51:58 +01:00
parent ee146d1a78
commit d1a89e71fc
3 changed files with 5 additions and 8 deletions

View file

@ -16,7 +16,6 @@ package main
import ( import (
"flag" "flag"
"log"
"net/http" "net/http"
"github.com/matrix-org/dendrite/common/keydb" "github.com/matrix-org/dendrite/common/keydb"
@ -32,8 +31,6 @@ import (
"github.com/matrix-org/dendrite/roomserver" "github.com/matrix-org/dendrite/roomserver"
"github.com/matrix-org/dendrite/syncapi" "github.com/matrix-org/dendrite/syncapi"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/prometheus/client_golang/prometheus/promhttp"
) )
var ( var (
@ -82,10 +79,6 @@ func main() {
} }
}() }()
// Set up prometheus metrics
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(":8080", nil))
// We want to block forever to let the HTTP and HTTPS handler serve the APIs // We want to block forever to let the HTTP and HTTPS handler serve the APIs
select {} select {}
} }

View file

@ -27,6 +27,7 @@ import (
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices" "github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
"github.com/matrix-org/dendrite/common" "github.com/matrix-org/dendrite/common"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/gorilla/mux" "github.com/gorilla/mux"
sarama "gopkg.in/Shopify/sarama.v1" sarama "gopkg.in/Shopify/sarama.v1"
@ -134,9 +135,11 @@ func (b *BaseDendrite) CreateFederationClient() *gomatrixserverlib.FederationCli
// ApiMux under /api/ and adds a prometheus handler under /metrics. // ApiMux under /api/ and adds a prometheus handler under /metrics.
func (b *BaseDendrite) SetupAndServeHTTP(addr string) { func (b *BaseDendrite) SetupAndServeHTTP(addr string) {
common.SetupHTTPAPI(http.DefaultServeMux, common.WrapHandlerInCORS(b.APIMux)) common.SetupHTTPAPI(http.DefaultServeMux, common.WrapHandlerInCORS(b.APIMux))
logrus.Infof("Starting %s server on %s", b.componentName, addr) logrus.Infof("Starting %s server on %s", b.componentName, addr)
http.Handle("/metrics", promhttp.Handler())
logrus.Infof("Starting %s Prometheus server at /metrics", b.componentName)
err := http.ListenAndServe(addr, nil) err := http.ListenAndServe(addr, nil)
if err != nil { if err != nil {

View file

@ -89,6 +89,7 @@ func MakeFedAPI(
func SetupHTTPAPI(servMux *http.ServeMux, apiMux http.Handler) { func SetupHTTPAPI(servMux *http.ServeMux, apiMux http.Handler) {
// This is deprecated. // This is deprecated.
servMux.Handle("/metrics", prometheus.Handler()) // nolint: megacheck, staticcheck servMux.Handle("/metrics", prometheus.Handler()) // nolint: megacheck, staticcheck
servMux.Handle("/metrics", promhttp.Handler())
servMux.Handle("/api/", http.StripPrefix("/api", apiMux)) servMux.Handle("/api/", http.StripPrefix("/api", apiMux))
} }