Based on the script by Pixel_K http://www.uradmonitor.com/howto-upgrade-uradmonitor-graph-local-statistics/ I have set up local RRD graphs for my uradmonitor on my pfsense firewall.
rrdtool is already installed on the pfsense.
since it does not have curl, I've replaced it with the available fetch
Here are the adapted scripts I use. I put them in a directory /var/urad
Script to test reading current values from the uradmonitor, curr.sh:
#!/bin/shURL=http://10.0.0.101/j
rrdpath="/usr/local/bin"
jsondata=$( /usr/bin/fetch -o /dev/stdout $URL 2> /dev/null );
v_cpm=$( echo $jsondata | cut -f 3 -d "," | cut -f 2 -d ":" )
v_temp=$( echo $jsondata | cut -f 4 -d "," | cut -f 2 -d ":" )
echo CPM : $v_cpm
echo Temperature : $v_temp
Get this script running first! Replace the URL of your uRadMonitor. Run with sh curr.sh
Script to set up the RRD Database, setup.sh:
#!/bin/shrrdpath="/usr/local/bin"
rrddata="/var/urad/data"
rrdgraph="/var/urad/graph"
mkdir $rrddata
mkdir $rrdgraph
$rrdpath/rrdtool create $rrddata/uRadMonitor.rrd -s 60 \
DS:cpm:GAUGE:300:0:U \
DS:temp:GAUGE:300:-100:100 \
RRA:AVERAGE:0.5:1:600 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 \
RRA:MAX:0.5:1:600 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797
echo database $rrddata/uRadMonitor.rrd created.
Run this sript once to set up the RDD database: sh setup.sh
Script to store the current value and update the graphs, update.sh:
#!/bin/shURL=http://10.0.0.101/j
rrdpath="/usr/local/bin"
rrddata="/var/urad/data"
rrdgraph="/var/urad/graph"
rrdfmt="--font AXIS:6: --font TITLE:9: --font UNIT:7: --font LEGEND:7: --font-render-mode mono --color ARROW#000000 --color GRID#8C8C8C --color MGRID#000000 -v \"cpm\" --alt-y-mrtg --width 600"
jsondata=$( /usr/bin/fetch -o /dev/stdout $URL 2> /dev/null );
v_cpm=$( echo $jsondata | cut -f 3 -d "," | cut -f 2 -d ":" )
v_temp=$( echo $jsondata | cut -f 4 -d "," | cut -f 2 -d ":" )
echo CPM : $v_cpm
echo Temperature : $v_temp
$rrdpath/rrdtool update $rrddata/uRadMonitor.rrd N:$v_cpm:$v_temp
$rrdpath/rrdtool graph --imgformat PNG $rrdgraph/rad-day.png --start -86400 --end -600 --title "Radiation daily" $rrdfmt \
DEF:cpm=$rrddata/uRadMonitor.rrd:cpm:AVERAGE \
AREA:cpm#00CCCC:"Count Per Minute\g" \
GPRINT:cpm:MAX:" Max \: %5.1lf " \
GPRINT:cpm:AVERAGE:" Avg \: %5.1lf " \
GPRINT:cpm:LAST:" Last \: %5.1lf \l"
$rrdpath/rrdtool graph --imgformat PNG $rrdgraph/rad-week.png --start -604800 -z --title "Radiation weekly" $rrdfmt \
DEF:cpm=$rrddata/uRadMonitor.rrd:cpm:AVERAGE \
AREA:cpm#00CCCC:"Count Per Minute\g" \
GPRINT:cpm:MAX:" Max \: %5.1lf " \
GPRINT:cpm:AVERAGE:" Avg \: %5.1lf " \
GPRINT:cpm:LAST:" Last \: %5.1lf \l"
$rrdpath/rrdtool graph --imgformat PNG $rrdgraph/rad-month.png --start -2592000 -z --title "Radiation monthly" $rrdfmt \
DEF:cpm=$rrddata/uRadMonitor.rrd:cpm:AVERAGE \
AREA:cpm#00CCCC:"Count Per Minute\g" \
GPRINT:cpm:MAX:" Max \: %5.1lf " \
GPRINT:cpm:AVERAGE:" Avg \: %5.1lf " \
GPRINT:cpm:LAST:" Last \: %5.1lf \l"
$rrdpath/rrdtool graph --imgformat PNG $rrdgraph/rad-year.png --start -31536000 -z --title "Radiation yearly" $rrdfmt \
DEF:cpm=$rrddata/uRadMonitor.rrd:cpm:AVERAGE \
AREA:cpm#00CCCC:"Count Per Minute\g" \
GPRINT:cpm:MAX:" Max \: %5.1lf " \
GPRINT:cpm:AVERAGE:" Avg \: %5.1lf " \
GPRINT:cpm:LAST:" Last \: %5.1lf \l"
Again, adjust your URL and paths, if necessary. Run manually using sh update.sh and check that png files in /var/urad/graph are generated and updated.
When everything is working, create a
When everything is working, create a
crontab file to run the update script every minute, uradcontab:
* * * * * /bin/sh /var/urad/update.sh > /dev/null 2> /dev/nullInstall the crontab with:
crontab /var/urad/uradcrontab
To publish the images in the internal pfsense web server:
As root, remount the root directory read-write (default read-only):
/etc/rc.conf_mount_rw
Soft-link the image files into the /usr/local/www directory so they become web-acessible (internal network only):
ln -s /var/urad/graph/*.png /usr/local/wwwCreate a simple html page with the images, e.g. /usr/local/www/rad.html:
<HTML>
<TITLE>
Local Radiation Levels
</TITLE>
<BODY>
<H2>Local Radiation Levels</H2>
<IMG SRC="rad-day.png"/>
</BR>
</BR>
<IMG SRC="rad-week.png"/>
</BR>
</BR>
<IMG SRC="rad-month.png"/>
</BR>
</BR>
<IMG SRC="rad-year.png"/>
</BODY></HTML>
/etc/rc.conf_mount_ro
Done!
And a word of caution, don't repeat my mistake and save your files somewhere, they may be erased when you install a system update! ;-)
Done!
And a word of caution, don't repeat my mistake and save your files somewhere, they may be erased when you install a system update! ;-)
Keine Kommentare:
Kommentar veröffentlichen