Calculate percentage in Graphite for groupByNode() results

拥有回忆 提交于 2019-12-04 16:55:06

This is possible but tricky, or at least I don't know of an easier way to do it in an extensible way.

Note that the approach below uses mapSeries / reduceSeries functions which are only available in graphite-web master (not 0.9.x, see below for a manual approach that will work on 0.9.x)

We start with 2 seriesLists, that each contain ccc and ddd:

groupByNode(a.b.*.*.hr,2,"sumSeries")
groupByNode(x.y.*.*.hr,2,"sumSeries")

Now we need to get them into a single seriesList that contains all the items, so first we're going to need to make them distinguishable again:

aliasSub(groupByNode(a.b.*.*.hr,2,"sumSeries"), "$", ".a_b")
aliasSub(groupByNode(x.y.*.*.hr,2,"sumSeries"), "$", ".x_y")

Now we have ccc.a_b, ddd.a_b, ccc.x_y, and ddd.x_y, and we can get them into a single list with group:

group(
  aliasSub(groupByNode(a.b.*.*.hr,2,"sumSeries"), "$", ".a_b"),
  aliasSub(groupByNode(x.y.*.*.hr,2,"sumSeries"), "$", ".x_y")
)

Now we can start on the map/reduce:

reduceSeries(
  mapSeries(
    group(
      aliasSub(groupByNode(a.b.*.*.hr,2,"sumSeries"), "$", ".a_b"),
      aliasSub(groupByNode(x.y.*.*.hr,2,"sumSeries"), "$", ".x_y")
    ),
    0
  ),
  "asPercent", 1, "a_b", "x_y"
)

At this point we'll have ccc.reduce.asPercent and ddd.reduce.asPercent, you can then wrap the enire thing in another aliasByNode(<query>, 0) if you want just ccc and ddd.

What this is doing is essentially the same as calling:

group(
  alias(asPercent(
    groupByNode(a.b.ccc.*.hr,2,"sumSeries"),
    groupByNode(x.y.ccc.*.hr,2,"sumSeries"),
  ), "ccc"),
  alias(asPercent(
    groupByNode(a.b.ddd.*.hr,2,"sumSeries"),
    groupByNode(x.y.ddd.*.hr,2,"sumSeries"),
  ), "ddd")
)

except of course that it'll continue to work if you add eee etc.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!