====== Grafana ======
==== Kilobytes per second ====
From my [[Projects/load logger]] project I collect the number of bytes in/out of my network devices. If I want to graph that in grafana using my MySQL data source (as KB/s) then I have to use SQL to munge the numbers. This gets what I need in SQL:
select
id,
created_on,
n4_r,
((n4_r - @lastValue) / 1024 ) as AvgKbPerSec,
@lastValue := n4_r
from
data_logger,
( select @lastValue := 0 ) SQLVars
order by
created_on,id
Then to get it working with Grafana, I change it to this (wrapped in an extra select, because graphana only wants one value to graph):
select time, KbPerSec from (
select
created_on as "time",
if(@lastValue = 0, 0, ((n4_r - @lastValue) / 1024 )) as Kb,
@lastValue := n4_r
from
data_logger,
( select @lastValue := 0 ) SQLVars
where $__timeFilter(created_on)
order by
created_on) as newtable
where $__timeFilter(time)
order by
time