Timelion: how generate .label() dynamically?

Hi,

I am using split function in timelion to do a term aggregation and to produce mutliple lines by grouping.
The query is quite long and I want to set a custom label, which includes fields of the query.

Example:
I split for the filed type.

That gives me 3 lines, one for (type1, type2, type3)
Now I want to set a custom lable, which should be as following:

"my very own static text" [type]

So this should result into:
my very own static text type1
my very own static text type2
my very own static text type3

How can I do that?

Thanks, Andreas

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

cool, works perfectly. thanks. Didn't found an example for the regex functionality before.

It is only mentioned very briefly in the in-app docs:

I agree that the guide could explain that better.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.