Timelion: how generate .label() dynamically?

Hi @asp,

when you look at the series labels that Timelion generates by default for a query like .es(q="*", metric="avg:bytes", split="type:10"), it probably looks something like this:

q:* > type:type1 > avg(bytes)

with the * being the query supplied to .es(), type:type1 being the type this time series corresponds to and avg(bytes) being the aggregation in the metric argument of .es(). To transform this label into something like you requested you can use the .label() function with its regex functionality, e.g.:

.es(metric="avg:bytes", split="type:10").label("my very own static text [$1]", "^.* > type:(\S+) > .*")

That should produce my very own static text [type1] as the label for the series corresponding to type1. It replaces every occurence of the regular expression given as the second argument to .label() with the first argument, substituting first capture group (\S+) for the $1 back-reference. See the MDN Regexp documentation for an explanation of the various other special characters.

9 Likes