Logic Machine Forum
rrdtool problem - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: rrdtool problem (/showthread.php?tid=671)



rrdtool problem - baggins - 12.03.2017

Hi,

As it is not possible to have a graph with more than one variable, I decided to make my own graphs with rrdtool.
At first I was going to use another server that would collect data with remote xlm service, create the graph, put it on a webpage and display that graph in an iframe in LM.

I had progressed up to the point of moving the graph to the web server when it occurred to me that the rrdtool package is available in LM![Image: rolleyes.png]
The new plan was then to create an rrd archive in LM, put the graph in the img directory and then use that image in my visualisation.

What I did (this is in LM4 firmware 20160714):
-create a directory /data/storage/rrd
-create a rrd archive as follows:

Code:
create_rrd = "rrdtool create /data/storage/rrd/ventilatie.rrd --start N --step 300" ..
" DS:T_intake:GAUGE:600:-20:50" ..
" DS:T_supply:GAUGE:600:-20:50" ..
" DS:T_discharge:GAUGE:600:-20:50" ..
" DS:T_exhaust:GAUGE:600:-20:50" ..
" RRA:MIN:0.5:12:1440" ..
" RRA:MAX:0.5:12:1440" ..
" RRA:AVERAGE:0.5:1:1440"
result = os.execute(create_rrd)

-update the rrd with data:

Code:
-- get data
T_intake = grp.getvalue('4/1/11')
T_supply = grp.getvalue('4/1/12')
T_discharge = grp.getvalue('4/1/14')
T_exhaust = grp.getvalue('4/1/13')
log(T_intake ..":" ..T_supply..":" ..T_discharge..":" ..T_exhaust)
rrdupdate = "rrdtool update /data/storage/rrd/ventilatie.rrd N:" ..T_intake ..":" ..T_supply ..":" ..T_discharge ..":" ..T_exhaust
result = io.readproc(rrdupdate)
-verify that data was being written with rrdtool first and rrdtool last

All this went well. I then wanted to create a graph as follows:

Code:
rrdgraph = "rrdtool  graph /data/storage/img/ventilatie.png DEF:T_i=/data/storage/rrd/ventilatie.rrd:T_intake:AVERAGE LINE1:T_i#ff0000:Invoer"
log(rrdgraph)
result = os.execute(rrdgraph)

This fails, with the os.execute statement returning 256. Obviously no graph is created.
The manual states that the return code of os.execute is system dependent. I have no idea what values to expect on LM...
On the other machine this worked without any problems. The only difference is the version of rrdtool: on LM this is 1.4.7 whereas on the other machine it is 1.6

What is going wrong here?

Thanks.


RE: rrdtool problem - admin - 13.03.2017

The built-in RRDtool does not have the graph option, it can only be used to store/retrieve data.


RE: rrdtool problem - baggins - 13.03.2017

OK, mystery solved... [Image: smile.png]

Back to the original plan then, unless there is a more elegant solution?

Thanks.


RE: rrdtool problem - Thomas - 13.03.2017

Hi
I don't know if it solves your problem but you can usemultiple trends. Below is my example of 1hr averages of brightness from 4 directions + max value.


RE: rrdtool problem - baggins - 13.03.2017

I did look at the multiple trends possibility, but I saw two problems with them:

1)unless I am mistaken, the moment you choose to have a multiple trend for a number of variables, you can't look at other trends in single mode anymore, unless you undo the multiple trend
2) minimum resolution is 5 min which is too long if you want to monitor some potentially fast changing variable (spikes in cpu load for example).


RE: rrdtool problem - baggins - 14.03.2017

Hi,

For those who might be interested to get these multi-valued graphs in their visualization, this is what I ended up doing:

-mark the objects to be used as 'export'.
-the second step involves another server that runs 24x7, otherwise the graphs will be incomplete... I used a powerful machine that I use for backups, Logitech Media Server, zoneminder, etc. I believe that a simple raspberry should do the trick also.
-create rrd archive (see original post).
-schedule a script that runs every x minutes. My script fetches the data, updates the rrd, creates the graph and moves it to the DocumentRoot of the webserver.

This is the script (note that this is quite a basic script with no error checking etc...


Code:
require('socket.http')
socket.http.TIMEOUT = 15

-- get data
local LM_data = socket.http.request('http://remote:remote@<ip_of_LM>/scada-remote?m=xml&r=objects')

if not LM_data then
 log('Data cannot be fetched.')
 return
end
for i in string.gmatch(LM_data, '<object.-</object>') do
 if i ~= nil then
     address =  i:match([[<address>(.-)</address>]])
     data =  i:match([[<data>(.-)</data>]])
     if address == '4/1/11' then
         T_intake = data
     end
     if address == '4/1/12' then
         T_supply = data
     end
     if address == '4/1/14' then
         T_discharge = data
     end
     if address == '4/1/13' then
         T_exhaust = data
     end
 end
end

-- update rrd
rrdupdate = "rrdtool update <path_to>/ventilatie.rrd N:" ..T_intake ..":" ..T_supply ..":" ..T_discharge ..":" ..T_exhaust

result = os.execute(rrdupdate)

--create graph
rrdgraph = "rrdtool graph <path_to>/ventilatie.png -a PNG --title='Ventilatie °C' --slope-mode " ..
" DEF:T_i=<path_to>/ventilatie.rrd:T_intake:AVERAGE " ..
" DEF:T_s=<path_to>/ventilatie.rrd:T_supply:AVERAGE " ..
" DEF:T_d=<path_to>/ventilatie.rrd:T_discharge:AVERAGE " ..
" DEF:T_e=<path_to>/ventilatie.rrd:T_exhaust:AVERAGE " ..
" --width 640" ..
" --height 240" ..
" --full-size-mode" ..
" --color BACK#243d47" ..
" --color CANVAS#243d47" ..
" --color FRAME#243d47" ..
" --color FONT#ffffff" ..
" --color AXIS#515d62" ..
" --color GRID#515d62" ..
" --color MGRID#515d62" ..
" --font TITLE:13:Arial" ..
" --font AXIS:10:Arial" ..
" --font LEGEND:9:Arial" ..
" --grid-dash 1:0" ..
" --border 0" ..
" --y-grid 10:1" ..
" LINE1:T_i#ff0000:' Invoer'" ..
" LINE1:T_s#0400ff:' Toevoer'" ..
" LINE1:T_d#aaff00:' Afvoer'" ..
" LINE1:T_e#35b73d:' Uitvoer'"

result = os.execute(rrdgraph)

-- move graph to web server
result = os.execute("sudo mv <path_to>/ventialtie.png /var/www/html/ventilatie")

Attached is the result.


RE: rrdtool problem - Thomas - 15.03.2017

Hi
I like your symbols at the picture. Is it your work? Or can it be freely downloaded from somewhere?


RE: rrdtool problem - baggins - 15.03.2017

These icons come from the KNX-userforum iconset.

You can find info on:

KNX iconset