mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-02-26 07:37:20 +00:00
metrics: allow changing influxdb interval (#33767)
The PR exposes the InfuxDB reporting interval as a CLI parameter, which was previously fixed 10s. Default is still kept at 10s. Note that decreasing the interval comes with notable extra traffic and load on InfluxDB.
This commit is contained in:
parent
00cbd2e6f4
commit
d3dd48e59d
5 changed files with 31 additions and 14 deletions
|
|
@ -111,6 +111,7 @@ if one is set. Otherwise it prints the genesis from the datadir.`,
|
|||
utils.MetricsInfluxDBUsernameFlag,
|
||||
utils.MetricsInfluxDBPasswordFlag,
|
||||
utils.MetricsInfluxDBTagsFlag,
|
||||
utils.MetricsInfluxDBIntervalFlag,
|
||||
utils.MetricsInfluxDBTokenFlag,
|
||||
utils.MetricsInfluxDBBucketFlag,
|
||||
utils.MetricsInfluxDBOrganizationFlag,
|
||||
|
|
|
|||
|
|
@ -377,6 +377,9 @@ func applyMetricConfig(ctx *cli.Context, cfg *gethConfig) {
|
|||
if ctx.IsSet(utils.MetricsInfluxDBTagsFlag.Name) {
|
||||
cfg.Metrics.InfluxDBTags = ctx.String(utils.MetricsInfluxDBTagsFlag.Name)
|
||||
}
|
||||
if ctx.IsSet(utils.MetricsInfluxDBIntervalFlag.Name) {
|
||||
cfg.Metrics.InfluxDBInterval = ctx.Duration(utils.MetricsInfluxDBIntervalFlag.Name)
|
||||
}
|
||||
if ctx.IsSet(utils.MetricsEnableInfluxDBV2Flag.Name) {
|
||||
cfg.Metrics.EnableInfluxDBV2 = ctx.Bool(utils.MetricsEnableInfluxDBV2Flag.Name)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -216,6 +216,7 @@ var (
|
|||
utils.MetricsInfluxDBUsernameFlag,
|
||||
utils.MetricsInfluxDBPasswordFlag,
|
||||
utils.MetricsInfluxDBTagsFlag,
|
||||
utils.MetricsInfluxDBIntervalFlag,
|
||||
utils.MetricsEnableInfluxDBV2Flag,
|
||||
utils.MetricsInfluxDBTokenFlag,
|
||||
utils.MetricsInfluxDBBucketFlag,
|
||||
|
|
|
|||
|
|
@ -1016,6 +1016,13 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.
|
|||
Category: flags.MetricsCategory,
|
||||
}
|
||||
|
||||
MetricsInfluxDBIntervalFlag = &cli.DurationFlag{
|
||||
Name: "metrics.influxdb.interval",
|
||||
Usage: "Interval between metrics reports to InfluxDB (with time unit, e.g. 10s)",
|
||||
Value: metrics.DefaultConfig.InfluxDBInterval,
|
||||
Category: flags.MetricsCategory,
|
||||
}
|
||||
|
||||
MetricsEnableInfluxDBV2Flag = &cli.BoolFlag{
|
||||
Name: "metrics.influxdbv2",
|
||||
Usage: "Enable metrics export/push to an external InfluxDB v2 database",
|
||||
|
|
@ -2246,13 +2253,14 @@ func SetupMetrics(cfg *metrics.Config) {
|
|||
bucket = cfg.InfluxDBBucket
|
||||
organization = cfg.InfluxDBOrganization
|
||||
tagsMap = SplitTagsFlag(cfg.InfluxDBTags)
|
||||
interval = cfg.InfluxDBInterval
|
||||
)
|
||||
if enableExport {
|
||||
log.Info("Enabling metrics export to InfluxDB")
|
||||
go influxdb.InfluxDBWithTags(metrics.DefaultRegistry, 10*time.Second, endpoint, database, username, password, "geth.", tagsMap)
|
||||
log.Info("Enabling metrics export to InfluxDB", "interval", interval)
|
||||
go influxdb.InfluxDBWithTags(metrics.DefaultRegistry, interval, endpoint, database, username, password, "geth.", tagsMap)
|
||||
} else if enableExportV2 {
|
||||
log.Info("Enabling metrics export to InfluxDB (v2)")
|
||||
go influxdb.InfluxDBV2WithTags(metrics.DefaultRegistry, 10*time.Second, endpoint, token, bucket, organization, "geth.", tagsMap)
|
||||
log.Info("Enabling metrics export to InfluxDB (v2)", "interval", interval)
|
||||
go influxdb.InfluxDBV2WithTags(metrics.DefaultRegistry, interval, endpoint, token, bucket, organization, "geth.", tagsMap)
|
||||
}
|
||||
|
||||
// Expvar exporter.
|
||||
|
|
|
|||
|
|
@ -16,18 +16,21 @@
|
|||
|
||||
package metrics
|
||||
|
||||
import "time"
|
||||
|
||||
// Config contains the configuration for the metric collection.
|
||||
type Config struct {
|
||||
Enabled bool `toml:",omitempty"`
|
||||
EnabledExpensive bool `toml:"-"`
|
||||
HTTP string `toml:",omitempty"`
|
||||
Port int `toml:",omitempty"`
|
||||
EnableInfluxDB bool `toml:",omitempty"`
|
||||
InfluxDBEndpoint string `toml:",omitempty"`
|
||||
InfluxDBDatabase string `toml:",omitempty"`
|
||||
InfluxDBUsername string `toml:",omitempty"`
|
||||
InfluxDBPassword string `toml:",omitempty"`
|
||||
InfluxDBTags string `toml:",omitempty"`
|
||||
Enabled bool `toml:",omitempty"`
|
||||
EnabledExpensive bool `toml:"-"`
|
||||
HTTP string `toml:",omitempty"`
|
||||
Port int `toml:",omitempty"`
|
||||
EnableInfluxDB bool `toml:",omitempty"`
|
||||
InfluxDBEndpoint string `toml:",omitempty"`
|
||||
InfluxDBDatabase string `toml:",omitempty"`
|
||||
InfluxDBUsername string `toml:",omitempty"`
|
||||
InfluxDBPassword string `toml:",omitempty"`
|
||||
InfluxDBTags string `toml:",omitempty"`
|
||||
InfluxDBInterval time.Duration `toml:",omitempty"`
|
||||
|
||||
EnableInfluxDBV2 bool `toml:",omitempty"`
|
||||
InfluxDBToken string `toml:",omitempty"`
|
||||
|
|
@ -47,6 +50,7 @@ var DefaultConfig = Config{
|
|||
InfluxDBUsername: "test",
|
||||
InfluxDBPassword: "test",
|
||||
InfluxDBTags: "host=localhost",
|
||||
InfluxDBInterval: 10 * time.Second,
|
||||
|
||||
// influxdbv2-specific flags
|
||||
EnableInfluxDBV2: false,
|
||||
|
|
|
|||
Loading…
Reference in a new issue