11

I want to label series by hostname + metric name. I know I can use aliasByNode(1) to do first part and aliasByMetric() to do the second. Any ideas how can I merge those two functions in a single metric?

Jakub Kubrynski
  • 13,724
  • 6
  • 60
  • 85

3 Answers3

14

aliasByNode can take multiple arguments.

aliasByNode(apps.fakesite.web_server_01.counters.requests.count, 2,5)

returns web_server_01.count.

The Grafana query editor for Graphite does not support this but if you toggle edit mode then you can edit the raw query. After editing it, you can toggle back.

Toggle Edit Mode

enter image description here

End Result

Daniel Lee
  • 7,709
  • 2
  • 48
  • 57
4

You may want to check out aliasSub, which allows you to use a regular expression replacement to modify the series name.

In grafana syntax something like aliasSub(([^.]+)([.][^.]+)*[.]([^.]+), \1 \3) should do what you're after.

AussieDan
  • 2,116
  • 15
  • 11
  • I'm aware of aliasSub but it's really complex comparing to what I want to achieve. It looks like a standard usecase and it's hard to belive there is no such solution out of the box – Jakub Kubrynski Jul 09 '16 at 17:36
  • aliaSub is very tedious but wouldn't have been had this type of regex worked: aliasSub( '(?:([^.]+)\.)+', \0 \1 \2 \3 \4 \5 etc) That is, have one nested capture that just captures every dot delimited string with a single capture grouping. You could use that same regex everywhere for a more printf like Grafana alias method. I haven't been able to get that to work. Maybe someone else has. The weird ?: thingy is Perl regex way of saying "group this, but don't capture it". I only want to capture the ([^.]+) part but multiple instances, thus the outer grouping is needed with its own + sign. – Walt Howard Dec 04 '20 at 18:35
3

Something that would solve ALL these problems would just be to have a string with replacement parameters for the metric nodes, like,

aliasByVars("core.app.city.rack.app.instance.thread", 
  "resource: city-$3,rack-$4")

You could intersperse static text with the values of the metric elements (nodes) all you wanted.

That could replace alias, aliasNode, aliasMetric and 99% of aliasSub with one simple, easy to understand namer.

There would be some aliasSub applications where you used partial node names this could not replace.

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Walt Howard
  • 7,676
  • 1
  • 16
  • 11