Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sum multiple metrics without summing over a wildcard?

I have the following metrics:

  • folsomite.<host>.cache.hit1
  • folsomite.<host>.cache.hit2
  • folsomite.<host>.cache.miss1
  • folsomite.<host>.cache.miss2
  • folsomite.<host>.cache.miss3

(The caching library I'm using has 2 flavours of hit: first-chance and second-chance, and 3 flavours of miss)

And I want to calculate (hit1 + hit2) / (miss1 + miss2 + miss3). I thought I'd start by calculating (hit1 + hit2), but if I use sumSeries as sumSeries(folsomite.*.cache.hit*), then it sums over the <host> values as well.

How do I sum multiple metrics over some wildcards, without summing over other wildcards? Or how do I specifically add two (or more metrics), while preserving the wildcards?

And, having done that, can I divide one (summed) result by another?

Edit: I'm actually using grafana to render the graphs. Does that make a difference?

like image 853
Roger Lipscombe Avatar asked Jan 11 '16 11:01

Roger Lipscombe


1 Answers

Note I have not solve this, but info could be helpful. Let's assume there are below data in graphite

folsomite.A.cache.hit1
folsomite.B.cache.hit1
folsomite.A.cache.hit2
folsomite.C.cache.hit1
folsomite.B.cache.hit2
folsomite.A.cache.miss1
folsomite.B.cache.miss1
folsomite.A.cache.miss2
folsomite.A.cache.miss3
folsomite.C.cache.miss2
folsomite.B.cache.miss2

To group by one wildcard, you should use groupByNode so

groupByNode(folsomite.*.cache.hit*, 1, 'sumSeries')

will output metrics A, B, C with summed hits. Since groupByNode on miss will returns the same names of metric, we should distinguish it somehow. Use aliasSub. So now we have:

aliasSub(groupByNode(folsomite.*.cache.hit*, 1, 'sumSeries'), '(.*)', '\1.hit')
aliasSub(groupByNode(folsomite.*.cache.miss*, 1, 'sumSeries'), '(.*)', '\1.miss')

and metric we get are A.hit, B.hit, C.hit, A.miss, B.miss, C.miss.

Next we could try reduceSeries (this is not working for me, I am missing something :) ). Since reduce expect list of series to work on, it need to be combine by group or mapSeries, so

group(
  aliasSub(groupByNode(folsomite.*.cache.hit*, 1, 'sumSeries'), '(.*)', '\1.hit'), 
  aliasSub(groupByNode(folsomite.*.cache.miss*, 1, 'sumSeries'), '(.*)', '\1.miss')
)

will output altogether miss and hit series. Now reduce

 reduceSeries(
   group(
     aliasSub(groupByNode(folsomite.*.cache.hit*, 1, 'sumSeries'), '(.*)', '\1.hit'),
     aliasSub(groupByNode(folsomite.*.cache.miss*, 1, 'sumSeries'), '(.*)', '\1.miss')
   ), 'divideSeries', 1, 'hit', miss')

That's all. Maybe later I will try different approach but... I hope it will give at least some hint.

And since grafana have ability to set templates with variables it is possible with it, but I would have to dig into this feature.

like image 158
kwarunek Avatar answered Sep 29 '22 13:09

kwarunek