5 if [ ! -d "$base" -o ! -f "$base/netdata.c" -o ! -d "$base/web" ]
7 echo >&2 "Cannot find my home directory '${base}'."
12 # every how many seconds to show the graphs
13 NETDATA_CONFIG_UPDATE_EVERY=2
15 # the detail of the data that will be kept in netdata
16 NETDATA_CONFIG_INTERNAL_UPDATE_EVERY=1
18 # how many points should the graphs have
19 NETDATA_CONFIG_HISTORY_POINTS=120
21 # how many points should be kept in memory
22 NETDATA_CONFIG_HISTORY_DATA=3600
24 # every how many graph refreshes, the page should be reloaded
25 # this fixes a bug in the google graphs API which leaks memory
26 # when refreshes graphs
27 NETDATA_CONFIG_RELOAD_EVERY=500
29 # the user to run netdata under
30 NETDATA_CONFIG_USER=nobody
32 # set to 1, to enable debugging
33 NETDATA_CONFIG_DEBUG=0
36 NETDATA_CONFIG_PORT=19999
38 # get user configuration
39 if [ -f netdata.conf ]
44 # how many history lines to keep in netdata
45 NETDATA_HISTORY_LINES=$[NETDATA_CONFIG_UPDATE_EVERY * NETDATA_CONFIG_HISTORY_POINTS / NETDATA_CONFIG_INTERNAL_UPDATE_EVERY]
47 echo "Stopping a (possibly) running netdata..."
48 killall netdata 2>/dev/null
49 killall tc-all.sh 2>/dev/null
52 echo "Compiling netdata"
53 if [ $NETDATA_CONFIG_DEBUG -eq 1 ]
56 gcc -Wall -ggdb -o netdata netdata.c -lpthread || exit 1
58 gcc -Wall -O3 -o netdata netdata.c -lpthread || exit 1
61 echo "Starting netdata"
62 if [ "$USER" = "root" ]
64 chown -R "$NETDATA_CONFIG_USER" web || exit 1
65 chmod 0775 web || exit 1
66 chmod -R 0664 web/* || exit 1
67 ./netdata -d -u $NETDATA_CONFIG_USER -t $NETDATA_CONFIG_INTERNAL_UPDATE_EVERY -l $NETDATA_HISTORY_LINES -p $NETDATA_CONFIG_PORT || exit 1
69 echo >&2 "WARNING: NOT RUNNING AS ROOT - CANNOT SWITCH TO USER $NETDATA_CONFIG_USER"
70 echo >&2 "WARNING: MAKE SURE FILES IN web/ ARE OWNED BY $USER - or it will not work"
71 ./netdata -d -t $NETDATA_CONFIG_INTERNAL_UPDATE_EVERY -l $NETDATA_HISTORY_LINES -p $NETDATA_CONFIG_PORT || exit 1
76 all=`wget http://127.0.0.1:$NETDATA_CONFIG_PORT/list -O - 2>/dev/null`
80 y=`echo "$x" | tr ".-" "__"`
81 eval "t=\${NETDATA_PRIORITY_${y}}"
82 if [ ! "$t" = "IGNORE" ]
88 echo "We have $count graphs..."
90 echo "Generating web/index.html"
92 cat >web/index.html <<EOF
93 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
94 <html xmlns="http://www.w3.org/1999/xhtml">
97 div {float: left; margin: 0 0 0 0; }
99 <title>${host} netdata</title>
101 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
103 <!--Load the AJAX API-->
104 <script type="text/javascript" src="https://www.google.com/jsapi"></script>
105 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
106 <script type="text/javascript" src="/file/netdata.js"></script>
107 <script type="text/javascript">
109 // Set a callback to run when the Google Visualization API is loaded.
110 google.setOnLoadCallback(drawCharts);
112 function drawCharts() {
113 // EDIT: add one line per interface you have
115 // EDIT: name div id json data graph vertical axis title
116 // EDIT: --------------------------------------------------------------------------------------------------
121 y=`echo "$x" | tr ".-" "__"`
127 title="Network Usage for "
128 vtitle="bandwidth in kilobits/s"
132 title="Disk I/O for "
133 vtitle="I/O in kilobytes/s"
137 title="Class utilization for "
138 vtitle="bandwidth in kilobits/s"
143 eval "NETDATA_TITLE_${y}=\${NETDATA_TITLE_${y}:-${x}}"
144 eval "t=\${NETDATA_TITLE_${y}}"
146 eval "p=\${NETDATA_PRIORITY_${y}}"
147 if [ ! "$p" = "IGNORE" ]
149 cat >>web/index.html <<EOF2
150 addChart('${x}', '${y}_div', 0, 0, "data/${x}/${NETDATA_CONFIG_HISTORY_POINTS}/${NETDATA_CONFIG_UPDATE_EVERY}/average/", "${title}${t} (${x})", "${vtitle}");
155 cat >>web/index.html <<EOF3
156 refreshCharts(999999);
159 var refreshCount = 0;
160 function myChartsRefresh() {
162 if(refreshCount > $NETDATA_CONFIG_RELOAD_EVERY) location.reload();
164 // refresh up to 2 charts per second
168 setInterval(myChartsRefresh, 1000);
170 //window.onresize = function(event) {
171 // refreshCharts(999999);
179 EDIT: add one div per interface you have
180 EDIT: use the same id above and bellow!
184 tmp="/tmp/$RANDOM.netdata.$$.$RANDOM"
187 y=`echo "$x" | tr ".-" "__"`
188 eval "NETDATA_PRIORITY_${y}=\${NETDATA_PRIORITY_${y}:-${x}}"
189 eval "t=\${NETDATA_PRIORITY_${y}}"
190 if [ ! "$t" = "IGNORE" ]
196 for x in `cat "${tmp}" | sort`
198 n="`echo "$x" | cut -d '|' -f 2-`"
199 cat >>web/index.html <<EOF4
200 <div id="${n}_div"></div>
205 cat >>web/index.html <<EOF5
210 if [ "$USER" = "root" ]
212 chown -R "$NETDATA_CONFIG_USER" web || exit 1
213 chmod 0775 web || exit 1
214 chmod -R 0664 web/* || exit 1
218 set|grep ^NETDATA_ >netdata.conf
221 echo "Just hit http://127.0.0.1:$NETDATA_CONFIG_PORT/ from your browser."
223 echo "You can edit config options in file netdata.conf"