Project

General

Profile

Download (14.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	status_rrd_graph.php
5
	Part of pfSense
6
	Copyright (C) 2004 Scott Ullrich
7
	All rights reserved.
8

    
9
	Originally part of m0n0wall (http://m0n0.ch/wall)
10
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
	All rights reserved.
12

    
13
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15

    
16
	1. Redistributions of source code must retain the above copyright notice,
17
	   this list of conditions and the following disclaimer.
18

    
19
	2. Redistributions in binary form must reproduce the above copyright
20
	   notice, this list of conditions and the following disclaimer in the
21
	   documentation and/or other materials provided with the distribution.
22

    
23
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
	POSSIBILITY OF SUCH DAMAGE.
33
*/
34

    
35
require("guiconfig.inc");
36

    
37
if ($_GET['if']) {
38
	$curif = $_GET['if'];
39
	$ifnum = $config['interfaces'][$curif]['if'];
40
} else {
41
	$curif = "wan";
42
	$ifnum = get_real_wan_interface();
43
}
44

    
45
if ($_GET['graph']) {
46
	$curgraph = $_GET['graph'];
47
} else {
48
	$curgraph = "traffic";
49
}
50

    
51
$pgtitle = "Status: RRD Graphs";
52
include("head.inc");
53

    
54
?>
55

    
56
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
57
<?php include("fbegin.inc"); ?>
58
<p class="pgtitle"><?=$pgtitle?></p>
59
<?php
60
$ifdescrs = array('wan' => 'WAN', 'lan' => 'LAN');
61
$graphs = array('traffic' => 'Traffic', 'quality' => 'Quality', 'queues' => 'Queues', 'packets' => 'Packets', 'spamd' => 'Spamd');
62

    
63
for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) {
64
	$ifdescrs['opt' . $j] = $config['interfaces']['opt' . $j]['descr'];
65
}
66
?>
67
<form name="form1" action="status_rrd_graph.php" method="get" style="padding-bottom: 10px; margin-bottom: 14px; 
68
border-bottom: 1px solid #999999">
69
Interface:
70
<select name="if" class="formfld" style="z-index: -10;" onchange="document.form1.submit()">
71
<?php
72
foreach ($ifdescrs as $ifn => $ifd) {
73
	echo "<option value=\"$ifn\"";
74
	if ($ifn == $curif) echo " selected";
75
	echo ">" . htmlspecialchars($ifd) . "</option>\n";
76
}
77
?>
78
</select>
79
Graph:
80
<select name="graph" class="formfld" style="z-index: -10;" onchange="document.form1.submit()">
81
<?php
82
foreach ($graphs as $graph => $graphd) {
83
	echo "<option value=\"$graph\"";
84
	if ($graph == $curgraph) echo " selected";
85
	echo ">" . htmlspecialchars($graphd) . "</option>\n";
86
}
87
?>
88
</select>
89
</form>
90
<p>
91
<div>
92
<?php
93

    
94
$periods = array("2h", "6h", "48h", "14d", "2m", "18m");
95
$graphs['2h']['seconds'] = 7200;
96
$graphs['2h']['average'] = 60;
97
$graphs['2h']['scale'] = "MINUTE:5:MINUTE:10:MINUTE:30:0:%H%:%M";
98
$graphs['6h']['seconds'] = 21600;
99
$graphs['6h']['average'] = 300;
100
$graphs['6h']['scale'] = "MINUTE:10:MINUTE:30:MINUTE:30:0:%H%:%M";
101
$graphs['48h']['seconds'] = 108000;
102
$graphs['48h']['average'] = 300;
103
$graphs['48h']['scale'] = "HOUR:1:HOUR:6:HOUR:2:0:%H";
104
$graphs['14d']['seconds'] = 1209600;
105
$graphs['14d']['average'] = 600;
106
$graphs['14d']['scale'] = "HOUR:6:DAY:1:DAY:1:0:%a";
107
$graphs['2m']['seconds'] = 5184000;
108
$graphs['2m']['average'] = 3600;
109
$graphs['2m']['scale'] = "DAY:1:WEEK:1:WEEK:1:0:Week %W";
110
$graphs['18m']['seconds'] = 46656000;
111
$graphs['18m']['average'] = 86400;
112
$graphs['18m']['scale'] = "MONTH:1:MONTH:1:MONTH:1:0:%b";
113

    
114
$rrddbpath = "/var/db/rrd/";
115
$traffic = "-traffic.rrd";
116
$quality = "-quality.rrd";
117
$queues = "-queues.rrd";
118
$packets = "-packets.rrd";
119
$spamd = "spamd.rrd";
120
$rrdtool = "/usr/local/bin/rrdtool";
121
$uptime = "/usr/bin/uptime";
122
$sed = "/usr/bin/sed";
123

    
124
/* FIXME: We need real shaper speeds here, yes i have a 22/2Mbps 
125
internet connection */
126
/* compare bytes/sec counters, divide bps by 8 */
127
$downstream = (22000000/8);
128
$upstream   =  (2000000/8);
129

    
130
/* FIXME: determine down and up interface, note: case insensitive */
131
$upif = "wan";
132
$downif = "lan";
133

    
134
foreach($periods as $period => $interval) {
135

    
136
/* generate the graphs when we request the page. */
137
$seconds = $graphs[$interval]['seconds'];
138
$average = $graphs[$interval]['average'];
139
$scale = $graphs[$interval]['scale'];
140

    
141
if(($curgraph == "traffic") && (file_exists("$rrddbpath$curif$traffic"))) {
142
	/* define graphcmd for traffic stats */
143
	$graphcmd = "$rrdtool graph $rrddbpath$curif-$interval-$curgraph.png \\
144
		--start -$seconds -e -$average \\
145
		--vertical-label \"bits/sec\" \\
146
		--title \"`hostname` - $curgraph - $interval\" \\
147
		--height 100 --width 650 -x \"$scale\" \\
148
		DEF:$curif-in_bytes=$rrddbpath$curif$traffic:in:AVERAGE \\
149
		DEF:$curif-out_bytes=$rrddbpath$curif$traffic:out:AVERAGE \\
150
		\"CDEF:$curif-in_bits=$curif-in_bytes,8,*\" \\
151
		\"CDEF:$curif-out_bits=$curif-out_bytes,8,*\" \\
152
		\"CDEF:$curif-bits_io=$curif-in_bits,$curif-out_bits,+\" \\
153
		\"CDEF:$curif-out_bits_neg=$curif-out_bits,-1,*\" \\
154
		\"CDEF:$curif-bytes_in=$curif-in_bytes,0,12500000,LIMIT,UN,0,$curif-in_bytes,IF,$average,*\" \\
155
		\"CDEF:$curif-bytes_out=$curif-out_bytes,0,12500000,LIMIT,UN,0,$curif-out_bytes,IF,$average,*\" \\
156
		\"CDEF:$curif-bytes=$curif-bytes_in,$curif-bytes_out,+\" \\
157
		\"CDEF:$curif-bytes_in_t=$curif-in_bytes,0,12500000,LIMIT,UN,0,$curif-in_bytes,IF,$seconds,*\" \\
158
		\"CDEF:$curif-bytes_out_t=$curif-out_bytes,0,12500000,LIMIT,UN,0,$curif-out_bytes,IF,$seconds,*\" \\
159
		\"CDEF:$curif-bytes_t=$curif-bytes_in_t,$curif-bytes_out_t,+\" \\
160
		AREA:$curif-in_bits#990000:$curif-in \\
161
		AREA:$curif-out_bits_neg#666666:$curif-out \\
162
		COMMENT:\"\\n\"\\
163
		COMMENT:\"\t\t  maximum       average       current        period\\n\"\\
164
		COMMENT:\"in\t\"\\
165
		GPRINT:$curif-in_bits:MAX:'%7.2lf %sb/s'\\
166
		GPRINT:$curif-in_bits:AVERAGE:'%7.2lf %Sb/s'\\
167
		GPRINT:$curif-in_bits:LAST:'%7.2lf %Sb/s'\\
168
		GPRINT:$curif-bytes_in_t:AVERAGE:'%7.2lf %sB i'\\
169
		COMMENT:\"\\n\"\\
170
		COMMENT:\"out\t\"\\
171
		GPRINT:$curif-out_bits:MAX:'%7.2lf %sb/s'\\
172
		GPRINT:$curif-out_bits:AVERAGE:'%7.2lf %Sb/s'\\
173
		GPRINT:$curif-out_bits:LAST:'%7.2lf %Sb/s'\\
174
		GPRINT:$curif-bytes_out_t:AVERAGE:'%7.2lf %sB o'\\
175
		COMMENT:\"\\n\"\\
176
		COMMENT:\"totals\"\\
177
		GPRINT:$curif-bits_io:MAX:'%7.2lf %sb/s'\\
178
		GPRINT:$curif-bits_io:AVERAGE:'%7.2lf %sb/s'\\
179
		GPRINT:$curif-bits_io:LAST:'%7.2lf %sb/s'\\
180
		GPRINT:$curif-bytes_t:AVERAGE:'%7.2lf %sB t'\\
181
        	COMMENT:\"\\n\"\\
182
		COMMENT:\"\t\t\t\t\t\t\t\t\t\t\t\t\t\t`date +\"%b %d %H\:%M\:%S %Y\"`\"";
183
	}
184
elseif(($curgraph == "packets") && (file_exists("$rrddbpath$curif$packets"))) {
185
	/* define graphcmd for packets stats */
186
	$graphcmd = "$rrdtool graph $rrddbpath$curif-$interval-$curgraph.png \\
187
		--start -$seconds -e -$average \\
188
		--vertical-label \"packets/sec\" \\
189
		--title \"`hostname` - $curgraph - $interval\" \\
190
		--height 100 --width 650 -x \"$scale\" \\
191
		DEF:$curif-in_pps=$rrddbpath$curif$packets:in:AVERAGE \\
192
		DEF:$curif-out_pps=$rrddbpath$curif$packets:out:AVERAGE \\
193
		\"CDEF:$curif-out_pps_neg=$curif-out_pps,-1,*\" \\
194
		\"CDEF:$curif-pps_in=$curif-in_pps,0,12500000,LIMIT,UN,0,$curif-in_pps,IF,$average,*\" \\
195
		\"CDEF:$curif-pps_out=$curif-out_pps,0,12500000,LIMIT,UN,0,$curif-out_pps,IF,$average,*\" \\
196
		\"CDEF:$curif-pps_io=$curif-in_pps,$curif-out_pps,+\" \\
197
		\"CDEF:$curif-pps=$curif-pps_in,$curif-pps_out,+\" \\
198
		\"CDEF:$curif-pps_in_t=$curif-in_pps,0,12500000,LIMIT,UN,0,$curif-in_pps,IF,$seconds,*\" \\
199
		\"CDEF:$curif-pps_out_t=$curif-out_pps,0,12500000,LIMIT,UN,0,$curif-out_pps,IF,$seconds,*\" \\
200
		\"CDEF:$curif-pps_t=$curif-pps_in_t,$curif-pps_out_t,+\" \\
201
		AREA:$curif-in_pps#990000:$curif-in \\
202
		AREA:$curif-out_pps_neg#666666:$curif-out \\
203
		COMMENT:\"\\n\"\\
204
		COMMENT:\"\t\t  maximum       average       current        period\\n\"\\
205
		COMMENT:\"in\t\"\\
206
		GPRINT:$curif-in_pps:MAX:'%7.2lf %s pps'\\
207
		GPRINT:$curif-in_pps:AVERAGE:'%7.2lf %S pps'\\
208
		GPRINT:$curif-in_pps:LAST:'%7.2lf %S pps'\\
209
		GPRINT:$curif-pps_in_t:AVERAGE:'%7.2lf %s pkts'\\
210
		COMMENT:\"\\n\"\\
211
		COMMENT:\"out\t\"\\
212
		GPRINT:$curif-out_pps:MAX:'%7.2lf %s pps'\\
213
		GPRINT:$curif-out_pps:AVERAGE:'%7.2lf %S pps'\\
214
		GPRINT:$curif-out_pps:LAST:'%7.2lf %S pps'\\
215
		GPRINT:$curif-pps_out_t:AVERAGE:'%7.2lf %s pkts'\\
216
		COMMENT:\"\\n\"\\
217
		COMMENT:\"totals\"\\
218
		GPRINT:$curif-pps_io:MAX:'%7.2lf %s pps'\\
219
		GPRINT:$curif-pps_io:AVERAGE:'%7.2lf %s pps'\\
220
		GPRINT:$curif-pps_io:LAST:'%7.2lf %s pps'\\
221
		GPRINT:$curif-pps_t:AVERAGE:'%7.2lf %s pkts'\\
222
        	COMMENT:\"\\n\"\\
223
		COMMENT:\"\t\t\t\t\t\t\t\t\t\t\t\t\t\t`date +\"%b %d %H\:%M\:%S %Y\"`\"";
224
	}
225
elseif(($curgraph == "queues") && (file_exists("$rrddbpath$curif$queues"))) {
226
	/* define graphcmd for queue stats */
227
	$graphcmd = "$rrdtool graph $rrddbpath$curif-$interval-$curgraph.png \\
228
		--start -$seconds -e -$average \\
229
		--vertical-label \"bits/sec\" \\
230
		--title \"`hostname` - $curgraph - $interval\" \\
231
		--height 200 --width 650 -x \"$scale\" \\";
232
		if (!is_array($config['shaper']['queue'])) {
233
			$config['shaper']['queue'] = array();
234
		}
235
		$a_queues = &$config['shaper']['queue'];
236
		/* determine in and out interface at a later time. Asume wan for now.*/
237
		$i = 0;
238
		$t = 0;
239
		$colors = array('000000','7B0000','990000','BB0000','CC0000','D90000','EE0000','FF0000','CC0000');
240
		foreach ($a_queues as $queue) {
241
			$name = $queue['name'];
242
			if((stristr($name, "$upif")) || (stristr($name, "up"))) {
243
				$color = "$colors[$t]";
244
				if($t > 0) { $stack = ":STACK"; }
245
				$graphcmd .= "DEF:$name=$rrddbpath$curif$queues:$name:AVERAGE \\
246
					\"CDEF:$name-bytes_out=$name,0,$upstream,LIMIT,UN,0,$name,IF\" \\
247
					\"CDEF:$name-bits_out=$name-bytes_out,8,*\" \\
248
					\"CDEF:$name-bits_out_neg=$name-bits_out,-1,*\" \\
249
					AREA:$name-bits_out_neg#${color}:$name$stack \\";
250
					$t++;
251
					if($t > 7) { $t = 0; }
252
			}
253
		}
254
		$graphcmd .= "COMMENT:\"\\n\" \\";
255
		$colors = array('000000','7B7B7B','999999','BBBBBB','CCCCCC','D9D9D9','EEEEEE','FFFFFF','CCCCCC');
256
		$stack = "";
257
		foreach ($a_queues as $queue) {
258
			$name = $queue['name'];
259
			if((stristr($name, "$downif")) || (stristr($name, "down"))) {
260
				$color = "$colors[$i]";
261
				if($i > 0) { $stack = ":STACK"; }
262
				$graphcmd .= "DEF:$name=$rrddbpath$curif$queues:$name:AVERAGE \\
263
					\"CDEF:$name-bytes_in=$name,0,$downstream,LIMIT,UN,0,$name,IF\" \\
264
					\"CDEF:$name-bits_in=$name-bytes_in,8,*\" \\
265
					AREA:$name-bits_in#${color}:$name$stack \\";
266
					$i++;
267
					if($i > 7) { $i = 0; }
268
			}
269
		}
270
		$graphcmd .= "COMMENT:\"\\n\" \\";
271
		$graphcmd .= "COMMENT:\"\t\t\t\t\t\t\t\t\t\t\t\t\t\t`date +\"%b %d %H\:%M\:%S %Y\"`\"";
272
	}
273
elseif(($curgraph == "quality") && (file_exists("$rrddbpath$curif$quality"))) {
274
	/* make a link quality graphcmd, we only have WAN for now, others too follow */
275
	$graphcmd = "$rrdtool graph $rrddbpath$curif-$interval-$curgraph.png \\
276
		--start -$seconds -e -$average \\
277
		--title=\"Link quality last $interval for $curif\" \\
278
		--vertical-label \"ms / %\" \\
279
		--height 100 --width 650 \\
280
		-x \"$scale\" --lower-limit 0 \\
281
		DEF:roundtrip=$rrddbpath$curif$quality:roundtrip:AVERAGE \\
282
		DEF:loss=$rrddbpath$curif$quality:loss:AVERAGE \\
283
		\"CDEF:roundavg=roundtrip,PREV(roundtrip),+,2,/\" \\
284
		\"CDEF:loss10=loss,10,*\" \\
285
		\"CDEF:r0=roundtrip,20,MIN\" \\
286
		\"CDEF:r1=roundtrip,60,MIN\" \\
287
		\"CDEF:r2=roundtrip,180,MIN\" \\
288
		\"CDEF:r3=roundtrip,420,MIN\" \\
289
		COMMENT:\"               * Roundtrip *                                     * Packet loss *\\n\" \\
290
		COMMENT:\"\\n\" \\
291
		COMMENT:\"  \" \\
292
		AREA:roundtrip#990000:\"> 420      ms\" \\
293
		GPRINT:roundtrip:MIN:\"    Min\\: %7.2lf ms\" \\
294
		COMMENT:\"               \" \\
295
		GPRINT:loss:MIN:\"Min\\: %3.1lf %%\\n\" \\
296
		COMMENT:\"  \" \\
297
    		AREA:r3#a83c3c:\"180-420    ms\" \\
298
		GPRINT:roundtrip:AVERAGE:\"    Avg\\: %7.2lf ms\" \\
299
		COMMENT:\"               \" \\
300
		GPRINT:loss:AVERAGE:\"Avg\\: %3.1lf %%\" \\
301
		COMMENT:\"   Packet loss multiplied\\n\" \\
302
		COMMENT:\"  \" \\
303
		AREA:r2#b36666:\"60-180     ms\" \\
304
		GPRINT:roundtrip:MAX:\"    Max\\: %7.2lf ms\" \\
305
		COMMENT:\"               \" \\
306
		GPRINT:loss:MAX:\"Max\\: %3.1lf %%\" \\
307
		COMMENT:\"   by 10 in graph.\\n\" \\
308
		COMMENT:\"  \" \\
309
		AREA:r1#bd9090:\"20-60      ms\" \\
310
		COMMENT:\"\\n\" \\
311
		COMMENT:\"  \" \\
312
		AREA:r0#cccccc:\"< 20       ms\" \\
313
		GPRINT:roundtrip:LAST:\"    Last\\: %7.2lf ms\" \\
314
		COMMENT:\"              \" \\
315
		GPRINT:loss:LAST:\"Last\: %3.1lf %%\" \\
316
		COMMENT:\"   \" \\
317
		AREA:loss10#ee0000:\"Packet loss\\n\" \\
318
		COMMENT:\"  \" \\
319
		LINE1:roundtrip#000000:\"roundtrip average\\n\" \\
320
		COMMENT:\"\t\t\t\t\t\t\t\t\t\t\t\t\t\t`date +\"%b %d %H\:%M\:%S %Y\"`\"";
321
	}
322
elseif(($curgraph == "spamd") && (file_exists("$rrddbpath$spamd"))) {
323
	/* graph a spamd statistics graph */
324
	$graphcmd = "$rrdtool graph $rrddbpath$curif-$interval-$curgraph.png \\
325
		--start -$seconds -e -$average \\
326
		--title=\"Spamd statistics for last $interval\" \\
327
		--vertical-label=\"Conn / Time, sec.\" \\
328
		--height 150 --width 650 --no-gridfit \\
329
		-x \"$scale\" --lower-limit 0  \\
330
		DEF:consmin=$rrddbpath$spamd:conn:MIN \\
331
		DEF:consavg=$rrddbpath$spamd:conn:AVERAGE \\
332
		DEF:consmax=$rrddbpath$spamd:conn:MAX \\
333
		DEF:timemin=$rrddbpath$spamd:time:MIN \\
334
		DEF:timeavg=$rrddbpath$spamd:time:AVERAGE \\
335
		DEF:timemax=$rrddbpath$spamd:time:MAX \\
336
		\"CDEF:timeminadj=timemin,0,86400,LIMIT,UN,0,timemin,IF\" \\
337
		\"CDEF:timeavgadj=timeavg,0,86400,LIMIT,UN,0,timeavg,IF\" \\
338
		\"CDEF:timemaxadj=timemax,0,86400,LIMIT,UN,0,timemax,IF\" \\
339
		\"CDEF:t1=timeminadj,timeavgadj,+,2,/,timeminadj,-\" \\
340
		\"CDEF:t2=timeavgadj,timemaxadj,+,2,/,timeminadj,-,t1,-\" \\
341
		\"CDEF:t3=timemaxadj,timeminadj,-,t1,-,t2,-\" \\
342
		AREA:timeminadj \\
343
		AREA:t1#DDDDFF::STACK \\
344
		AREA:t2#AAAAFF::STACK \\
345
		AREA:t3#DDDDFF::STACK \\
346
		LINE2:timeavgadj#000066:\"Time \" \\
347
		GPRINT:timeminadj:MIN:\"Min\\:%6.2lf\\t\" \\
348
		GPRINT:timeavgadj:AVERAGE:\"Avg\\:%6.2lf\\t\" \\
349
		GPRINT:timemaxadj:MAX:\"Max\\:%6.2lf\\n\" \\
350
		AREA:consmax#00AA00BB \\
351
		AREA:consmin#FFFFFFFF \\
352
		LINE1:consmin#00660088 \\
353
		LINE1:consmax#FFFFFF88 \\
354
		LINE1:consavg#006600:\"Cons \" \\
355
		GPRINT:consmin:MIN:\"Min\\:%6.2lf\\t\" \\
356
		GPRINT:consavg:AVERAGE:\"Avg\\:%6.2lf\\t\" \\
357
		GPRINT:consmax:MAX:\"Max\\:%6.2lf\\n\" \\
358
		COMMENT:\"\t\t\t\t\t\t\t\t\t\t\t\t\t\t`date +\"%b %d %H\:%M\:%S %Y\"`\"";
359
	}
360
else
361
	{
362
		PRINT "<b>Sorry we do not have data to graph $curgraph for $curif with.</b><br>";
363
		break;
364
	} 
365

    
366
	/* check modification time to see if we need to generate image */
367
	if (file_exists("$rrddbpath$curif-$interval-$curgraph.png")) {
368
		if((time() - filemtime("$rrddbpath$curif-$interval-$curgraph.png")) >= 280 ) {
369
			system("$graphcmd >/dev/null");
370
			usleep(500);
371
		}			
372
	} else {
373
		system("$graphcmd >/dev/null");
374
		usleep(500);
375
	}
376

    
377
PRINT "<B>Analysis for $curif -- $interval $curgraph</B><BR>";
378
PRINT "<IMG BORDER=1 ALT=\"$ifname $curgraph Graph\" 
379
SRC=\"rrd/$curif-$interval-$curgraph.png\"><BR><BR>";
380
}
381

    
382
?>
383

    
384
</div>
385

    
386
<meta http-equiv="refresh" content="300;url=<?php print $_SERVER['PHP_SELF']; ?>">
387

    
388
<?php include("fend.inc"); ?>
389
</body>
390
</html>
(122-122/162)