-
Notifications
You must be signed in to change notification settings - Fork 20.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
geth metrics export to InfluxDB #16979
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ import ( | |
"runtime" | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/accounts" | ||
"github.com/ethereum/go-ethereum/accounts/keystore" | ||
|
@@ -48,6 +49,7 @@ import ( | |
"github.com/ethereum/go-ethereum/les" | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/ethereum/go-ethereum/metrics" | ||
"github.com/ethereum/go-ethereum/metrics/influxdb" | ||
"github.com/ethereum/go-ethereum/node" | ||
"github.com/ethereum/go-ethereum/p2p" | ||
"github.com/ethereum/go-ethereum/p2p/discover" | ||
|
@@ -532,6 +534,41 @@ var ( | |
Usage: "Minimum POW accepted", | ||
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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets expand the usage a bit (otherwise there's not much point to have it). E.g.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
Value: "http://localhost:8086", | ||
} | ||
MetricsInfluxDBDatabaseFlag = cli.StringFlag{ | ||
Name: "metrics.influxdb.database", | ||
Usage: "Metrics InfluxDB database", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets expand the usage a bit (otherwise there's not much point to have it). Perhaps
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I went with |
||
Value: "metrics", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
MetricsInfluxDBUsernameFlag = cli.StringFlag{ | ||
Name: "metrics.influxdb.username", | ||
Usage: "Metrics InfluxDB username", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Username to authorize access to the database" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
Value: "test", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need this if we want to be able to hook up |
||
} | ||
MetricsInfluxDBPasswordFlag = cli.StringFlag{ | ||
Name: "metrics.influxdb.password", | ||
Usage: "Metrics InfluxDB password", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Password to authorize access to the database" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should stay as is, because sometimes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fair enough |
||
Usage: "Metrics InfluxDB `host` tag attached to all measurements", | ||
Value: "localhost", | ||
} | ||
) | ||
|
||
// MakeDataDir retrieves the currently requested data directory, terminating | ||
|
@@ -1181,6 +1218,27 @@ func SetupNetwork(ctx *cli.Context) { | |
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. | ||
func MakeChainDatabase(ctx *cli.Context, stack *node.Node) ethdb.Database { | ||
var ( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
metrics.influxdb
is enough here. It's mostly obvious what that would do :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I agree it is better.