@cryptotaxi247 / netdata-1 / commits / 574dc94a8

the run directory is ready for web server access

box@home root committed Oct 22, 2013 at 21:06 UTC 574dc94a84c39337603ffcdfa0576089d727a7b5
2 files changed +43 -24
README.md
+3 -1
@@ -43,9 +43,11 @@ Your browser will hit the web server to fetch the JSON data and refresh the grap
43 For this to work, you need to have persmission to create a directory in /run or /var/run or /tmp.
44 If you run into problems, try to become root to verify it works.
45
46 -Once you run it, the file all.config will be created. You can edit this file to set options for each graph.
46 +Once you run it, the file netdata.conf will be created. You can edit this file to set options for each graph.
47 To apply the changes you made, you have to run netdata.start again.
48
49 +The directory /run/netdata (or /var/run/netdata, or /tmp/netdata depending on your distro) is ready to be
50 +served by a web server (it contains all files needed). Just link it to your htdocs and access it from your web browser.
51
52 ---
53
netdata.start
+40 -23
@@ -1,6 +1,5 @@
1 #!/bin/bash
2
3 -
3 base="`dirname "$0"`"
4
5 if [ ! -d "$base" -o ! -f "$base/netdata.c" ]
@@ -10,11 +9,20 @@ then
9 fi
10 cd "$base" || exit 1
11
13 -NETDATA_UPDATE_EVERY=1
14 -NETDATA_HISTORY_POINTS=60
15 -if [ -f all.config ]
12 +# every how many seconds to update the JSON files
13 +NETDATA_CONFIG_UPDATE_EVERY=1
14 +
15 +# how many points should the graphs have
16 +NETDATA_CONFIG_HISTORY_POINTS=60
17 +
18 +# every how many graph refreshes, the page should be reloaded
19 +# this fixes a bug in the google graphs API which leaks memory
20 +# when refreshes graphs
21 +NETDATA_CONFIG_RELOAD_EVERY=500
22 +
23 +if [ -f netdata.conf ]
24 then
17 - source all.config
25 + source netdata.conf
26 fi
27
28 echo "Creating a directory for netdata..."
@@ -24,7 +32,7 @@ do
32 echo " Trying '${x}'..."
33 if [ ! -d "${x}" ]
34 then
27 - mkdir "${x}"
35 + mkdir "${x}" 2>/dev/null
36 if [ $? -eq 0 ]
37 then
38 echo " OK. '${x}' works."
@@ -55,16 +63,17 @@ Header set Pragma "no-cache"
63
64 EOFHTACCESS
65
58 -rm "${data}"/*.json
59 -
66 echo "Stopping a (possibly) running netdata..."
67 killall netdata 2>/dev/null
68
69 +sleep 1
70 +rm "${data}"/*.json
71 +
72 echo "Compiling netdata"
73 gcc -O3 -o netdata netdata.c || exit 1
74
75 echo "Starting netdata"
67 -./netdata -d -u $NETDATA_UPDATE_EVERY -l $NETDATA_HISTORY_POINTS -o "${data}" || exit 1
76 +./netdata -d -u $NETDATA_CONFIG_UPDATE_EVERY -l $NETDATA_CONFIG_HISTORY_POINTS -o "${data}" || exit 1
77
78 echo "Waiting 2 seconds for the JSON files"
79 # wait 2 seconds for the JSON files to be generated
@@ -132,9 +141,11 @@ then
141 h=10
142 fi
143
135 -echo "Generating all.html"
144 +cp "${base}/netdata.js" "${data}/"
145 +
146 +echo "Generating ${data}/index.html"
147 host="`hostname`"
137 -cat >all.html <<EOF
148 +cat >${data}/index.html <<EOF
149 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
150 <html xmlns="http://www.w3.org/1999/xhtml">
151 <style>
@@ -173,31 +184,31 @@ do
184 eval "p=\${NETDATA_PRIORITY_${y}}"
185 if [ ! "$p" = "IGNORE" ]
186 then
176 - cat >>all.html <<EOF2
187 + cat >>${data}/index.html <<EOF2
188 drawChart('${x}', '${x}_div', width, height, "data/${x}.json", "${t}");
189 EOF2
190 fi
191 done
192
182 -ref=$[4 * NETDATA_UPDATE_EVERY]
183 -tim=$[1000 * NETDATA_UPDATE_EVERY]
193 +ref=$[4 * NETDATA_CONFIG_UPDATE_EVERY]
194 +tim=$[1000 * NETDATA_CONFIG_UPDATE_EVERY]
195 if [ $count -gt 4 ]
196 then
197 ref=1
187 - tim=$[1000 * NETDATA_UPDATE_EVERY / count]
188 - if [ $tim -lt $[100 * NETDATA_UPDATE_EVERY] ]
198 + tim=$[1000 * NETDATA_CONFIG_UPDATE_EVERY / count]
199 + if [ $tim -lt $[100 * NETDATA_CONFIG_UPDATE_EVERY] ]
200 then
190 - tim=$[100 * NETDATA_UPDATE_EVERY]
201 + tim=$[100 * NETDATA_CONFIG_UPDATE_EVERY]
202 fi
203 fi
204
194 -cat >>all.html <<EOF3
205 +cat >>${data}/index.html <<EOF3
206 }
207
208 var refreshCount = 0;
209 function myChartsRefresh() {
210 refreshCount++;
200 - if(refreshCount > 1000) location.reload();
211 + if(refreshCount > $NETDATA_CONFIG_RELOAD_EVERY) location.reload();
212
213 // refresh up to $ref charts per second
214 refreshCharts($ref);
@@ -230,19 +241,25 @@ done >"${tmp}"
241 for x in `cat "${tmp}" | sort`
242 do
243 n="`echo "$x" | cut -d '.' -f 2-`"
233 - cat >>all.html <<EOF4
244 + cat >>${data}/index.html <<EOF4
245 <div id="${n}_div"></div>
246 EOF4
247 done
248 rm -f "${tmp}"
249
239 -cat >>all.html <<EOF5
250 +cat >>${data}/index.html <<EOF5
251 </body>
252 </html>
253 EOF5
254
244 -set|grep ^NETDATA_ >all.config
255 +set|grep ^NETDATA_ >netdata.conf
256 +
257 +if [ ! -h "${data}/data" ]
258 +then
259 + cd "${data}"
260 + ln -s . data
261 +fi
262
263 echo "All Done."
247 -echo "Just hit all.html from your browser."
264 +echo "Just hit netdata/ from your browser."
265