Project

General

Profile

Download (14.4 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("6h", "30h", "10d", "400d");
95
$graphs['6h']['seconds'] = 21600;
96
$graphs['6h']['average'] = 300;
97
$graphs['6h']['scale'] = "MINUTE:10:MINUTE:30:MINUTE:30:0:%H%:%M";
98
$graphs['30h']['seconds'] = 108000;
99
$graphs['30h']['average'] = 1200;
100
$graphs['30h']['scale'] = "HOUR:1:HOUR:6:HOUR:2:0:%H";
101
$graphs['10d']['seconds'] = 864000;
102
$graphs['10d']['average'] = 7200;
103
$graphs['10d']['scale'] = "HOUR:6:DAY:1:DAY:1:0:%a";
104
$graphs['400d']['seconds'] = 34560000;
105
$graphs['400d']['average'] = 86400;
106
$graphs['400d']['scale'] = "MONTH:1:MONTH:1:MONTH:1:0:%b";
107

    
108
$rrddbpath = "/var/db/rrd/";
109
$traffic = "-traffic.rrd";
110
$quality = "-quality.rrd";
111
$queues = "-queues.rrd";
112
$packets = "-packets.rrd";
113
$spamd = "spamd.rrd";
114
$rrdtool = "/usr/local/bin/rrdtool";
115
$uptime = "/usr/bin/uptime";
116
$sed = "/usr/bin/sed";
117

    
118
foreach($periods as $period => $interval) {
119

    
120
/* generate the graphs when we request the page. */
121
$seconds = $graphs[$interval]['seconds'];
122
$average = $graphs[$interval]['average'];
123
$scale = $graphs[$interval]['scale'];
124

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

    
351
	/* check modification time to see if we need to generate image */
352
	if (file_exists("$rrddbpath$curif-$interval-$curgraph.png")) {
353
		if((time() - filemtime("$rrddbpath$curif-$interval-$curgraph.png")) >= 60 ) {
354
			system("$graphcmd 2>&1");
355
			usleep(500);
356
		}			
357
	} else {
358
		system("$graphcmd 2>&1");
359
		usleep(500);
360
	}
361

    
362
PRINT "<B>Analysis for $curif -- $interval $curgraph</B><BR>";
363
PRINT "<IMG BORDER=1 ALT=\"$ifname $curgraph Graph\" 
364
SRC=\"rrd/$curif-$interval-$curgraph.png\"><BR><BR>";
365
}
366

    
367
?>
368

    
369
</div>
370

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

    
373
<?php include("fend.inc"); ?>
374
</body>
375
</html>
(122-122/162)