mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
correct metrics flags and add metrics init on smoke run
This commit is contained in:
parent
e176fe5bbd
commit
8be02faefa
2 changed files with 55 additions and 16 deletions
|
|
@ -18,8 +18,13 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||||
|
gethmetrics "github.com/ethereum/go-ethereum/metrics"
|
||||||
|
"github.com/ethereum/go-ethereum/metrics/influxdb"
|
||||||
swarmmetrics "github.com/ethereum/go-ethereum/swarm/metrics"
|
swarmmetrics "github.com/ethereum/go-ethereum/swarm/metrics"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
|
@ -102,8 +107,14 @@ func main() {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Flags = append(app.Flags, swarmmetrics.Flags[0])
|
app.Flags = append(app.Flags, []cli.Flag{
|
||||||
app.Flags = append(app.Flags, swarmmetrics.Flags[1:]...)
|
utils.MetricsEnabledFlag,
|
||||||
|
swarmmetrics.MetricsInfluxDBEndpointFlag,
|
||||||
|
swarmmetrics.MetricsInfluxDBDatabaseFlag,
|
||||||
|
swarmmetrics.MetricsInfluxDBUsernameFlag,
|
||||||
|
swarmmetrics.MetricsInfluxDBPasswordFlag,
|
||||||
|
swarmmetrics.MetricsInfluxDBHostTagFlag,
|
||||||
|
}...)
|
||||||
|
|
||||||
app.Commands = []cli.Command{
|
app.Commands = []cli.Command{
|
||||||
{
|
{
|
||||||
|
|
@ -122,6 +133,11 @@ func main() {
|
||||||
|
|
||||||
sort.Sort(cli.FlagsByName(app.Flags))
|
sort.Sort(cli.FlagsByName(app.Flags))
|
||||||
sort.Sort(cli.CommandsByName(app.Commands))
|
sort.Sort(cli.CommandsByName(app.Commands))
|
||||||
|
app.Before = func(ctx *cli.Context) error {
|
||||||
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
|
setupMetrics(ctx)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
err := app.Run(os.Args)
|
err := app.Run(os.Args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -129,3 +145,22 @@ func main() {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setupMetrics(ctx *cli.Context) {
|
||||||
|
if gethmetrics.Enabled {
|
||||||
|
var (
|
||||||
|
endpoint = ctx.GlobalString(swarmmetrics.MetricsInfluxDBEndpointFlag.Name)
|
||||||
|
database = ctx.GlobalString(swarmmetrics.MetricsInfluxDBDatabaseFlag.Name)
|
||||||
|
username = ctx.GlobalString(swarmmetrics.MetricsInfluxDBUsernameFlag.Name)
|
||||||
|
password = ctx.GlobalString(swarmmetrics.MetricsInfluxDBPasswordFlag.Name)
|
||||||
|
hosttag = ctx.GlobalString(swarmmetrics.MetricsInfluxDBHostTagFlag.Name)
|
||||||
|
)
|
||||||
|
|
||||||
|
// Start system runtime metrics collection
|
||||||
|
go gethmetrics.CollectProcessMetrics(2 * time.Second)
|
||||||
|
|
||||||
|
go influxdb.InfluxDBWithTags(gethmetrics.DefaultRegistry, 10*time.Second, endpoint, database, username, password, "swarm.", map[string]string{
|
||||||
|
"host": hosttag,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,26 +27,26 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
metricsEnableInfluxDBExportFlag = cli.BoolFlag{
|
MetricsEnableInfluxDBExportFlag = cli.BoolFlag{
|
||||||
Name: "metrics.influxdb.export",
|
Name: "metrics.influxdb.export",
|
||||||
Usage: "Enable metrics export/push to an external InfluxDB database",
|
Usage: "Enable metrics export/push to an external InfluxDB database",
|
||||||
}
|
}
|
||||||
metricsInfluxDBEndpointFlag = cli.StringFlag{
|
MetricsInfluxDBEndpointFlag = cli.StringFlag{
|
||||||
Name: "metrics.influxdb.endpoint",
|
Name: "metrics.influxdb.endpoint",
|
||||||
Usage: "Metrics InfluxDB endpoint",
|
Usage: "Metrics InfluxDB endpoint",
|
||||||
Value: "http://127.0.0.1:8086",
|
Value: "http://127.0.0.1:8086",
|
||||||
}
|
}
|
||||||
metricsInfluxDBDatabaseFlag = cli.StringFlag{
|
MetricsInfluxDBDatabaseFlag = cli.StringFlag{
|
||||||
Name: "metrics.influxdb.database",
|
Name: "metrics.influxdb.database",
|
||||||
Usage: "Metrics InfluxDB database",
|
Usage: "Metrics InfluxDB database",
|
||||||
Value: "metrics",
|
Value: "metrics",
|
||||||
}
|
}
|
||||||
metricsInfluxDBUsernameFlag = cli.StringFlag{
|
MetricsInfluxDBUsernameFlag = cli.StringFlag{
|
||||||
Name: "metrics.influxdb.username",
|
Name: "metrics.influxdb.username",
|
||||||
Usage: "Metrics InfluxDB username",
|
Usage: "Metrics InfluxDB username",
|
||||||
Value: "",
|
Value: "",
|
||||||
}
|
}
|
||||||
metricsInfluxDBPasswordFlag = cli.StringFlag{
|
MetricsInfluxDBPasswordFlag = cli.StringFlag{
|
||||||
Name: "metrics.influxdb.password",
|
Name: "metrics.influxdb.password",
|
||||||
Usage: "Metrics InfluxDB password",
|
Usage: "Metrics InfluxDB password",
|
||||||
Value: "",
|
Value: "",
|
||||||
|
|
@ -55,7 +55,7 @@ var (
|
||||||
// It is used so that we can group all nodes and average a measurement across all of them, but also so
|
// 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.
|
// that we can select a specific node and inspect its measurements.
|
||||||
// https://docs.influxdata.com/influxdb/v1.4/concepts/key_concepts/#tag-key
|
// https://docs.influxdata.com/influxdb/v1.4/concepts/key_concepts/#tag-key
|
||||||
metricsInfluxDBHostTagFlag = cli.StringFlag{
|
MetricsInfluxDBHostTagFlag = cli.StringFlag{
|
||||||
Name: "metrics.influxdb.host.tag",
|
Name: "metrics.influxdb.host.tag",
|
||||||
Usage: "Metrics InfluxDB `host` tag attached to all measurements",
|
Usage: "Metrics InfluxDB `host` tag attached to all measurements",
|
||||||
Value: "localhost",
|
Value: "localhost",
|
||||||
|
|
@ -65,20 +65,24 @@ var (
|
||||||
// Flags holds all command-line flags required for metrics collection.
|
// Flags holds all command-line flags required for metrics collection.
|
||||||
var Flags = []cli.Flag{
|
var Flags = []cli.Flag{
|
||||||
utils.MetricsEnabledFlag,
|
utils.MetricsEnabledFlag,
|
||||||
metricsEnableInfluxDBExportFlag,
|
MetricsEnableInfluxDBExportFlag,
|
||||||
metricsInfluxDBEndpointFlag, metricsInfluxDBDatabaseFlag, metricsInfluxDBUsernameFlag, metricsInfluxDBPasswordFlag, metricsInfluxDBHostTagFlag,
|
MetricsInfluxDBEndpointFlag,
|
||||||
|
MetricsInfluxDBDatabaseFlag,
|
||||||
|
MetricsInfluxDBUsernameFlag,
|
||||||
|
MetricsInfluxDBPasswordFlag,
|
||||||
|
MetricsInfluxDBHostTagFlag,
|
||||||
}
|
}
|
||||||
|
|
||||||
func Setup(ctx *cli.Context) {
|
func Setup(ctx *cli.Context) {
|
||||||
if gethmetrics.Enabled {
|
if gethmetrics.Enabled {
|
||||||
log.Info("Enabling swarm metrics collection")
|
log.Info("Enabling swarm metrics collection")
|
||||||
var (
|
var (
|
||||||
enableExport = ctx.GlobalBool(metricsEnableInfluxDBExportFlag.Name)
|
enableExport = ctx.GlobalBool(MetricsEnableInfluxDBExportFlag.Name)
|
||||||
endpoint = ctx.GlobalString(metricsInfluxDBEndpointFlag.Name)
|
endpoint = ctx.GlobalString(MetricsInfluxDBEndpointFlag.Name)
|
||||||
database = ctx.GlobalString(metricsInfluxDBDatabaseFlag.Name)
|
database = ctx.GlobalString(MetricsInfluxDBDatabaseFlag.Name)
|
||||||
username = ctx.GlobalString(metricsInfluxDBUsernameFlag.Name)
|
username = ctx.GlobalString(MetricsInfluxDBUsernameFlag.Name)
|
||||||
password = ctx.GlobalString(metricsInfluxDBPasswordFlag.Name)
|
password = ctx.GlobalString(MetricsInfluxDBPasswordFlag.Name)
|
||||||
hosttag = ctx.GlobalString(metricsInfluxDBHostTagFlag.Name)
|
hosttag = ctx.GlobalString(MetricsInfluxDBHostTagFlag.Name)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start system runtime metrics collection
|
// Start system runtime metrics collection
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue