cmd/geth: simple it

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
jsvisa 2023-09-13 12:32:45 +08:00
parent 3711a738bd
commit 18d0211b00
2 changed files with 52 additions and 54 deletions

View file

@ -258,9 +258,7 @@ func importChain(ctx *cli.Context) error {
utils.Fatalf("This command requires an argument.")
}
// Start metrics export if enabled
utils.SetupMetrics(ctx)
// Start system runtime metrics collection
go metrics.CollectProcessMetrics(3 * time.Second)
utils.SetupMetricsFromCLI(ctx)
stack, _ := makeConfigNode(ctx)
defer stack.Close()

View file

@ -1982,8 +1982,11 @@ func RegisterFullSyncTester(stack *node.Node, eth *eth.Ethereum, path string) {
log.Info("Registered full-sync tester", "number", block.NumberU64(), "hash", block.Hash())
}
func SetupMetrics(ctx *cli.Context) {
if metrics.Enabled {
func SetupMetricsFromCLI(ctx *cli.Context) {
if !metrics.Enabled {
return
}
log.Info("Enabling metrics collection")
var (
@ -2009,6 +2012,7 @@ func SetupMetrics(ctx *cli.Context) {
}
var (
tagsMap = SplitTagsFlag(ctx.String(MetricsInfluxDBTagsFlag.Name))
endpoint = ctx.String(MetricsInfluxDBEndpointFlag.Name)
database = ctx.String(MetricsInfluxDBDatabaseFlag.Name)
username = ctx.String(MetricsInfluxDBUsernameFlag.Name)
@ -2020,16 +2024,10 @@ func SetupMetrics(ctx *cli.Context) {
)
if enableExport {
tagsMap := SplitTagsFlag(ctx.String(MetricsInfluxDBTagsFlag.Name))
log.Info("Enabling metrics export to InfluxDB")
go influxdb.InfluxDBWithTags(metrics.DefaultRegistry, 10*time.Second, endpoint, database, username, password, "geth.", tagsMap)
} else if enableExportV2 {
tagsMap := SplitTagsFlag(ctx.String(MetricsInfluxDBTagsFlag.Name))
log.Info("Enabling metrics export to InfluxDB (v2)")
go influxdb.InfluxDBV2WithTags(metrics.DefaultRegistry, 10*time.Second, endpoint, token, bucket, organization, "geth.", tagsMap)
}
@ -2040,7 +2038,9 @@ func SetupMetrics(ctx *cli.Context) {
} else if ctx.IsSet(MetricsPortFlag.Name) {
log.Warn(fmt.Sprintf("--%s specified without --%s, metrics server will not start.", MetricsPortFlag.Name, MetricsHTTPFlag.Name))
}
}
// Start system runtime metrics collection
go metrics.CollectProcessMetrics(3 * time.Second)
}
func SetupMetricsFromConfig(c *metrics.Config) {