@cryptotaxi247 / netdata-1 / commits / 1fb475ce2

no need to generate index.html anymore; config variables are passes to netdata binary and exported from netdata binary

Costa Tsaousis (ktsaou) committed Mar 29, 2014 at 22:40 UTC 1fb475ce2dd549952246af885c3e5e8b4f19ded7
1 file changed +14 -151
netdata.start
+14 -151
@@ -9,19 +9,11 @@ then
9 fi
10 cd "$base" || exit 1
11
12 -# every how many seconds to show the graphs
13 -NETDATA_CONFIG_UPDATE_EVERY=2
14 -
12 # the detail of the data that will be kept in netdata
13 NETDATA_CONFIG_INTERNAL_UPDATE_EVERY=1
14
18 -# how many points should the graphs have
19 -NETDATA_CONFIG_HISTORY_POINTS=120
20 -
21 -# every how many graph refreshes, the page should be reloaded
22 -# this fixes a bug in the google graphs API which leaks memory
23 -# when refreshes graphs
24 -NETDATA_CONFIG_RELOAD_EVERY=500
15 +# how many entries to keep in memory
16 +NETDATA_CONFIG_INTERNAL_HISTORY_LINES=2400
17
18 # the user to run netdata under
19 NETDATA_CONFIG_USER=nobody
@@ -38,9 +30,6 @@ then
30 . netdata.conf
31 fi
32
41 -# how many history lines to keep in netdata
42 -NETDATA_HISTORY_LINES=$[NETDATA_CONFIG_UPDATE_EVERY * NETDATA_CONFIG_HISTORY_POINTS / NETDATA_CONFIG_INTERNAL_UPDATE_EVERY]
43 -
33 echo "Stopping a (possibly) running netdata..."
34 killall netdata 2>/dev/null
35 killall tc-all.sh 2>/dev/null
@@ -55,155 +44,24 @@ else
44 gcc -Wall -O3 -o netdata netdata.c -lpthread || exit 1
45 fi
46
47 +# exporting NETDATA variables to netdata
48 +export `set | grep ^NETDATA_TITLE_ ` 2>/dev/null
49 +export `set | grep ^NETDATA_PRIORITY_ ` 2>/dev/null
50 +
51 echo "Starting netdata"
52 if [ "$USER" = "root" ]
53 then
54 chown -R "$NETDATA_CONFIG_USER" web || exit 1
55 chmod 0775 web || exit 1
56 chmod -R 0664 web/* || exit 1
64 - `pwd`/netdata -d -u $NETDATA_CONFIG_USER -t $NETDATA_CONFIG_INTERNAL_UPDATE_EVERY -l $NETDATA_HISTORY_LINES -p $NETDATA_CONFIG_PORT || exit 1
57 + `pwd`/netdata -d -u $NETDATA_CONFIG_USER -t $NETDATA_CONFIG_INTERNAL_UPDATE_EVERY -l $NETDATA_CONFIG_INTERNAL_HISTORY_LINES -p $NETDATA_CONFIG_PORT || exit 1
58 else
59 echo >&2 "WARNING: NOT RUNNING AS ROOT - CANNOT SWITCH TO USER $NETDATA_CONFIG_USER"
60 echo >&2 "WARNING: MAKE SURE FILES IN web/ ARE OWNED BY $USER - or it will not work"
68 - `pwd`/netdata -d -t $NETDATA_CONFIG_INTERNAL_UPDATE_EVERY -l $NETDATA_HISTORY_LINES -p $NETDATA_CONFIG_PORT || exit 1
61 + `pwd`/netdata -d -t $NETDATA_CONFIG_INTERNAL_UPDATE_EVERY -l $NETDATA_CONFIG_INTERNAL_HISTORY_LINES -p $NETDATA_CONFIG_PORT || exit 1
62 fi
63 sleep 2
64
72 -# count all graphs
73 -all=`wget http://127.0.0.1:$NETDATA_CONFIG_PORT/list -O - 2>/dev/null`
74 -count=0
75 -for x in $all
76 -do
77 - y=`echo "$x" | tr ".-" "__"`
78 - eval "t=\${NETDATA_PRIORITY_${y}}"
79 - if [ ! "$t" = "IGNORE" ]
80 - then
81 - count=$[count + 1]
82 - fi
83 -done
84 -
85 -echo "We have $count graphs..."
86 -
87 -echo "Generating web/index.html"
88 -host="`hostname`"
89 -cat >web/index.html <<EOF
90 -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
91 -<html xmlns="http://www.w3.org/1999/xhtml">
92 -<style>
93 - * {font-family:Arial}
94 - div {float: left; margin: 0 0 0 0; }
95 -</style>
96 -<title>${host} netdata</title>
97 -<head>
98 - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
99 -
100 - <!--Load the AJAX API-->
101 - <script type="text/javascript" src="https://www.google.com/jsapi"></script>
102 - <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
103 - <script type="text/javascript" src="/file/netdata.js"></script>
104 - <script type="text/javascript">
105 -
106 - // Set a callback to run when the Google Visualization API is loaded.
107 - google.setOnLoadCallback(drawCharts);
108 -
109 - function drawCharts() {
110 - // EDIT: add one line per interface you have
111 - // EDIT:
112 - // EDIT: name div id json data graph vertical axis title
113 - // EDIT: --------------------------------------------------------------------------------------------------
114 -EOF
115 -
116 -for x in $all
117 -do
118 - y=`echo "$x" | tr ".-" "__"`
119 -
120 - title=
121 - vtitle=
122 - case "$x" in
123 - net.*)
124 - title="Network Usage for "
125 - vtitle="bandwidth in kilobits/s"
126 - ;;
127 -
128 - disk.*)
129 - title="Disk I/O for "
130 - vtitle="I/O in kilobytes/s"
131 - ;;
132 -
133 - tc.*)
134 - title="Class utilization for "
135 - vtitle="bandwidth in kilobits/s"
136 - ;;
137 -
138 - esac
139 -
140 - eval "NETDATA_TITLE_${y}=\${NETDATA_TITLE_${y}:-${x}}"
141 - eval "t=\${NETDATA_TITLE_${y}}"
142 -
143 - eval "p=\${NETDATA_PRIORITY_${y}}"
144 - if [ ! "$p" = "IGNORE" ]
145 - then
146 - cat >>web/index.html <<EOF2
147 - addChart('${x}', '${y}_div', 0, 0, "/data/${x}/${NETDATA_CONFIG_HISTORY_POINTS}/${NETDATA_CONFIG_UPDATE_EVERY}/average/", "${title}${t} (${x})", "${vtitle}");
148 -EOF2
149 - fi
150 -done
151 -
152 -cat >>web/index.html <<EOF3
153 - refreshCharts(999999);
154 - }
155 -
156 - var refreshCount = 0;
157 - function myChartsRefresh() {
158 - refreshCount += 2;
159 - if(refreshCount > $NETDATA_CONFIG_RELOAD_EVERY) location.reload();
160 -
161 - // refresh up to 2 charts per second
162 - refreshCharts(2);
163 - }
164 -
165 - setInterval(myChartsRefresh, 1000);
166 -
167 - //window.onresize = function(event) {
168 - // refreshCharts(999999);
169 - //};
170 - </script>
171 -
172 - </head>
173 -
174 -<body>
175 - <!--
176 - EDIT: add one div per interface you have
177 - EDIT: use the same id above and bellow!
178 - -->
179 -EOF3
180 -
181 -tmp="/tmp/$RANDOM.netdata.$$.$RANDOM"
182 -for x in $all
183 -do
184 - y=`echo "$x" | tr ".-" "__"`
185 - eval "NETDATA_PRIORITY_${y}=\${NETDATA_PRIORITY_${y}:-${x}}"
186 - eval "t=\${NETDATA_PRIORITY_${y}}"
187 - if [ ! "$t" = "IGNORE" ]
188 - then
189 - echo "${t}|${y}"
190 - fi
191 -done >"${tmp}"
192 -
193 -for x in `cat "${tmp}" | sort`
194 -do
195 - n="`echo "$x" | cut -d '|' -f 2-`"
196 - cat >>web/index.html <<EOF4
197 - <div id="${n}_div"></div>
198 -EOF4
199 -done
200 -rm -f "${tmp}"
201 -
202 -cat >>web/index.html <<EOF5
203 - </body>
204 -</html>
205 -EOF5
206 -
65 if [ "$USER" = "root" ]
66 then
67 chown -R "$NETDATA_CONFIG_USER" web || exit 1
@@ -211,8 +69,13 @@ then
69 chmod -R 0664 web/* || exit 1
70 fi
71
72 +# merge the server variables into the config
73 +eval "`wget -O - http://localhost:$NETDATA_CONFIG_PORT/envlist 2>/dev/null`"
74 +
75 # save config back
215 -set|grep ^NETDATA_ >netdata.conf
76 +set|grep ^NETDATA_CONFIG_ >netdata.conf
77 +set|grep ^NETDATA_PRIORITY_ >>netdata.conf
78 +set|grep ^NETDATA_TITLE_ >>netdata.conf
79
80 echo "All Done."
81 echo "Just hit http://127.0.0.1:$NETDATA_CONFIG_PORT/ from your browser."