Closed guilhemmarchand closed 2 years ago
Exactly - static renaming is too simple. Regexp much better, or even "tr" like replace all whitespaces to underscore
tr/ /_/
Very simple and quick way to modify tag or field names from "cluster name" to "clustername". Sure it can be done with regexp like PERLRE "s/\s+//g" to replace one or more whitespaces to single underscore globally over tag name.
Does anyone know if this has been implemented in the 1.10 nightlies?
It is not, it has been bumped to the 1.11 milestone
This feature would be helpful for renaming fields and tags as well.
I just came across the string processor and the following reference:
Replace all non-overlapping instances of old with new
[[processors.strings.replace]] measurement = "*" old = ":" new = "_"
It is not clear what this is doing ... does this operate on the measurement name and replace ":" with "_"?
Does this do what the @guilhemmarchand was looking to do?
Edit: Probably not ... the documentation says the string processor operates on the measurement values. It is not clear to me what the measurement value is? I understand that a field has a key value pair. Does a measurement have a key value pair as well? Are all the fields of a measurement considered as the measurement value? So, then perhaps this function is a global search and replace for the entire measurement?
Measurements don't have a key/value pair, just the one item, so its not entirely clear if they are more like tag keys or like tag values. In this case the strings processor treats it as both, it both matches and replaces substrings in the measurement itself, and can be used for modifications like: foo:bar,host=localhost value=42
-> foo_bar,host=localhost value=42
.
Hi @sslupsky My original point was from exposed in this thread:
https://community.influxdata.com/t/is-it-possible-to-mass-rename-measurements-with-telegraf/7855/3
Through my apps, I am using Telegraf to poll Jolokia for Kafka, I would like to support an alternative type of deployment via Prometheus JMX exporter.
However, Prometheus does not allow the use of "." in the metric names, meaning the metrics like:
kafka_controller.UncleanLeaderElectionEnableRateAndTimeMs_Mean;host=ip-10-0-0-26;url=http:--ip-10-0-0-26:18080-metrics 0 1544977962
Will be the a "_" based format if polled from Prometheus JMX exporter:
kafka_controller_UncleanLeaderElectionEnableRateAndTimeMs_Mean;host=ip-10-0-0-26;url=http:--ip-10-0-0-26:18080-metrics 0 1544977962
Because the metrics back end relies on the "." convention to categorise the metrics together, I want to be able to mass rename those using regular expressions and capturing group, specially because there might hundreds of them, an explicit rename is not doable.
@guilhemmarchand Ahh, ok. Yes, a regex would be most helpful for that. I am am finding that more flexibility with the measurement names would indeed be helpful.
I am currently facing the same issue. Though there is already the rather powerful template pattern which lets me extract metric properties from the metric name ( https://docs.influxdata.com/telegraf/v1.10/data_formats/template-patterns/ ) it is not sufficient in my current use case.
I have lots of Apache Spark applications from which I want to collect metrics. Sadly, Spark doesn't support exporting metrics to InfluxDB directly, but only via community based custom reporters. I thought it is going to be easier to use the Spark Statsd exporter and configure Telegraf to push the metrics to InfluxDB, so that I don't need to adjust the running applications or adding JAR files on the cluster specific to the current Spark version.
Spark lets me encode some information into the metric name like the spark application name and the spark application id. I can for instance encode the info like so:
--conf spark.metrics.namespace='__\${spark.app.name}___\${spark.app.id}__'
And will get metrics of the form:
driver.__de.myproject.com.main.BatchJob1Main____84934-348f-48349f-4834894__.BlockManager.disk.diskSpaceUsed 0
The problem here is: We have a convention that spark app name must be the main project class name, and this is highly varying in terms of "number of dots" so that I can't use the template naming pattern here to extract this information.
With the prometheus statsd exporter, this is no problem as this allows exactly what is described here: Regex matching with groups. I currently have an prometheus statsd_exporter mapping file:
mappings:
- match: ([a-zA-Z0-9-]+)\.__([a-zA-Z0-9-\.]+)___([a-zA-Z0-9-\.]+)__\.([a-zA-Z0-9-\.]+)
match_type: regex
name: "$4"
labels:
project: "$1"
appname: "$2"
appid: "$3"
which works like a charm in terms of metric conversion. Would be awesome to have this capability in telegraf as well.
Feature Request
Allow mass renaming measurements using the regex processor and one or more rules.
Proposal:
Some collectors may have specific metric rules and naming conventions, where the targets (which could be multiple) might require a different naming convention.
Currently, on the rename processor allows renaming measurements explicitly on a per measurement basis, however with very large applications such as Java based application like Kafka, there are hundreds of potential metrics and a long explicit renaming would be not realistic.
Proposal would be having the regex processor being able to rename measurements with capturing groups capabilities, such that a user could mass rename the metric generated by the source collector depending in its needs with one or more rules.
Current behavior:
Only the rename processor can statically rename a measurement, which is very limited.
Desired behavior:
Extend the regex processor with measurement renaming capabilities
Use case:
Providing advanced management of metric naming convention to allow an easier interfaces between foreign collectors and targets that do not rely on the same naming convention, or expect one that cannot be easily achieved due the huge number of metrics.
A use case example is the ingestion of Prometheus JMX exporter metrics where Prometheus forbids the use of "." in the metric name. Some target system may require a different naming convention to categorise the metrics such as a ".".
For reference please read:
Currently the capabilities are limited to explicit renames using the rename processor, although this works well for specific use cases, this is slightly limited and could advantageously be extended by regex capabilities.
Thank you