statsd
statsd copied to clipboard
How to escape metrics with colon in the name
I'm sending metrics which use colon char as a namespace hierarchical separator in their names.
Since it is also the field separator for StatsD, I get DEBUG: Bad line: a in msg "foo:a:b:1|c" when debuging with echo "foo:a:b:1|c" | nc -u -w0 127.0.0.1 8125.
Tried escaping colons with preceding backslashes (\:) but same error. Is there any escape sequence? If not, would not it be desirable/acceptable as a feature request and/or patch?
TIA.
Bump.
With my limited JS knowledge, in statsd.js looks like there isn't any code to deal with metrics containing colons. Would be grateful if someone knowledgeable could confirm and, those who can, provide feedback on the chances of having colons to be accepted.
The StatsD protocol relies on the ':' character to separate the metric name from the metric value. Having ':' characters in the incoming metric name is not supported.
Is it possible to replace that character before sending the metric to StatsD?
Thanks for confirming, Ben. Currently, that's what I'm doing as a workaround. But, since in my case colons are used everywhere as namespace separators, I would like to know if accepting colons in metric names would be desirable/acceptable as a feature request and/or patch. If I'm not wrong, just escaping them with a backslash would do the trick. What do you think?
This is tricky, one way to potentially solve this is to use percent encoding. Which means the parser should be aware of such thing.
What if the parser just "waits" for the last colon by splitting the metrics name or something like that - wouldn't that be a seamless solution?
You know that everything that comes after the last colon, is the metrics value. Everything else before is the name
I mean something like that
> echo "some:metrics:name.timestamp:12.3456|ms" | grep -o '[^:]*$'
12.3456|ms
Would replacing the following https://github.com/statsd/statsd/blob/9cf77d87855bcb69a8663135f59aa23825db9797/stats.js#L261-L262 with something like that
let key;
({ key, bits } = bits[0].match(/^(?<key>.*):(?<bits>[^:]*)$/).groups);
do the trick?