diff --git a/README.md b/README.md index 592267950..867acda33 100644 --- a/README.md +++ b/README.md @@ -209,7 +209,8 @@ For instance, put the following lines into `Telegraf` config, so it sends data t Do not forget substituting `` with the real address where VictoriaMetrics runs. VictoriaMetrics maps Influx data using the following rules: -* [`db` query arg](https://docs.influxdata.com/influxdb/v1.7/tools/api/#write-http-endpoint) is mapped into `db` label value. +* [`db` query arg](https://docs.influxdata.com/influxdb/v1.7/tools/api/#write-http-endpoint) is mapped into `db` label value + unless `db` tag exists in the Influx line. * Field names are mapped to time series names prefixed with `{measurement}{separator}` value, where `{separator}` equals to `_` by default. It can be changed with `-influxMeasurementFieldSeparator` command-line flag. See also `-influxSkipSingleField` command-line flag. diff --git a/app/vminsert/influx/request_handler.go b/app/vminsert/influx/request_handler.go index b2f2d7188..e0bfbe85d 100644 --- a/app/vminsert/influx/request_handler.go +++ b/app/vminsert/influx/request_handler.go @@ -90,11 +90,17 @@ func (ctx *pushCtx) InsertRows(db string) error { for i := range rows { r := &rows[i] ic.Labels = ic.Labels[:0] - ic.AddLabel("db", db) + hasDBLabel := false for j := range r.Tags { tag := &r.Tags[j] + if tag.Key == "db" { + hasDBLabel = true + } ic.AddLabel(tag.Key, tag.Value) } + if len(db) > 0 && !hasDBLabel { + ic.AddLabel("db", db) + } ctx.metricNameBuf = storage.MarshalMetricNameRaw(ctx.metricNameBuf[:0], ic.Labels) ctx.metricGroupBuf = append(ctx.metricGroupBuf[:0], r.Measurement...) skipFieldKey := len(r.Fields) == 1 && *skipSingleField