Starlark script for renaming prometheus remote write metrics (#9074)
This commit is contained in:
parent
78d67ba87b
commit
885bf273a9
|
|
@ -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{
|
||||
|
|
@ -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.
|
||||
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
Loading…
Reference in New Issue