This is the code:
First the shell script:
#! /bin/sh
# plot the number of unique nodes added to the routing table over time
# Count the number of nodes that have been added in Node.log
# and add that number to a data file.
# Create a x-y data set ready for plotting
printf $(date +"%H:%M")" " >> ~/bin/output.dat
# Node that if you are going to use UTC as your timezone then
# you will need to set it beforehand with:
# $ sudo cp /usr/share/zoneinfo/UTC /etc/localtime
grep -o 'Added [0-9,a-f]\{4\}.. to routing table' $1 |\
grep -o '[0-9,a-f]\{4\}' | sort -n | uniq | wc -l >> ~/bin/output.dat
# Generate the plot image from output.dat
~/bin/plot.gnu
# Copy the plot image to the web folder.
# Note that for this to work you will need to
# grant the user write privileges there.
cp -f ~/bin/plot.svg /var/www/html/
This is the plotter script that is called by the shell script:
#! /usr/bin/gnuplot
# (gnuplot version: 4.6 patchlevel 6)
#
# Plotting the data of ouput.dat
set key noautotitle
# svg
set terminal svg size 1024,768 fname 'Verdana, Helvetica, Arial, sans-serif'\
fsize '10'
set output '~/bin/plot.svg'
# Axes label
set xlabel 'Time (UTC)'
set ylabel 'No. of Unique Nodes Added to Routing Table'
set title "SAFE TEST 3, 2016-05-17: Unique Nodes Added to Routing Table"\
font "Arial,14"
# color definitions
set border linewidth 1.5
# set style line 1 lc rgb '#0060ad' lt 1 lw 2 pt 7 ps 1.5 # --- blue
set grid nopolar
set grid xtics nomxtics ytics nomytics noztics nomztics \
nox2tics nomx2tics noy2tics nomy2tics nocbtics nomcbtics
set grid layerdefault lt 0 linewidth 0.500, lt 0 linewidth 0.500
set ytics 10
# I haven't set xtics because gnuplot takes care of it well enough.
set tics scale 1
set xdata time
set timefmt "%H:%M"
set format x "%H:%M"
set xrange ["18:00":"23:59"]
set yrange [50:250]
# set the grid lines
set style line 12 lc rgb 'blue' lt 1 lw 1.5
set style line 13 lc rgb 'blue' lt 1 lw 0.5
set grid xtics ytics mxtics mytics ls 12, ls 13
# set the frequency of the minor tics
set mxtics 6
set mytics 2
plot "~/bin/output.dat" using 1:2
This is what the output.dat file looks like after a few cycles:
18:21 64
18:22 64
18:23 64
18:24 64
This is the crontab:
*/1 * * * * /home/user/bin/run /home/user/safe_vault1/Node.log
Manual usage is (although the cron job normally takes care of it):
$ ./run ../safe_vault1/Node.log
If you are running safe_vault as a service, as I describe here, then make the argument in the cron job, and the manual usage, point to /opt/safe_vault1/Node.log, or wherever you have installed it. That’s the only change you would need to make, since neither of the two scripts hard-wire that path.