Add ability to exclude db/bucket tag from influxdb outputs (#6184)
This commit is contained in:
@@ -23,6 +23,9 @@ The InfluxDB output plugin writes metrics to the [InfluxDB v1.x] HTTP or UDP ser
|
||||
## tag is not set the 'database' option is used as the default.
|
||||
# database_tag = ""
|
||||
|
||||
## If true, the database tag will not be added to the metric.
|
||||
# exclude_database_tag = false
|
||||
|
||||
## If true, no CREATE DATABASE queries will be sent. Set to true when using
|
||||
## Telegraf with a user without permissions to create databases or when the
|
||||
## database already exists.
|
||||
|
||||
@@ -94,6 +94,7 @@ type HTTPConfig struct {
|
||||
ContentEncoding string
|
||||
Database string
|
||||
DatabaseTag string
|
||||
ExcludeDatabaseTag bool
|
||||
RetentionPolicy string
|
||||
Consistency string
|
||||
SkipDatabaseCreation bool
|
||||
@@ -250,6 +251,10 @@ func (c *httpClient) Write(ctx context.Context, metrics []telegraf.Metric) error
|
||||
batches[db] = make([]telegraf.Metric, 0)
|
||||
}
|
||||
|
||||
if c.config.ExcludeDatabaseTag {
|
||||
metric.RemoveTag(c.config.DatabaseTag)
|
||||
}
|
||||
|
||||
batches[db] = append(batches[db], metric)
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ type InfluxDB struct {
|
||||
Password string
|
||||
Database string
|
||||
DatabaseTag string `toml:"database_tag"`
|
||||
ExcludeDatabaseTag bool `toml:"exclude_database_tag"`
|
||||
UserAgent string
|
||||
RetentionPolicy string
|
||||
WriteConsistency string
|
||||
@@ -77,6 +78,9 @@ var sampleConfig = `
|
||||
## tag is not set the 'database' option is used as the default.
|
||||
# database_tag = ""
|
||||
|
||||
## If true, the database tag will not be added to the metric.
|
||||
# exclude_database_tag = false
|
||||
|
||||
## If true, no CREATE DATABASE queries will be sent. Set to true when using
|
||||
## Telegraf with a user without permissions to create databases or when the
|
||||
## database already exists.
|
||||
@@ -262,6 +266,7 @@ func (i *InfluxDB) httpClient(ctx context.Context, url *url.URL, proxy *url.URL)
|
||||
Headers: i.HTTPHeaders,
|
||||
Database: i.Database,
|
||||
DatabaseTag: i.DatabaseTag,
|
||||
ExcludeDatabaseTag: i.ExcludeDatabaseTag,
|
||||
SkipDatabaseCreation: i.SkipDatabaseCreation,
|
||||
RetentionPolicy: i.RetentionPolicy,
|
||||
Consistency: i.WriteConsistency,
|
||||
|
||||
Reference in New Issue
Block a user