mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-16 01:40:44 +00:00
metrics/exp: allow configuring metrics HTTP server on separate endpoint (#21290)
This commit is contained in:
parent
d7d54b00f7
commit
3dee6675d2
2 changed files with 8 additions and 3 deletions
|
|
@ -313,7 +313,9 @@ func Setup(ctx *cli.Context) error {
|
||||||
// pprof server
|
// pprof server
|
||||||
if ctx.Bool(pprofFlag.Name) {
|
if ctx.Bool(pprofFlag.Name) {
|
||||||
address := fmt.Sprintf("%s:%d", ctx.String(pprofAddrFlag.Name), ctx.Int(pprofPortFlag.Name))
|
address := fmt.Sprintf("%s:%d", ctx.String(pprofAddrFlag.Name), ctx.Int(pprofPortFlag.Name))
|
||||||
StartPProf(address)
|
// This context value ("metrics-addr") represents the utils.MetricsHTTPFlag.Name.
|
||||||
|
// It cannot be imported because it will cause a cyclical dependency.
|
||||||
|
StartPProf(address, !ctx.IsSet("metrics-addr") && !ctx.IsSet("metrics.addr"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(logFile) > 0 || rotation {
|
if len(logFile) > 0 || rotation {
|
||||||
|
|
@ -323,10 +325,12 @@ func Setup(ctx *cli.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func StartPProf(address string) {
|
func StartPProf(address string, withMetrics bool) {
|
||||||
// Hook go-metrics into expvar on any /debug/metrics request, load all vars
|
// Hook go-metrics into expvar on any /debug/metrics request, load all vars
|
||||||
// from the registry into expvar, and execute regular expvar handler.
|
// from the registry into expvar, and execute regular expvar handler.
|
||||||
exp.Exp(metrics.DefaultRegistry)
|
if withMetrics {
|
||||||
|
exp.Exp(metrics.DefaultRegistry)
|
||||||
|
}
|
||||||
log.Info("Starting pprof server", "addr", fmt.Sprintf("http://%s/debug/pprof", address))
|
log.Info("Starting pprof server", "addr", fmt.Sprintf("http://%s/debug/pprof", address))
|
||||||
go func() {
|
go func() {
|
||||||
if err := http.ListenAndServe(address, nil); err != nil {
|
if err := http.ListenAndServe(address, nil); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ func ExpHandler(r metrics.Registry) http.Handler {
|
||||||
func Setup(address string) {
|
func Setup(address string) {
|
||||||
m := http.NewServeMux()
|
m := http.NewServeMux()
|
||||||
m.Handle("/debug/metrics", ExpHandler(metrics.DefaultRegistry))
|
m.Handle("/debug/metrics", ExpHandler(metrics.DefaultRegistry))
|
||||||
|
m.Handle("/debug/metrics/prometheus", prometheus.Handler(metrics.DefaultRegistry))
|
||||||
log.Info("Starting metrics server", "addr", fmt.Sprintf("http://%s/debug/metrics", address))
|
log.Info("Starting metrics server", "addr", fmt.Sprintf("http://%s/debug/metrics", address))
|
||||||
go func() {
|
go func() {
|
||||||
if err := http.ListenAndServe(address, m); err != nil {
|
if err := http.ListenAndServe(address, m); err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue