Skip to content

Commit

Permalink
Starlark script for renaming prometheus remote write metrics (influxd…
Browse files Browse the repository at this point in the history
  • Loading branch information
helenosheaa authored Mar 31, 2021
1 parent 78d67ba commit 885bf27
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
10 changes: 6 additions & 4 deletions plugins/parsers/prometheusremotewrite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ Converts prometheus remote write samples directly into Telegraf metrics. It can
data_format = "prometheusremotewrite"
```

### Example

**Example Input**
### Example Input
```
prompb.WriteRequest{
Timeseries: []*prompb.TimeSeries{
Expand All @@ -38,7 +36,11 @@ prompb.WriteRequest{
```

**Example Output**
### Example Output
```
prometheus_remote_write,instance=localhost:9090,job=prometheus,quantile=0.99 go_gc_duration_seconds=4.63 1614889298859000000
```

**For alignment with the [InfluxDB v1.x Prometheus Remote Write Spec](https://docs.influxdata.com/influxdb/v1.8/supported_protocols/prometheus/#how-prometheus-metrics-are-parsed-in-influxdb)**

- Use the [Starlark processor rename prometheus remote write script](https://github.com/influxdata/telegraf/blob/master/plugins/processors/starlark/testdata/rename_prometheus_remote_write.star) to rename the measurement name to the fieldname and rename the fieldname to value.
1 change: 1 addition & 0 deletions plugins/processors/starlark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ def apply(metric):
- [multiple metrics from json array](/plugins/processors/starlark/testdata/multiple_metrics_with_json.star) - Builds a new metric from each element of a json array then returns all the created metrics.
- [custom error](/plugins/processors/starlark/testdata/fail.star) - Return a custom error with [fail](https://docs.bazel.build/versions/master/skylark/lib/globals.html#fail).
- [compare with previous metric](/plugins/processors/starlark/testdata/compare_metrics.star) - Compare the current metric with the previous one using the shared state.
- [rename prometheus remote write](/plugins/processors/starlark/testdata/rename_prometheus_remote_write.star) - Rename prometheus remote write measurement name with fieldname and rename fieldname to value.

[All examples](/plugins/processors/starlark/testdata) are in the testdata folder.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Specifically for prometheus remote write - renames the measurement name to the fieldname. Renames the fieldname to value.
# Assumes there is only one field as is the case for prometheus remote write.
#
# Example Input:
# prometheus_remote_write,instance=localhost:9090,job=prometheus,quantile=0.99 go_gc_duration_seconds=4.63 1614889298859000000
#
# Example Output:
# go_gc_duration_seconds,instance=localhost:9090,job=prometheus,quantile=0.99 value=4.63 1614889299000000000

def apply(metric):
if metric.name == "prometheus_remote_write":
for k, v in metric.fields.items():
metric.name = k
metric.fields["value"] = v
metric.fields.pop(k)
return metric

0 comments on commit 885bf27

Please sign in to comment.