#!/bin/bash base="`dirname "$0"`" if [ ! -d "$base" -o ! -f "$base/netdata.c" ] then echo >&2 "Cannot find my home directory '${base}'." exit 1 fi cd "$base" || exit 1 echo "Creating a directory for netdata..." data= for x in /run/netdata /var/run/netdata /tmp/netdata do echo " Trying '${x}'..." if [ ! -d "${x}" ] then mkdir "${x}" if [ $? -eq 0 ] then echo " OK. '${x}' works." data="${x}" break fi else echo " OK. '${x}' works." data="${x}" break fi done if [ -z "${data}" ] then echo >&2 "Cannot find where to put JSON files." exit 1 fi echo "Stopping a (possibly) running netdata..." killall netdata 2>/dev/null echo "Compiling netdata" gcc -O3 -o netdata netdata.c || exit 1 echo "Starting netdata" ./netdata -d -u 1 -l 60 -o "${data}" || exit 1 echo "Waiting 2 seconds for the JSON files" # wait 2 seconds for the JSON files to be generated sleep 2 if [ -h data ] then echo "Removing existing $base/data link" rm data || exit 1 fi if [ ! -d data ] then echo "Linking '${data}' to $base/data" ln -s "${data}" data || exit 1 else echo >&2 "Directory $base/data already exists. Not touching it, however it should be a link '${data}'." fi echo "Finding proper parameters for dashboard..." # count all JSON files all=`ls "${data}" | grep .json$ | sed "s/\.json$//g"` count=0 for x in $all do count=$[count + 1] done # find the optimal graphs per page w=1 h=1 a=1 while [ $a -lt $count ] do if [ $[h+1] -le $w ] then h=$[h+1] else w=$[w+1] h=$[h-1] fi a=$[w*h] done # prefer to have wider graphs if [ $w -gt $h ] then w=$[w-1] h=$[h+1] fi # make sure we don't display too small graphs if [ $w -gt 10 ] then w=10 fi if [ $h -gt 10 ] then h=10 fi echo "Generating all.html" host="`hostname`" cat >all.html < ${host} netdata EOF3 for x in $all do cat >>all.html < EOF4 done cat >>all.html < EOF5 echo "All Done." echo "Just hit all.html from your browser."