计算groupByNode()结果在Graphite中的百分比 [英] Calculate percentage in Graphite for groupByNode() results

查看:225
本文介绍了计算groupByNode()结果在Graphite中的百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两组石墨系列,都采用这种格式.第二组是相同的,除了它的前缀是"x.y"而不是"a.b".

 a.b.ccc.a1.hr
 a.b.ccc.a2.hr
 a.b.ccc.a3.hr
 a.b.ddd.a1.hr
 a.b.ddd.a4.hr

要按第三个节点分组,我使用groupByNode(a.b.*.*.hr,2,"sumSeries"),这使我得到两个系列:cccddd.我想将第一组中的cccddd系列除以第二组中的相应系列.如何在map/reduce函数中使用groupByNode的结果?

解决方案

这是可能的,但很棘手,或者至少我不知道以可扩展的方式进行此操作的更简单方法.

请注意,以下方法使用mapSeries/reduceSeries功能,这些功能仅在石墨网master中可用(不适用于0.9.x,有关在0.9.x上可以使用的手动方法,请参见下文)

我们从2个seriesList开始,每个都有cccddd:

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

现在我们需要将它们放入包含所有项目的单个seriesList中,因此首先我们需要再次使其具有可区分性:

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

现在我们有ccc.a_bddd.a_bccc.x_yddd.x_y,并且可以通过group将它们放入一个列表中:

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

现在我们可以从地图上开始/缩小:

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"
)

这时,我们将有ccc.reduce.asPercentddd.reduce.asPercent,然后,如果只需要cccddd,则可以将整个对象包装在另一个aliasByNode(<query>, 0)中.

这实际上与调用相同:

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")
)

当然,如果添加eee等,它将继续工作.

I have two groups of Graphite series, both in this format. The second group is identical, except that instead of "a.b", it has "x.y" prefix.

 a.b.ccc.a1.hr
 a.b.ccc.a2.hr
 a.b.ccc.a3.hr
 a.b.ddd.a1.hr
 a.b.ddd.a4.hr

To group by 3rd node I use groupByNode(a.b.*.*.hr,2,"sumSeries"), which gets me two series: ccc and ddd. I would like to divide ccc and ddd series from the first group by corresponding series in the second group. How do I use the result of groupByNode in the map/reduce function?

解决方案

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.

这篇关于计算groupByNode()结果在Graphite中的百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆