Graphite / Grafana - fetch metrics, aggregate, store as a new metric - any solution?

718 views Asked by At

I've got fairly specific use case where I need to multiply:

  • metric A by metric B, let's call it AB
  • metric C by metric D, let's call it CD and so on

Then I need to use AB, CD ... YZ together in order to work out result, let's call it ABYZ. The real transformations are more complicated, but let's skip it as it's not that important.

It would make my life easier if I have the AB and CD precalculated, as I could query it using template variables in Grafana. Let's say I could specify variable $include which would be list of pairs: AB, CD etc. Then I could easily control the results for ABYZ by including some of the metrics and excluding some of them.

In my current schema, without metrics being precalculated, it's not possible to use template variables, as at this stage is not possible to work out which metric should by multiplied by which metric.

Let's say I would like to get the results of this Graphite query: alias(diffSeries(maxSeries(multiplySeries(maxSeries(stats.gauges.stock.{stock1,stock2}.offers.EUR.bid.), averageSeries(stats.gauges.stock.currency.fidor..EUR.PLN)),maxSeries(stats.gauges.stock.{stock1,stock2}.offers.PLN.bid.*)), minSeries(multiplySeries(minSeries(stats.gauges.stock.{stock1,stock2}.offers.EUR.ask.), averageSeries(stats.gauges.stock.currency.fidor..EUR.PLN)),minSeries(stats.gauges.stock.{stock1,stock2}.offers.PLN.ask.*))), 'diff')

and store it in this metrics: stats.gauges.stock.diff

Is there any solution which could create new metrics from existing ones? I would like skip StatsD layer and touch the graphite / carbon layer directly (if possible).

1

There are 1 answers

1
AussieDan On BEST ANSWER

You can absolutely write a small script that can query the values A, B, etc from graphite and feed AB, etc into carbon so you can query them back out from graphite.

Pretty much any language should suffice, the graphite API is just JSON over HTTP and the carbon protocol is even simpler. Here's a small PHP script I wrote a while back to get values from my home automation system and feed them into carbon after doing some transformations. It is just run via cron on an appropriate interval. The only difference for your application would be that you're pulling the raw values from graphite rather than from an external system.

https://gist.github.com/DanCech/348d37ee45898b34abd3