From 269285848f0fc83a0a5ede330ab4f6b3ef9a4eea Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 14 Jun 2019 09:57:13 +0300 Subject: [PATCH] app/vminsert/influx: add -influxMeasurementFieldSeparator flag for the ability to change separator for `{measurement}{separator}{field_name}` metric name --- README.md | 8 ++++---- app/vminsert/influx/request_handler.go | 7 ++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e8e08caeb2..b9ea6b3cd9 100644 --- a/README.md +++ b/README.md @@ -206,10 +206,10 @@ 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 -* Field names are mapped to time series names prefixed by `{measurement}.` value -* Field values are mapped to time series values -* Tags are mapped to Prometheus labels as-is +* [`db` query arg](https://docs.influxdata.com/influxdb/v1.7/tools/api/#write-http-endpoint) is mapped into `db` label value. +* Field names are mapped to time series names prefixed with `{measurement}{separator}` value. `{separator}` equals to `.` by default, but can be changed with `-influxMeasurementFieldSeparator` command-line flag. +* Field values are mapped to time series values. +* Tags are mapped to Prometheus labels as-is. For example, the following Influx line: diff --git a/app/vminsert/influx/request_handler.go b/app/vminsert/influx/request_handler.go index 2e489e7e2d..e5d08f89a4 100644 --- a/app/vminsert/influx/request_handler.go +++ b/app/vminsert/influx/request_handler.go @@ -2,6 +2,7 @@ package influx import ( "compress/gzip" + "flag" "fmt" "io" "net/http" @@ -16,6 +17,10 @@ import ( "github.com/VictoriaMetrics/metrics" ) +var ( + measurementFieldSeparator = flag.String("influxMeasurementFieldSeparator", ".", "Separator for `{measurement}{separator}{field_name}` metric name when inserted via Influx line protocol") +) + var rowsInserted = metrics.NewCounter(`vm_rows_inserted_total{type="influx"}`) // InsertHandler processes remote write for influx line protocol. @@ -88,7 +93,7 @@ func (ctx *pushCtx) InsertRows(db string) error { } ctx.metricNameBuf = storage.MarshalMetricNameRaw(ctx.metricNameBuf[:0], ic.Labels) ctx.metricGroupBuf = append(ctx.metricGroupBuf[:0], r.Measurement...) - ctx.metricGroupBuf = append(ctx.metricGroupBuf, '.') + ctx.metricGroupBuf = append(ctx.metricGroupBuf, *measurementFieldSeparator...) metricGroupPrefixLen := len(ctx.metricGroupBuf) for j := range r.Fields { f := &r.Fields[j]