From cc17abfa17afbb8439ffdfb0ce45c846b7fe6fdf Mon Sep 17 00:00:00 2001 From: dylanhuang Date: Fri, 16 Dec 2022 07:59:16 +0800 Subject: [PATCH] metrics: add miner info into metrics server (#1212) * metrics: add unlock address to metrics when miner module is enabled * metrics: add miner config into metrics server * metrics: add device-info into metrics server * metrics: fix the format of device info * metrics: remove device-info --- cmd/geth/config.go | 5 +++++ cmd/geth/main.go | 7 ------- cmd/utils/flags.go | 15 +++++++++++++++ go.mod | 3 ++- go.sum | 4 ++++ 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/cmd/geth/config.go b/cmd/geth/config.go index 00f2cebe34..0f01f123e8 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -174,6 +174,11 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) { if cfg.Ethstats.URL != "" { utils.RegisterEthStatsService(stack, backend, cfg.Ethstats.URL) } + + utils.SetupMetrics(ctx, + utils.EnableBuildInfo(gitCommit, gitDate), + utils.EnableMinerInfo(ctx, cfg.Eth.Miner), + ) return stack, backend } diff --git a/cmd/geth/main.go b/cmd/geth/main.go index a4455c3c0f..852266513e 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -37,7 +37,6 @@ import ( "github.com/ethereum/go-ethereum/internal/ethapi" "github.com/ethereum/go-ethereum/internal/flags" "github.com/ethereum/go-ethereum/log" - "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/node" // Force-load the tracer engines to trigger registration @@ -322,12 +321,6 @@ func prepare(ctx *cli.Context) { log.Info("Dropping default light client cache", "provided", ctx.GlobalInt(utils.CacheFlag.Name), "updated", 128) ctx.GlobalSet(utils.CacheFlag.Name, strconv.Itoa(128)) } - - // Start metrics export if enabled - utils.SetupMetrics(ctx, utils.EnableBuildInfo(gitCommit, gitDate)) - - // Start system runtime metrics collection - go metrics.CollectProcessMetrics(3 * time.Second) } // geth is the main entry point into the system if no special subcommand is ran. diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 33cc72bb27..12524bee5a 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -34,6 +34,7 @@ import ( "text/template" "time" + "github.com/fatih/structs" pcsclite "github.com/gballet/go-libpcsclite" gopsutil "github.com/shirou/gopsutil/mem" "gopkg.in/urfave/cli.v1" @@ -1948,6 +1949,17 @@ func EnableBuildInfo(gitCommit, gitDate string) SetupMetricsOption { } } +func EnableMinerInfo(ctx *cli.Context, minerConfig miner.Config) SetupMetricsOption { + return func() { + if ctx.GlobalBool(MiningEnabledFlag.Name) { + // register miner info into metrics + minerInfo := structs.Map(minerConfig) + minerInfo[UnlockedAccountFlag.Name] = ctx.GlobalString(UnlockedAccountFlag.Name) + metrics.NewRegisteredLabel("miner-info", nil).Mark(minerInfo) + } + } +} + func SetupMetrics(ctx *cli.Context, options ...SetupMetricsOption) { if metrics.Enabled { log.Info("Enabling metrics collection") @@ -2008,6 +2020,9 @@ func SetupMetrics(ctx *cli.Context, options ...SetupMetricsOption) { for _, opt := range options { opt() } + + // Start system runtime metrics collection + go metrics.CollectProcessMetrics(3 * time.Second) } } diff --git a/go.mod b/go.mod index 9dbf3b79cc..a91f415f8d 100644 --- a/go.mod +++ b/go.mod @@ -50,7 +50,7 @@ require ( github.com/prometheus/tsdb v0.7.1 github.com/rjeczalik/notify v0.9.1 github.com/rs/cors v1.7.0 - github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible + github.com/shirou/gopsutil v3.21.11+incompatible github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4 github.com/stretchr/testify v1.7.0 github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 @@ -82,6 +82,7 @@ require ( github.com/cespare/xxhash/v2 v2.1.1 // indirect github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91 // indirect github.com/etcd-io/bbolt v1.3.3 // indirect + github.com/fatih/structs v1.1.0 // indirect github.com/fortytw2/leaktest v1.3.0 // indirect github.com/go-kit/kit v0.8.0 // indirect github.com/go-logfmt/logfmt v0.4.0 // indirect diff --git a/go.sum b/go.sum index f5ca88eff3..c5eade57db 100644 --- a/go.sum +++ b/go.sum @@ -144,6 +144,8 @@ github.com/etcd-io/bbolt v1.3.3 h1:gSJmxrs37LgTqR/oyJBWok6k6SvXEUerFTbltIhXkBM= github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo= +github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlKLDt+S+6hbjVMEW6RGQ7aUf7c= github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= @@ -409,6 +411,8 @@ github.com/segmentio/kafka-go v0.2.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfP github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= +github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= +github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=