mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
cmd/geth: add flags for metrics export
This commit is contained in:
parent
e8ea5aa0d5
commit
0e2c88a979
2 changed files with 71 additions and 0 deletions
|
|
@ -144,6 +144,15 @@ var (
|
||||||
utils.WhisperMaxMessageSizeFlag,
|
utils.WhisperMaxMessageSizeFlag,
|
||||||
utils.WhisperMinPOWFlag,
|
utils.WhisperMinPOWFlag,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
metricsFlags = []cli.Flag{
|
||||||
|
utils.MetricsEnableInfluxDBExportFlag,
|
||||||
|
utils.MetricsInfluxDBEndpointFlag,
|
||||||
|
utils.MetricsInfluxDBDatabaseFlag,
|
||||||
|
utils.MetricsInfluxDBUsernameFlag,
|
||||||
|
utils.MetricsInfluxDBPasswordFlag,
|
||||||
|
utils.MetricsInfluxDBHostTagFlag,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -186,6 +195,7 @@ func init() {
|
||||||
app.Flags = append(app.Flags, consoleFlags...)
|
app.Flags = append(app.Flags, consoleFlags...)
|
||||||
app.Flags = append(app.Flags, debug.Flags...)
|
app.Flags = append(app.Flags, debug.Flags...)
|
||||||
app.Flags = append(app.Flags, whisperFlags...)
|
app.Flags = append(app.Flags, whisperFlags...)
|
||||||
|
app.Flags = append(app.Flags, metricsFlags...)
|
||||||
|
|
||||||
app.Before = func(ctx *cli.Context) error {
|
app.Before = func(ctx *cli.Context) error {
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
|
|
@ -208,6 +218,9 @@ func init() {
|
||||||
log.Debug("Sanitizing Go's GC trigger", "percent", int(gogc))
|
log.Debug("Sanitizing Go's GC trigger", "percent", int(gogc))
|
||||||
godebug.SetGCPercent(int(gogc))
|
godebug.SetGCPercent(int(gogc))
|
||||||
|
|
||||||
|
// Start metrics export if enabled
|
||||||
|
utils.SetupMetrics(ctx)
|
||||||
|
|
||||||
// Start system runtime metrics collection
|
// Start system runtime metrics collection
|
||||||
go metrics.CollectProcessMetrics(3 * time.Second)
|
go metrics.CollectProcessMetrics(3 * time.Second)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts"
|
"github.com/ethereum/go-ethereum/accounts"
|
||||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||||
|
|
@ -48,6 +49,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/les"
|
"github.com/ethereum/go-ethereum/les"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/metrics"
|
"github.com/ethereum/go-ethereum/metrics"
|
||||||
|
"github.com/ethereum/go-ethereum/metrics/influxdb"
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||||
|
|
@ -532,6 +534,41 @@ var (
|
||||||
Usage: "Minimum POW accepted",
|
Usage: "Minimum POW accepted",
|
||||||
Value: whisper.DefaultMinimumPoW,
|
Value: whisper.DefaultMinimumPoW,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Metrics flags
|
||||||
|
MetricsEnableInfluxDBExportFlag = cli.BoolFlag{
|
||||||
|
Name: "metrics.influxdb.export",
|
||||||
|
Usage: "Enable metrics export/push to an external InfluxDB database",
|
||||||
|
}
|
||||||
|
MetricsInfluxDBEndpointFlag = cli.StringFlag{
|
||||||
|
Name: "metrics.influxdb.endpoint",
|
||||||
|
Usage: "Metrics InfluxDB endpoint",
|
||||||
|
Value: "http://localhost:8086",
|
||||||
|
}
|
||||||
|
MetricsInfluxDBDatabaseFlag = cli.StringFlag{
|
||||||
|
Name: "metrics.influxdb.database",
|
||||||
|
Usage: "Metrics InfluxDB database",
|
||||||
|
Value: "metrics",
|
||||||
|
}
|
||||||
|
MetricsInfluxDBUsernameFlag = cli.StringFlag{
|
||||||
|
Name: "metrics.influxdb.username",
|
||||||
|
Usage: "Metrics InfluxDB username",
|
||||||
|
Value: "test",
|
||||||
|
}
|
||||||
|
MetricsInfluxDBPasswordFlag = cli.StringFlag{
|
||||||
|
Name: "metrics.influxdb.password",
|
||||||
|
Usage: "Metrics InfluxDB password",
|
||||||
|
Value: "test",
|
||||||
|
}
|
||||||
|
// The `host` tag is part of every measurement sent to InfluxDB. Queries on tags are faster in InfluxDB.
|
||||||
|
// It is used so that we can group all nodes and average a measurement across all of them, but also so
|
||||||
|
// that we can select a specific node and inspect its measurements.
|
||||||
|
// https://docs.influxdata.com/influxdb/v1.4/concepts/key_concepts/#tag-key
|
||||||
|
MetricsInfluxDBHostTagFlag = cli.StringFlag{
|
||||||
|
Name: "metrics.influxdb.host.tag",
|
||||||
|
Usage: "Metrics InfluxDB `host` tag attached to all measurements",
|
||||||
|
Value: "localhost",
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// MakeDataDir retrieves the currently requested data directory, terminating
|
// MakeDataDir retrieves the currently requested data directory, terminating
|
||||||
|
|
@ -1181,6 +1218,27 @@ func SetupNetwork(ctx *cli.Context) {
|
||||||
params.TargetGasLimit = ctx.GlobalUint64(TargetGasLimitFlag.Name)
|
params.TargetGasLimit = ctx.GlobalUint64(TargetGasLimitFlag.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetupMetrics(ctx *cli.Context) {
|
||||||
|
if metrics.Enabled {
|
||||||
|
log.Info("Enabling metrics collection")
|
||||||
|
var (
|
||||||
|
enableExport = ctx.GlobalBool(MetricsEnableInfluxDBExportFlag.Name)
|
||||||
|
endpoint = ctx.GlobalString(MetricsInfluxDBEndpointFlag.Name)
|
||||||
|
database = ctx.GlobalString(MetricsInfluxDBDatabaseFlag.Name)
|
||||||
|
username = ctx.GlobalString(MetricsInfluxDBUsernameFlag.Name)
|
||||||
|
password = ctx.GlobalString(MetricsInfluxDBPasswordFlag.Name)
|
||||||
|
hosttag = ctx.GlobalString(MetricsInfluxDBHostTagFlag.Name)
|
||||||
|
)
|
||||||
|
|
||||||
|
if enableExport {
|
||||||
|
log.Info("Enabling metrics export to InfluxDB")
|
||||||
|
go influxdb.InfluxDBWithTags(metrics.DefaultRegistry, 10*time.Second, endpoint, database, username, password, "geth.", map[string]string{
|
||||||
|
"host": hosttag,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MakeChainDatabase open an LevelDB using the flags passed to the client and will hard crash if it fails.
|
// MakeChainDatabase open an LevelDB using the flags passed to the client and will hard crash if it fails.
|
||||||
func MakeChainDatabase(ctx *cli.Context, stack *node.Node) ethdb.Database {
|
func MakeChainDatabase(ctx *cli.Context, stack *node.Node) ethdb.Database {
|
||||||
var (
|
var (
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue