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');
|
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("day", "week", "month", "year");
|
95
|
$graphs['day']['seconds'] = 86400;
|
96
|
$graphs['day']['average'] = 300;
|
97
|
$graphs['day']['scale'] = "HOUR:1:HOUR:6:HOUR:2:0:%H";
|
98
|
$graphs['week']['seconds'] = 604800;
|
99
|
$graphs['week']['average'] = 1800;
|
100
|
$graphs['week']['scale'] = "HOUR:6:DAY:1:DAY:1:0:%a";
|
101
|
$graphs['month']['seconds'] = 2592000;
|
102
|
$graphs['month']['average'] = 7200;
|
103
|
$graphs['month']['scale'] = "DAY:1:WEEK:1:WEEK:1:0:Week %W";
|
104
|
$graphs['year']['seconds'] = 31536000;
|
105
|
$graphs['year']['average'] = 86400;
|
106
|
$graphs['year']['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
|
$rrdtool = "/usr/local/bin/rrdtool";
|
113
|
$uptime = "/usr/bin/uptime";
|
114
|
$sed = "/usr/bin/sed";
|
115
|
|
116
|
foreach($periods as $period => $interval) {
|
117
|
|
118
|
/* generate the graphs when we request the page. */
|
119
|
$seconds = $graphs[$interval]['seconds'];
|
120
|
$average = $graphs[$interval]['average'];
|
121
|
$scale = $graphs[$interval]['scale'];
|
122
|
|
123
|
if(($curgraph == "traffic") && (file_exists("$rrddbpath$curif$traffic"))) {
|
124
|
/* define graphcmd for traffic stats */
|
125
|
$graphcmd = "$rrdtool graph $rrddbpath$curif-$interval-$curgraph.png \\
|
126
|
--start -$seconds -e -$average \\
|
127
|
--vertical-label \"bits/sec\" \\
|
128
|
--title \"`hostname` - $curgraph - $interval\" \\
|
129
|
--height 100 --width 650 -x \"$scale\" \\
|
130
|
DEF:$curif-in_bytes=$rrddbpath$curif$traffic:in:AVERAGE \\
|
131
|
DEF:$curif-out_bytes=$rrddbpath$curif$traffic:out:AVERAGE \\
|
132
|
\"CDEF:$curif-in_bits=$curif-in_bytes,8,*\" \\
|
133
|
\"CDEF:$curif-out_bits=$curif-out_bytes,8,*\" \\
|
134
|
\"CDEF:$curif-out_bits_neg=$curif-out_bits,-1,*\" \\
|
135
|
\"CDEF:$curif-bytes_in=$curif-in_bytes,0,12500000,LIMIT,UN,0,$curif-in_bytes,IF,$average,*\" \\
|
136
|
\"CDEF:$curif-bytes_out=$curif-out_bytes,0,12500000,LIMIT,UN,0,$curif-out_bytes,IF,$average,*\" \\
|
137
|
\"CDEF:$curif-bytes=$curif-bytes_in,$curif-bytes_out,+\" \\
|
138
|
AREA:$curif-in_bits#990000:$curif-in \\
|
139
|
AREA:$curif-out_bits_neg#666666:$curif-out \\
|
140
|
COMMENT:\"\\n\"\\
|
141
|
COMMENT:\"\t\t maximum average current\\n\"\\
|
142
|
COMMENT:\"in\t\"\\
|
143
|
GPRINT:$curif-in_bits:MAX:'%7.2lf %sb/s'\\
|
144
|
GPRINT:$curif-in_bits:AVERAGE:'%7.2lf %Sb/s'\\
|
145
|
GPRINT:$curif-in_bits:LAST:'%7.2lf %Sb/s'\\
|
146
|
COMMENT:\"\\n\"\\
|
147
|
COMMENT:\"out\t\"\\
|
148
|
GPRINT:$curif-out_bits:MAX:'%7.2lf %Sb/s'\\
|
149
|
GPRINT:$curif-out_bits:AVERAGE:'%7.2lf %Sb/s'\\
|
150
|
GPRINT:$curif-out_bits:LAST:'%7.2lf %Sb/s'\\
|
151
|
COMMENT:\"\\n\"\\
|
152
|
COMMENT:\"totals\"\\
|
153
|
GPRINT:$curif-bytes_in:AVERAGE:'%7.2lf %sB i'\\
|
154
|
GPRINT:$curif-bytes_out:AVERAGE:'%7.2lf %sB o'\\
|
155
|
GPRINT:$curif-bytes:AVERAGE:'%7.2lf %sB t'\\
|
156
|
COMMENT:\"\\n\"\\
|
157
|
COMMENT:\"\t\t\t\t\t\t\t\t\t\t\t\t\t\t`date +\"%b %d %H\:%M\:%S %Y\"`\"";
|
158
|
}
|
159
|
elseif(($curgraph == "quality") && (file_exists("$rrddbpath$curif$quality"))) {
|
160
|
/* make a link quality graphcmd, we only have WAN for now, others too follow */
|
161
|
$graphcmd = "$rrdtool graph $rrddbpath$curif-$interval-$curgraph.png \\
|
162
|
--start -$seconds -e -$average \\
|
163
|
--title=\"Link quality last $interval for $curif\" \\
|
164
|
--vertical-label \"ms / %\" \\
|
165
|
--height 100 --width 650 \\
|
166
|
-x \"$scale\" --lower-limit 0 \\
|
167
|
DEF:roundtrip=$rrddbpath$curif$quality:roundtrip:AVERAGE \\
|
168
|
DEF:loss=$rrddbpath$curif$quality:loss:AVERAGE \\
|
169
|
\"CDEF:roundavg=roundtrip,PREV(roundtrip),+,2,/\" \\
|
170
|
\"CDEF:loss10=loss,10,*\" \\
|
171
|
\"CDEF:r0=roundtrip,20,MIN\" \\
|
172
|
\"CDEF:r1=roundtrip,60,MIN\" \\
|
173
|
\"CDEF:r2=roundtrip,180,MIN\" \\
|
174
|
\"CDEF:r3=roundtrip,420,MIN\" \\
|
175
|
COMMENT:\" * Roundtrip * * Packet loss *\\n\" \\
|
176
|
COMMENT:\"\\n\" \\
|
177
|
COMMENT:\" \" \\
|
178
|
AREA:roundtrip#990000:\"> 420 ms\" \\
|
179
|
GPRINT:roundtrip:MIN:\" Min\\: %7.2lf ms\" \\
|
180
|
COMMENT:\" \" \\
|
181
|
GPRINT:loss:MIN:\"Min\\: %3.1lf %%\\n\" \\
|
182
|
COMMENT:\" \" \\
|
183
|
AREA:r3#a83c3c:\"180-420 ms\" \\
|
184
|
GPRINT:roundtrip:AVERAGE:\" Avg\\: %7.2lf ms\" \\
|
185
|
COMMENT:\" \" \\
|
186
|
GPRINT:loss:AVERAGE:\"Avg\\: %3.1lf %%\" \\
|
187
|
COMMENT:\" Packet loss multiplied\\n\" \\
|
188
|
COMMENT:\" \" \\
|
189
|
AREA:r2#b36666:\"60-180 ms\" \\
|
190
|
GPRINT:roundtrip:MAX:\" Max\\: %7.2lf ms\" \\
|
191
|
COMMENT:\" \" \\
|
192
|
GPRINT:loss:MAX:\"Max\\: %3.1lf %%\" \\
|
193
|
COMMENT:\" by 10 in graph.\\n\" \\
|
194
|
COMMENT:\" \" \\
|
195
|
AREA:r1#bd9090:\"20-60 ms\" \\
|
196
|
COMMENT:\"\\n\" \\
|
197
|
COMMENT:\" \" \\
|
198
|
AREA:r0#cccccc:\"< 20 ms\" \\
|
199
|
GPRINT:roundtrip:LAST:\" Last\\: %7.2lf ms\" \\
|
200
|
COMMENT:\" \" \\
|
201
|
GPRINT:loss:LAST:\"Last\: %3.1lf %%\" \\
|
202
|
COMMENT:\" \" \\
|
203
|
AREA:loss10#ee0000:\"Packet loss\\n\" \\
|
204
|
COMMENT:\" \" \\
|
205
|
LINE1:roundtrip#ff0000:\"roundtrip average\\n\" \\
|
206
|
COMMENT:\"\t\t\t\t\t\t\t\t\t\t\t\t\t\t`date +\"%b %d %H\:%M\:%S %Y\"`\"";
|
207
|
}
|
208
|
else
|
209
|
{
|
210
|
PRINT "<b>Sorry we do not have data to graph $curgraph for $curif with.</b><br>";
|
211
|
break;
|
212
|
}
|
213
|
|
214
|
/* check modification time to see if we need to generate image */
|
215
|
if (file_exists("$rrddbpath$curif-$interval-$curgraph.png")) {
|
216
|
if((time() - filemtime("$rrddbpath$curif-$interval-$curgraph.png")) >= 280 ) {
|
217
|
system("$graphcmd >/dev/null");
|
218
|
usleep(500);
|
219
|
}
|
220
|
} else {
|
221
|
system("$graphcmd >/dev/null");
|
222
|
usleep(500);
|
223
|
}
|
224
|
|
225
|
PRINT "<B>Analysis for $curif -- $interval $curgraph</B><BR>";
|
226
|
PRINT "<IMG BORDER=1 ALT=\"$ifname $curgraph Graph\"
|
227
|
SRC=\"rrd/$curif-$interval-$curgraph.png\"><BR><BR>";
|
228
|
}
|
229
|
|
230
|
?>
|
231
|
|
232
|
</div>
|
233
|
|
234
|
<meta http-equiv="refresh" content="300;url=<?php print $_SERVER['PHP_SELF']; ?>">
|
235
|
|
236
|
<?php include("fend.inc"); ?>
|
237
|
</body>
|
238
|
</html>
|