#!/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 cat <"${data}/.htaccess" ExpiresActive on ExpiresDefault A0 ExpiresByType application/json A0 Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0" Header set Pragma "no-cache" EOFHTACCESS rm "${data}"/*.json 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 120 -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 tmp="/tmp/$RANDOM.netdata.$$.$RANDOM" for x in $all do y=`echo "$x" | tr "-" "_"` eval "NETDATA_PRIORITY_${y}=\${NETDATA_PRIORITY_${y}:-${x}}" eval "t=\${NETDATA_PRIORITY_${y}}" echo "${t}.${x}" done >"${tmp}" for x in `cat "${tmp}" | sort` do n="`echo "$x" | cut -d '.' -f 2-`" cat >>all.html < EOF4 done rm -f "${tmp}" cat >>all.html < EOF5 set|grep ^NETDATA_ >all.config echo "All Done." echo "Just hit all.html from your browser."