#!/bin/bash base="`dirname "$0"`" if [ ! -d "$base" -o ! -f "$base/netdata.c" -o ! -d "$base/web" ] 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 # 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 # the user to run netdata under NETDATA_CONFIG_USER=nobody # set to 1, to enable debugging NETDATA_CONFIG_DEBUG=0 # our port NETDATA_CONFIG_PORT=19999 # get user configuration if [ -f netdata.conf ] then . 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 "Stopping a (possibly) running netdata..." killall netdata 2>/dev/null killall tc-all.sh 2>/dev/null sleep 2 echo "Compiling netdata" if [ $NETDATA_CONFIG_DEBUG -eq 1 ] then ulimit -c unlimited gcc -Wall -ggdb -o netdata netdata.c -lpthread || exit 1 else gcc -Wall -O3 -o netdata netdata.c -lpthread || exit 1 fi echo "Starting netdata" if [ "$USER" = "root" ] then chown -R "$NETDATA_CONFIG_USER" web || exit 1 chmod 0775 web || exit 1 chmod -R 0664 web/* || exit 1 `pwd`/netdata -d -u $NETDATA_CONFIG_USER -t $NETDATA_CONFIG_INTERNAL_UPDATE_EVERY -l $NETDATA_HISTORY_LINES -p $NETDATA_CONFIG_PORT || exit 1 else echo >&2 "WARNING: NOT RUNNING AS ROOT - CANNOT SWITCH TO USER $NETDATA_CONFIG_USER" echo >&2 "WARNING: MAKE SURE FILES IN web/ ARE OWNED BY $USER - or it will not work" `pwd`/netdata -d -t $NETDATA_CONFIG_INTERNAL_UPDATE_EVERY -l $NETDATA_HISTORY_LINES -p $NETDATA_CONFIG_PORT || exit 1 fi sleep 2 # count all graphs all=`wget http://127.0.0.1:$NETDATA_CONFIG_PORT/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 web/index.html" host="`hostname`" cat >web/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 >>web/index.html < EOF4 done rm -f "${tmp}" cat >>web/index.html < EOF5 if [ "$USER" = "root" ] then chown -R "$NETDATA_CONFIG_USER" web || exit 1 chmod 0775 web || exit 1 chmod -R 0664 web/* || exit 1 fi # save config back set|grep ^NETDATA_ >netdata.conf echo "All Done." echo "Just hit http://127.0.0.1:$NETDATA_CONFIG_PORT/ from your browser." echo echo "You can edit config options in file netdata.conf" echo