]> arthur.barton.de Git - netdata.git/blob - netdata.start
fixed url
[netdata.git] / netdata.start
1 #!/bin/bash
2
3 base="`dirname "$0"`"
4
5 if [ ! -d "$base" -o ! -f "$base/netdata.c" ]
6 then
7         echo >&2 "Cannot find my home directory '${base}'."
8         exit 1
9 fi
10 cd "$base" || exit 1
11
12 # every how many seconds to show the graphs
13 NETDATA_CONFIG_UPDATE_EVERY=2
14
15 # the detail of the data that will be kept in netdata
16 NETDATA_CONFIG_INTERNAL_UPDATE_EVERY=1
17
18 # how many points should the graphs have
19 NETDATA_CONFIG_HISTORY_POINTS=120
20
21 # how many points should be kept in memory
22 NETDATA_CONFIG_HISTORY_DATA=3600
23
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
28
29 if [ -f netdata.conf ]
30 then
31         source netdata.conf
32 fi
33
34 # how many history lines to keep in netdata
35 NETDATA_HISTORY_LINES=$[NETDATA_CONFIG_UPDATE_EVERY * NETDATA_CONFIG_HISTORY_POINTS / NETDATA_CONFIG_INTERNAL_UPDATE_EVERY]
36
37 echo "Creating a directory for netdata..."
38 data=
39 for x in /run/netdata /var/run/netdata /tmp/netdata
40 do
41         echo "  Trying '${x}'..."
42         if [ ! -d "${x}" ]
43         then
44                 mkdir "${x}" 2>/dev/null
45                 if [ $? -eq 0 ]
46                 then
47                         echo "  OK. '${x}' works."
48                         data="${x}"
49                         break
50                 fi
51         else
52                 echo "  OK. '${x}' works."
53                 data="${x}"
54                 break
55         fi
56 done
57
58 if [ -z "${data}" ]
59 then
60         echo >&2 "Cannot find where to put netdata files."
61         exit 1
62 fi
63
64 if [ -h data ]
65 then
66         echo "Removing existing $base/data link"
67         rm data || exit 1
68 fi
69
70 if [ ! -d data ]
71 then
72         echo "Linking '${data}' to $base/data"
73         ln -s "${data}" data || exit 1
74 else
75         echo >&2 "Directory $base/data already exists. Not touching it, however it should be a link '${data}'."
76 fi
77
78 cp "${base}/all.xsl" "${data}/"
79 cp "${base}/netdata.js" "${data}/"
80 cp "${base}/tc-all.sh" "${data}/"
81 chmod 700 "${data}/tc-all.sh"
82
83 echo "Finding proper parameters for dashboard..."
84
85 echo "Stopping a (possibly) running netdata..."
86 killall netdata 2>/dev/null
87 killall tc-all.sh 2>/dev/null
88
89 echo "Compiling netdata"
90 # gcc -Wall -O3 -o netdata netdata.c -lpthread || exit 1
91 gcc -Wall -ggdb -o netdata netdata.c -lpthread || exit 1
92
93 echo "Starting netdata"
94 p=`pwd`
95 cd data
96 ulimit -c unlimited
97 $p/netdata -d -u $NETDATA_CONFIG_INTERNAL_UPDATE_EVERY -l $NETDATA_HISTORY_LINES || exit 1
98 cd "$p"
99
100 sleep 2
101
102 # count all graphs
103 all=`wget http://127.0.0.1:19999/list -O - 2>/dev/null`
104 count=0
105 for x in $all
106 do
107         y=`echo "$x" | tr ".-" "__"`
108         eval "t=\${NETDATA_PRIORITY_${y}}"
109         if [ ! "$t" = "IGNORE" ]
110         then
111                 count=$[count + 1]
112         fi
113 done
114
115 echo "We have $count graphs..."
116
117 echo "Generating ${data}/index.html"
118 host="`hostname`"
119 cat >${data}/index.html <<EOF
120 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
121 <html xmlns="http://www.w3.org/1999/xhtml">
122 <style>
123         * {font-family:Arial}
124         div {float: left; margin: 0 0 0 0; }
125 </style>
126 <title>${host} netdata</title>
127 <head>
128         <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
129
130         <!--Load the AJAX API-->
131         <script type="text/javascript" src="https://www.google.com/jsapi"></script>
132         <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
133         <script type="text/javascript" src="/file/netdata.js"></script>
134         <script type="text/javascript">
135         
136         // Set a callback to run when the Google Visualization API is loaded.
137         google.setOnLoadCallback(drawCharts);
138         
139         function drawCharts() {
140                 // EDIT: add one line per interface you have
141                 // EDIT: 
142                 // EDIT:   name    div id                    json data           graph                                  vertical axis title
143                 // EDIT: --------------------------------------------------------------------------------------------------
144 EOF
145
146 for x in $all
147 do
148         y=`echo "$x" | tr ".-" "__"`
149
150         title=
151         vtitle=
152         case "$x" in
153                 net.*)
154                         title="Network Usage for "
155                         vtitle="bandwidth in kilobits/s"
156                         ;;
157
158                 disk.*)
159                         title="Disk I/O for "
160                         vtitle="I/O in kilobytes/s"
161                         ;;
162
163                 tc.*)
164                         title="Class utilization for "
165                         vtitle="bandwidth in kilobits/s"
166                         ;;
167
168         esac
169
170         eval "NETDATA_TITLE_${y}=\${NETDATA_TITLE_${y}:-${x}}"
171         eval "t=\${NETDATA_TITLE_${y}}"
172         
173         eval "p=\${NETDATA_PRIORITY_${y}}"
174         if [ ! "$p" = "IGNORE" ]
175         then
176                 cat >>${data}/index.html <<EOF2
177                 addChart('${x}', '${y}_div', 0, 0, "data/${x}/${NETDATA_CONFIG_HISTORY_POINTS}/${NETDATA_CONFIG_UPDATE_EVERY}/average/", "${title}${t} (${x})", "${vtitle}");
178 EOF2
179         fi
180 done
181
182 ref=$[4 * NETDATA_CONFIG_UPDATE_EVERY]
183 tim=$[1000 * NETDATA_CONFIG_UPDATE_EVERY]
184 if [ $count -gt 4 ]
185 then
186         ref=1
187         tim=$[1000 * NETDATA_CONFIG_UPDATE_EVERY / count]
188         if [ $tim -lt $[200 * NETDATA_CONFIG_UPDATE_EVERY] ]
189         then
190                 tim=$[200 * NETDATA_CONFIG_UPDATE_EVERY]
191         fi
192 fi
193
194 cat >>${data}/index.html <<EOF3
195                 refreshCharts(999999);
196         }
197         
198         var refreshCount = 0;
199         function myChartsRefresh() {
200                 refreshCount++;
201                 if(refreshCount > $NETDATA_CONFIG_RELOAD_EVERY) location.reload();
202
203                 // refresh up to $ref charts per second
204                 refreshCharts($ref);
205         }
206         
207         setInterval(myChartsRefresh, $tim);
208
209         //window.onresize = function(event) {
210         //      refreshCharts(999999);
211         //};
212         </script>
213
214         </head>
215
216 <body>
217         <!--
218                 EDIT: add one div per interface you have
219                 EDIT: use the same id above and bellow!
220         -->
221 EOF3
222
223 tmp="/tmp/$RANDOM.netdata.$$.$RANDOM"
224 for x in $all
225 do
226         y=`echo "$x" | tr ".-" "__"`
227         eval "NETDATA_PRIORITY_${y}=\${NETDATA_PRIORITY_${y}:-${x}}"
228         eval "t=\${NETDATA_PRIORITY_${y}}"
229         if [ ! "$t" = "IGNORE" ]
230         then
231                 echo "${t}|${y}"
232         fi
233 done >"${tmp}"
234
235 for x in `cat "${tmp}" | sort`
236 do
237         n="`echo "$x" | cut -d '|' -f 2-`"
238         cat >>${data}/index.html <<EOF4
239         <div id="${n}_div"></div>
240 EOF4
241 done
242 rm -f "${tmp}"
243
244 cat >>${data}/index.html <<EOF5
245  </body>
246 </html>
247 EOF5
248
249 set|grep ^NETDATA_ >netdata.conf
250
251 if [ ! -h "${data}/data" ]
252 then
253         cd "${data}"
254         ln -s . data
255 fi
256
257 echo "All Done."
258 echo "Just hit http://127.0.0.1:19999/ from your browser."
259