diff --git a/metrics/config.go b/metrics/config.go index 2eb09fb48a..c7ac8f8238 100644 --- a/metrics/config.go +++ b/metrics/config.go @@ -16,6 +16,10 @@ package metrics +import ( + "errors" +) + // Config contains the configuration for the metric collection. type Config struct { Enabled bool `toml:",omitempty"` @@ -35,6 +39,20 @@ type Config struct { InfluxDBOrganization string `toml:",omitempty"` } +func (c *Config) Validate() error { + if c.EnableInfluxDB || c.EnableInfluxDBV2 { + v1FlagIsSet := c.InfluxDBUsername != "" || c.InfluxDBPassword != "" + v2FlagIsSet := c.InfluxDBToken != "" || c.InfluxDBOrganization != "" || c.InfluxDBBucket != "" + + if c.EnableInfluxDB && v2FlagIsSet { + return errors.New("Flags --influxdb.metrics.organization, --influxdb.metrics.token, --influxdb.metrics.bucket are only available for influxdb-v2") + } else if c.EnableInfluxDBV2 && v1FlagIsSet { + return errors.New("Flags --influxdb.metrics.username, --influxdb.metrics.password are only available for influxdb-v1") + } + } + return nil +} + // DefaultConfig is the default config for metrics used in go-ethereum. var DefaultConfig = Config{ Enabled: false,