forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serve_admin.go
35 lines (29 loc) · 861 Bytes
/
serve_admin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package serve
import (
"fmt"
"net/http"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
supporthttp "github.com/aiblocks/go/support/http"
supportlog "github.com/aiblocks/go/support/log"
)
func serveAdmin(opts Options, deps adminDeps) {
adminHandler := adminHandler(deps)
addr := fmt.Sprintf(":%d", opts.AdminPort)
supporthttp.Run(supporthttp.Config{
ListenAddr: addr,
Handler: adminHandler,
OnStarting: func() {
deps.Logger.Infof("Starting admin port server on %s", addr)
},
})
}
type adminDeps struct {
Logger *supportlog.Entry
MetricsGatherer prometheus.Gatherer
}
func adminHandler(deps adminDeps) http.Handler {
mux := supporthttp.NewMux(deps.Logger)
mux.Handle("/metrics", promhttp.HandlerFor(deps.MetricsGatherer, promhttp.HandlerOpts{}))
return mux
}