mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
Enable prometheus in bootnode
This commit is contained in:
parent
71326b501b
commit
ec6b09240e
1 changed files with 44 additions and 8 deletions
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -16,6 +17,8 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/internal/cli/flagset"
|
"github.com/ethereum/go-ethereum/internal/cli/flagset"
|
||||||
"github.com/ethereum/go-ethereum/internal/cli/server"
|
"github.com/ethereum/go-ethereum/internal/cli/server"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
"github.com/ethereum/go-ethereum/metrics"
|
||||||
|
"github.com/ethereum/go-ethereum/metrics/prometheus"
|
||||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||||
"github.com/ethereum/go-ethereum/p2p/nat"
|
"github.com/ethereum/go-ethereum/p2p/nat"
|
||||||
|
|
@ -27,6 +30,8 @@ type BootnodeCommand struct {
|
||||||
UI cli.Ui
|
UI cli.Ui
|
||||||
|
|
||||||
listenAddr string
|
listenAddr string
|
||||||
|
enableMetrics bool
|
||||||
|
prometheusAddr string
|
||||||
v5 bool
|
v5 bool
|
||||||
verbosity int
|
verbosity int
|
||||||
logLevel string
|
logLevel string
|
||||||
|
|
@ -60,6 +65,18 @@ func (b *BootnodeCommand) Flags() *flagset.Flagset {
|
||||||
Usage: "listening address of bootnode (<ip>:<port>)",
|
Usage: "listening address of bootnode (<ip>:<port>)",
|
||||||
Value: &b.listenAddr,
|
Value: &b.listenAddr,
|
||||||
})
|
})
|
||||||
|
flags.BoolFlag(&flagset.BoolFlag{
|
||||||
|
Name: "metrics",
|
||||||
|
Usage: "Enable metrics collection and reporting",
|
||||||
|
Value: &b.enableMetrics,
|
||||||
|
Default: true,
|
||||||
|
})
|
||||||
|
flags.StringFlag(&flagset.StringFlag{
|
||||||
|
Name: "prometheus-addr",
|
||||||
|
Default: "127.0.0.1:7071",
|
||||||
|
Usage: "listening address of bootnode (<ip>:<port>)",
|
||||||
|
Value: &b.prometheusAddr,
|
||||||
|
})
|
||||||
flags.BoolFlag(&flagset.BoolFlag{
|
flags.BoolFlag(&flagset.BoolFlag{
|
||||||
Name: "v5",
|
Name: "v5",
|
||||||
Default: false,
|
Default: false,
|
||||||
|
|
@ -237,6 +254,25 @@ func (b *BootnodeCommand) Run(args []string) int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if b.enableMetrics {
|
||||||
|
prometheusMux := http.NewServeMux()
|
||||||
|
|
||||||
|
prometheusMux.Handle("/debug/metrics/prometheus", prometheus.Handler(metrics.DefaultRegistry))
|
||||||
|
|
||||||
|
promServer := &http.Server{
|
||||||
|
Addr: b.prometheusAddr,
|
||||||
|
Handler: prometheusMux,
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
if err := promServer.ListenAndServe(); err != nil {
|
||||||
|
log.Error("Failure in running Prometheus server", "err", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
log.Info("Enabling metrics export to prometheus", "path", fmt.Sprintf("http://%s/debug/metrics/prometheus", b.prometheusAddr))
|
||||||
|
}
|
||||||
|
|
||||||
signalCh := make(chan os.Signal, 4)
|
signalCh := make(chan os.Signal, 4)
|
||||||
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
|
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue