#!/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 # every how many seconds to show the graphs NETDATA_CONFIG_UPDATE_EVERY=2 # the detail of the data that will be kept in netdata NETDATA_CONFIG_INTERNAL_UPDATE_EVERY=1 # how many points should the graphs have NETDATA_CONFIG_HISTORY_POINTS=120 # how many points should be kept in memory NETDATA_CONFIG_HISTORY_DATA=3600 # every how many graph refreshes, the page should be reloaded # this fixes a bug in the google graphs API which leaks memory # when refreshes graphs NETDATA_CONFIG_RELOAD_EVERY=500 if [ -f netdata.conf ] then source netdata.conf fi # how many history lines to keep in netdata NETDATA_HISTORY_LINES=$[NETDATA_CONFIG_UPDATE_EVERY * NETDATA_CONFIG_HISTORY_POINTS / NETDATA_CONFIG_INTERNAL_UPDATE_EVERY] 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}" 2>/dev/null 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 netdata files." exit 1 fi 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 cp "${base}/all.xsl" "${data}/" cp "${base}/netdata.js" "${data}/" cp "${base}/tc-all.sh" "${data}/" chmod 700 "${data}/tc-all.sh" echo "Finding proper parameters for dashboard..." echo "Stopping a (possibly) running netdata..." killall netdata 2>/dev/null killall tc-all.sh 2>/dev/null echo "Compiling netdata" # gcc -Wall -O3 -o netdata netdata.c -lpthread || exit 1 gcc -Wall -ggdb -o netdata netdata.c -lpthread || exit 1 echo "Starting netdata" p=`pwd` cd data ulimit -c unlimited $p/netdata -d -u $NETDATA_CONFIG_INTERNAL_UPDATE_EVERY -l $NETDATA_HISTORY_LINES || exit 1 cd "$p" sleep 2 # count all graphs all=`wget http://127.0.0.1:19999/list -O - 2>/dev/null` count=0 for x in $all do y=`echo "$x" | tr ".-" "__"` eval "t=\${NETDATA_PRIORITY_${y}}" if [ ! "$t" = "IGNORE" ] then count=$[count + 1] fi done echo "We have $count graphs..." echo "Generating ${data}/index.html" host="`hostname`" cat >${data}/index.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}}" if [ ! "$t" = "IGNORE" ] then echo "${t}|${y}" fi done >"${tmp}" for x in `cat "${tmp}" | sort` do n="`echo "$x" | cut -d '|' -f 2-`" cat >>${data}/index.html < EOF4 done rm -f "${tmp}" cat >>${data}/index.html < EOF5 set|grep ^NETDATA_ >netdata.conf if [ ! -h "${data}/data" ] then cd "${data}" ln -s . data fi echo "All Done." echo "Just hit http://127.0.0.1:19999/ from your browser."