diff --git a/cmd/prometheus/Readme.md b/cmd/prometheus/Readme.md index 06e224e3c0b78fccc319f3c46f6f143dd5aa9a2d..d41ca92caac488fbba9fac6adb0d5bb4cc4222cd 100644 --- a/cmd/prometheus/Readme.md +++ b/cmd/prometheus/Readme.md @@ -1,8 +1,8 @@ -Build: `cd cmd/prometheus && docker-compose build --parallel` +Build: `docker-compose build --parallel` -Run only Prometheus: `cd cmd/prometheus && docker-compose up prometheus grafana` +Run only Prometheus: `docker-compose up prometheus grafana` -Run with TurboGeth, RestApi and DebugUI: `cd cmd/prometheus && TGETH_DATADIR=/path/to/geth/data/dir docker-compose up` +Run with TurboGeth, RestApi and DebugUI: `XDG_DATA_HOME=/path/to/geth/data/dir docker-compose up` Grafana: [localhost:3000](localhost:3000), admin/admin DebugUI: [localhost:3001](localhost:3001) diff --git a/cmd/prometheus/prometheus.yml b/cmd/prometheus/prometheus.yml index 1f085361dbbb1fe359207a25488530446d9d4fb1..706c214a09abbc849ec262345f7a2d1b290ec42d 100644 --- a/cmd/prometheus/prometheus.yml +++ b/cmd/prometheus/prometheus.yml @@ -16,12 +16,12 @@ scrape_configs: scheme: http static_configs: - targets: - - turbo-geth:6060 - - turbo-geth:6061 - - turbo-geth:6062 - - host.docker.internal:6060 - - host.docker.internal:6061 - - host.docker.internal:6062 + - turbo-geth:6060 + - turbo-geth:6061 + - turbo-geth:6062 + - host.docker.internal:6060 # this is how docker-for-mac allow to access host machine + - host.docker.internal:6061 + - host.docker.internal:6062 - job_name: turbo-geth2 metrics_path: /debug/metrics/prometheus2 diff --git a/docker-compose.yml b/docker-compose.yml index 5857a481e17f345661a2e2e6550e82d6b868d496..45d1c671fc646d9a212557d59e66b7ea7589dac1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,14 +5,14 @@ services: turbo-geth: image: turbo-geth:latest build: . - command: tg --metrics --pprof.addr="0.0.0.0" --pprof.port="6060" --private.api.addr="0.0.0.0:9090" --ipcdisable + command: tg --metrics --metrics.addr="0.0.0.0" --metrics.port="6060" --private.api.addr="0.0.0.0:9090" --pprof --pprof.addr="0.0.0.0" --pprof.port="6061" volumes: - ${XDG_DATA_HOME:-~/.local/share}/turbogeth:/root/.local/share/turbogeth ports: - 30303:30303 prometheus: - image: prom/prometheus:v2.20.1 + image: prom/prometheus:v2.21.0 command: --log.level=warn --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/prometheus --web.console.libraries=/usr/share/prometheus/console_libraries --web.console.templates=/usr/share/prometheus/consoles ports: - 9090:9090 diff --git a/internal/debug/flags.go b/internal/debug/flags.go index 907e9d68eb667027f633929052a38ab71e9a6bea..b9c11a73664e3f8b7353298c5e0fd38bf68c8059 100644 --- a/internal/debug/flags.go +++ b/internal/debug/flags.go @@ -92,16 +92,6 @@ var ( Usage: "Write execution trace to the given file", } // (Deprecated April 2020) - legacyPprofPortFlag = cli.IntFlag{ - Name: "pprofport", - Usage: "pprof HTTP server listening port (deprecated, use --pprof.port)", - Value: 6060, - } - legacyPprofAddrFlag = cli.StringFlag{ - Name: "pprofaddr", - Usage: "pprof HTTP server listening interface (deprecated, use --pprof.addr)", - Value: "127.0.0.1", - } legacyMemprofilerateFlag = cli.IntFlag{ Name: "memprofilerate", Usage: "Turn on memory profiling with the given rate (deprecated, use --pprof.memprofilerate)", @@ -125,7 +115,7 @@ var Flags = []cli.Flag{ } var DeprecatedFlags = []cli.Flag{ - legacyPprofPortFlag, legacyPprofAddrFlag, legacyMemprofilerateFlag, + legacyMemprofilerateFlag, legacyBlockprofilerateFlag, legacyCpuprofileFlag, } @@ -276,24 +266,31 @@ func Setup(ctx *cli.Context) error { } } - // pprof server - if ctx.GlobalBool(pprofFlag.Name) { - listenHost := ctx.GlobalString(pprofAddrFlag.Name) - if ctx.GlobalIsSet(legacyPprofAddrFlag.Name) && !ctx.GlobalIsSet(pprofAddrFlag.Name) { - listenHost = ctx.GlobalString(legacyPprofAddrFlag.Name) - log.Warn("The flag --pprofaddr is deprecated and will be removed in the future, please use --pprof.addr") - } + fmt.Printf("ctx.GlobalBool(pprofFlag.Name): %v\n", ctx.GlobalBool(pprofFlag.Name)) - port := ctx.GlobalInt(pprofPortFlag.Name) - if ctx.GlobalIsSet(legacyPprofPortFlag.Name) && !ctx.GlobalIsSet(pprofPortFlag.Name) { - port = ctx.GlobalInt(legacyPprofPortFlag.Name) - log.Warn("The flag --pprofport is deprecated and will be removed in the future, please use --pprof.port") - } + if metrics.Enabled { + go metrics.CollectProcessMetrics(3 * time.Second) // Start system runtime metrics collection + } + + pprofEnabled := ctx.GlobalBool(pprofFlag.Name) + metricsAddr := ctx.GlobalString(metricsAddrFlag.Name) + + if metrics.Enabled && (!pprofEnabled || metricsAddr != "") { + metricsPort := ctx.GlobalInt(metricsPortFlag.Name) + address := fmt.Sprintf("%s:%d", metricsAddr, metricsPort) + log.Info("Enabling stand-alone metrics HTTP endpoint", "addr", address) + exp.Setup(address) + } - address := fmt.Sprintf("%s:%d", listenHost, port) + // pprof server + if pprofEnabled { + pprofHost := ctx.GlobalString(pprofAddrFlag.Name) + pprofPort := ctx.GlobalInt(pprofPortFlag.Name) + address := fmt.Sprintf("%s:%d", pprofHost, pprofPort) // This context value ("metrics.addr") represents the utils.MetricsHTTPFlag.Name. // It cannot be imported because it will cause a cyclical dependency. - StartPProf(address, !ctx.GlobalIsSet("metrics.addr")) + withMetrics := metrics.Enabled && metricsAddr == "" + StartPProf(address, withMetrics) } return nil }