Revision 20413b72
Added by Warren Baker over 14 years ago
etc/inc/rrd.inc | ||
---|---|---|
175 | 175 |
$mem = "-memory.rrd"; |
176 | 176 |
$cellular = "-cellular.rrd"; |
177 | 177 |
$vpnusers = "-vpnusers.rrd"; |
178 |
$captiveportalconcurrent = "-concurrent.rrd"; |
|
179 |
$captiveportalloggedin = "-loggedin.rrd"; |
|
178 | 180 |
|
179 | 181 |
$rrdtool = "/usr/bin/nice -n20 /usr/local/bin/rrdtool"; |
180 | 182 |
$netstat = "/usr/bin/netstat"; |
... | ... | |
186 | 188 |
$top = "/usr/bin/top"; |
187 | 189 |
$spamd_gather = "/usr/local/bin/spamd_gather_stats.php"; |
188 | 190 |
$ifconfig = "/sbin/ifconfig"; |
191 |
$captiveportal_gather = "/usr/local/bin/captiveportal_gather_stats.php"; |
|
189 | 192 |
|
190 | 193 |
$rrdtrafficinterval = 60; |
191 | 194 |
$rrdwirelessinterval = 60; |
... | ... | |
199 | 202 |
$rrdmeminterval = 60; |
200 | 203 |
$rrdcellularinterval = 60; |
201 | 204 |
$rrdvpninterval = 60; |
205 |
$rrdcaptiveportalinterval = 60; |
|
202 | 206 |
|
203 | 207 |
$trafficvalid = $rrdtrafficinterval * 2; |
204 | 208 |
$wirelessvalid = $rrdwirelessinterval * 2; |
... | ... | |
212 | 216 |
$memvalid = $rrdmeminterval * 2; |
213 | 217 |
$cellularvalid = $rrdcellularinterval * 2; |
214 | 218 |
$vpnvalid = $rrdvpninterval * 2; |
219 |
$captiveportalvalid = $rrdcaptiveportalinterval * 2; |
|
215 | 220 |
|
216 | 221 |
/* Asume GigE for now */ |
217 | 222 |
$downstream = 125000000; |
... | ... | |
660 | 665 |
$rrdupdatesh .= "else $rrdtool update $rrddbpath$ifname$cellular N:U:U; fi\n"; |
661 | 666 |
} |
662 | 667 |
|
668 |
/* Captive Portal statistics, set up the rrd file */ |
|
669 |
if(isset($config['captiveportal']['enable'])) { |
|
670 |
$ifname= "captiveportal"; |
|
671 |
if (!file_exists("$rrddbpath$ifname$captiveportal")) { |
|
672 |
$rrdcreate = "$rrdtool create $rrddbpath$ifname$captiveportalconcurrent --step $rrdcaptiveportalinterval "; |
|
673 |
$rrdcreate .= "DS:concurrentusers:GAUGE:$captiveportalvalid:0:10000 "; |
|
674 |
$rrdcreate .= "RRA:AVERAGE:0.5:1:1000 "; |
|
675 |
$rrdcreate .= "RRA:AVERAGE:0.5:5:1000 "; |
|
676 |
$rrdcreate .= "RRA:AVERAGE:0.5:60:1000 "; |
|
677 |
$rrdcreate .= "RRA:AVERAGE:0.5:720:3000 "; |
|
678 |
$rrdcreate .= "RRA:MIN:0.5:1:1000 "; |
|
679 |
$rrdcreate .= "RRA:MIN:0.5:5:1000 "; |
|
680 |
$rrdcreate .= "RRA:MIN:0.5:60:1000 "; |
|
681 |
$rrdcreate .= "RRA:MIN:0.5:720:3000 "; |
|
682 |
$rrdcreate .= "RRA:MAX:0.5:1:1000 "; |
|
683 |
$rrdcreate .= "RRA:MAX:0.5:5:1000 "; |
|
684 |
$rrdcreate .= "RRA:MAX:0.5:60:1000 "; |
|
685 |
$rrdcreate .= "RRA:MAX:0.5:720:3000 "; |
|
686 |
$rrdcreate .= "RRA:LAST:0.5:1:1000 "; |
|
687 |
$rrdcreate .= "RRA:LAST:0.5:5:1000 "; |
|
688 |
$rrdcreate .= "RRA:LAST:0.5:60:1000 "; |
|
689 |
$rrdcreate .= "RRA:LAST:0.5:720:3000 "; |
|
690 |
|
|
691 |
create_new_rrd($rrdcreate); |
|
692 |
} |
|
693 |
|
|
694 |
/* enter UNKNOWN values in the RRD so it knows we rebooted. */ |
|
695 |
if($g['booting']) { |
|
696 |
mwexec("$rrdtool update $rrddbpath$ifname$captiveportalconcurrent N:U"); |
|
697 |
} |
|
698 |
|
|
699 |
/* the Captive Portal stats gathering function. */ |
|
700 |
$rrdupdatesh .= "\n"; |
|
701 |
$rrdupdatesh .= "# polling Captive Portal for number of concurrent users\n"; |
|
702 |
$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$captiveportalconcurrent \\\n"; |
|
703 |
$rrdupdatesh .= "`$php -q $captiveportal_gather concurrent`\n"; |
|
704 |
|
|
705 |
$ifname= "captiveportal"; |
|
706 |
if (!file_exists("$rrddbpath$ifname$captiveportal")) { |
|
707 |
$rrdcreate = "$rrdtool create $rrddbpath$ifname$captiveportalloggedin --step $rrdcaptiveportalinterval "; |
|
708 |
$rrdcreate .= "DS:loggedinusers:GAUGE:$captiveportalvalid:0:10000 "; |
|
709 |
$rrdcreate .= "RRA:AVERAGE:0.5:1:1000 "; |
|
710 |
$rrdcreate .= "RRA:AVERAGE:0.5:5:1000 "; |
|
711 |
$rrdcreate .= "RRA:AVERAGE:0.5:60:1000 "; |
|
712 |
$rrdcreate .= "RRA:AVERAGE:0.5:720:3000 "; |
|
713 |
$rrdcreate .= "RRA:MIN:0.5:1:1000 "; |
|
714 |
$rrdcreate .= "RRA:MIN:0.5:5:1000 "; |
|
715 |
$rrdcreate .= "RRA:MIN:0.5:60:1000 "; |
|
716 |
$rrdcreate .= "RRA:MIN:0.5:720:3000 "; |
|
717 |
$rrdcreate .= "RRA:MAX:0.5:1:1000 "; |
|
718 |
$rrdcreate .= "RRA:MAX:0.5:5:1000 "; |
|
719 |
$rrdcreate .= "RRA:MAX:0.5:60:1000 "; |
|
720 |
$rrdcreate .= "RRA:MAX:0.5:720:3000 "; |
|
721 |
$rrdcreate .= "RRA:LAST:0.5:1:1000 "; |
|
722 |
$rrdcreate .= "RRA:LAST:0.5:5:1000 "; |
|
723 |
$rrdcreate .= "RRA:LAST:0.5:60:1000 "; |
|
724 |
$rrdcreate .= "RRA:LAST:0.5:720:3000 "; |
|
725 |
|
|
726 |
create_new_rrd($rrdcreate); |
|
727 |
} |
|
728 |
|
|
729 |
/* enter UNKNOWN values in the RRD so it knows we rebooted. */ |
|
730 |
if($g['booting']) { |
|
731 |
mwexec("$rrdtool update $rrddbpath$ifname$captiveportalloggedin N:U"); |
|
732 |
} |
|
733 |
|
|
734 |
/* the Captive Portal stats gathering function. */ |
|
735 |
$rrdupdatesh .= "\n"; |
|
736 |
$rrdupdatesh .= "# polling Captive Portal for number of logged in users and concurrent users\n"; |
|
737 |
$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$captiveportalloggedin \\\n"; |
|
738 |
$rrdupdatesh .= "`$php -q $captiveportal_gather loggedin`\n"; |
|
739 |
} |
|
663 | 740 |
|
664 | 741 |
$rrdupdatesh .= "sleep 60\n"; |
665 | 742 |
$rrdupdatesh .= "done\n"; |
usr/local/bin/captiveportal_gather_stats.php | ||
---|---|---|
1 |
#!/usr/local/bin/php -q |
|
2 |
<?php |
|
3 |
/* $Id$ */ |
|
4 |
/* |
|
5 |
captiveportal_gather_stats.php |
|
6 |
Copyright (C) 2011 Warren Baker |
|
7 |
All rights reserved. |
|
8 |
|
|
9 |
Redistribution and use in source and binary forms, with or without |
|
10 |
modification, are permitted provided that the following conditions are met: |
|
11 |
|
|
12 |
1. Redistributions of source code must retain the above copyright notice, |
|
13 |
this list of conditions and the following disclaimer. |
|
14 |
|
|
15 |
2. Redistributions in binary form must reproduce the above copyright |
|
16 |
notice, this list of conditions and the following disclaimer in the |
|
17 |
documentation and/or other materials provided with the distribution. |
|
18 |
|
|
19 |
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
20 |
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
|
21 |
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
22 |
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, |
|
23 |
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
24 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
25 |
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
26 |
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
27 |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
28 |
POSSIBILITY OF SUCH DAMAGE. |
|
29 |
*/ |
|
30 |
|
|
31 |
require_once("functions.inc"); |
|
32 |
require_once("captiveportal.inc"); |
|
33 |
require_once("util.inc"); |
|
34 |
|
|
35 |
/* read in captive portal db */ |
|
36 |
$cpdb = captiveportal_read_db(); |
|
37 |
|
|
38 |
/* determine number of logged in users */ |
|
39 |
$no_users = count($cpdb); |
|
40 |
$concurrent_users = $no_users; |
|
41 |
|
|
42 |
/* set initial user count to zero */ |
|
43 |
$current_user_count = 0; |
|
44 |
|
|
45 |
/* tmp file to use to store old data (per interface)*/ |
|
46 |
$tmpfile = "{$g['tmp_path']}/captiveportal_online_users"; |
|
47 |
|
|
48 |
$type = $argv[1]; |
|
49 |
|
|
50 |
if(empty($type)) |
|
51 |
exit; |
|
52 |
|
|
53 |
/* echo the rrd required syntax */ |
|
54 |
echo "N:"; |
|
55 |
|
|
56 |
if ($type == "loggedin") { |
|
57 |
|
|
58 |
/* Find out the previous user timestamp |
|
59 |
* so we can determine the difference between the current |
|
60 |
* and previous user count. If the file is empty return a 0. |
|
61 |
*/ |
|
62 |
$fd = @fopen($tmpfile, "r"); |
|
63 |
if ($fd) { |
|
64 |
while (!feof($fd)) { |
|
65 |
$line = trim(fgets($fd)); |
|
66 |
if($line) |
|
67 |
$previous_user_timestamp = $line; |
|
68 |
else |
|
69 |
$previous_user_timestamp = 0; |
|
70 |
} |
|
71 |
} else { |
|
72 |
$previous_user_timestamp = 0; |
|
73 |
} |
|
74 |
@fclose($fd); |
|
75 |
|
|
76 |
|
|
77 |
foreach($cpdb as $user) { |
|
78 |
$user_ip = $user[2]; |
|
79 |
// Record the timestamp |
|
80 |
$timestamp = $user[0]; |
|
81 |
if ($timestamp > $previous_user_timestamp) |
|
82 |
$current_user_count = $current_user_count + 1; |
|
83 |
} |
|
84 |
|
|
85 |
// Write out the latest timestamp |
|
86 |
$fd = @fopen($tmpfile, "w"); |
|
87 |
if ($fd) { |
|
88 |
fwrite($fd, $timestamp); |
|
89 |
} |
|
90 |
@fclose($fd); |
|
91 |
|
|
92 |
/* If $timestamp is less than or equal to previous_user_timestamp return 0, |
|
93 |
* as we only want the 'X' number of users logged in since last RRD poll. |
|
94 |
*/ |
|
95 |
if($timestamp <= $previous_user_timestamp) |
|
96 |
$result = 0; |
|
97 |
else { |
|
98 |
$result = $current_user_count; |
|
99 |
} |
|
100 |
} else |
|
101 |
$result = $no_users; |
|
102 |
|
|
103 |
|
|
104 |
echo "$result"; |
|
105 |
|
|
106 |
?> |
usr/local/www/status_rrd_graph.php | ||
---|---|---|
122 | 122 |
continue 2; |
123 | 123 |
} |
124 | 124 |
} |
125 |
case "captiveportal": |
|
126 |
$curoption = "allgraphs"; |
|
127 |
break; |
|
125 | 128 |
default: |
126 | 129 |
$curoption = "wan"; |
127 | 130 |
break; |
... | ... | |
173 | 176 |
"allgraphs-wireless.rrd", |
174 | 177 |
"allgraphs-cellular.rrd", |
175 | 178 |
"allgraphs-vpnusers.rrd", |
179 |
"captiveportal-allgraphs.rrd", |
|
176 | 180 |
"allgraphs-packets.rrd", |
177 | 181 |
"system-allgraphs.rrd", |
178 | 182 |
"system-throughput.rrd", |
... | ... | |
196 | 200 |
if(stristr($database, "-vpnusers")) { |
197 | 201 |
$vpnusers = true; |
198 | 202 |
} |
203 |
if(stristr($database, "captiveportal-") && isset($config['captiveportal']['enable'])) { |
|
204 |
$captiveportal = true; |
|
205 |
} |
|
199 | 206 |
} |
200 | 207 |
/* append the existing array to the header */ |
201 | 208 |
$ui_databases = array_merge($dbheader, $databases); |
... | ... | |
344 | 351 |
if($curcat == "vpnusers") { $tabactive = True; } else { $tabactive = False; } |
345 | 352 |
$tab_array[] = array("VPN", $tabactive, "status_rrd_graph.php?cat=vpnusers"); |
346 | 353 |
} |
354 |
if($captiveportal) { |
|
355 |
if($curcat == "captiveportal") { $tabactive = True; } else { $tabactive = False; } |
|
356 |
$tab_array[] = array("Captive Portal", $tabactive, "status_rrd_graph.php?cat=captiveportal"); |
|
357 |
} |
|
347 | 358 |
if($curcat == "custom") { $tabactive = True; } else { $tabactive = False; } |
348 | 359 |
$tab_array[] = array(gettext("Custom"), $tabactive, "status_rrd_graph.php?cat=custom"); |
349 | 360 |
if($curcat == "settings") { $tabactive = True; } else { $tabactive = False; } |
... | ... | |
387 | 398 |
$replace = array(" :: ", "", $friendly); |
388 | 399 |
|
389 | 400 |
switch($curcat) { |
401 |
case "captiveportal": |
|
402 |
$optionc = str_replace($search, $replace, $optionc[1]); |
|
403 |
echo "<option value=\"$optionc\""; |
|
404 |
$prettyprint = ucwords(str_replace($search, $replace, $optionc)); |
|
405 |
break; |
|
390 | 406 |
case "system": |
391 | 407 |
$optionc = str_replace($search, $replace, $optionc[1]); |
392 | 408 |
echo "<option value=\"$optionc\""; |
usr/local/www/status_rrd_graph_img.php | ||
---|---|---|
209 | 209 |
$colorspamdtime = array('DDDDFF', 'AAAAFF', 'DDDDFF', '000066'); |
210 | 210 |
$colorspamdconn = array('00AA00BB', 'FFFFFFFF', '00660088', 'FFFFFF88', '006600'); |
211 | 211 |
$colorvpnusers = array('990000'); |
212 |
$colorcaptiveportalusers = array('990000'); |
|
212 | 213 |
} |
213 | 214 |
|
214 | 215 |
switch ($curstyle) { |
... | ... | |
910 | 911 |
$graphcmd .= "COMMENT:\"\\n\" "; |
911 | 912 |
$graphcmd .= "COMMENT:\"\t\t\t\t\t\t\t\t\t\t\t\t\t`date +\"%b %d %H\:%M\:%S %Y\"`\" "; |
912 | 913 |
} |
914 |
elseif((strstr($curdatabase, "-loggedin.rrd")) && (file_exists("$rrddbpath$curdatabase"))) { |
|
915 |
/* define graphcmd for online Captive Portal users stats */ |
|
916 |
$graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$curgraph.png "; |
|
917 |
$graphcmd .= "--start $start --end $end "; |
|
918 |
$graphcmd .= "--vertical-label \"Captive Portal Users\" "; |
|
919 |
$graphcmd .= "--color SHADEA#eeeeee --color SHADEB#eeeeee "; |
|
920 |
$graphcmd .= "--title \"`hostname` - {$prettydb} - {$hperiod} - {$havg} average\" "; |
|
921 |
$graphcmd .= "--height 200 --width 620 "; |
|
922 |
$graphcmd .= "DEF:\"$curif-loggedinusers=$rrddbpath$curdatabase:loggedinusers:AVERAGE\" "; |
|
923 |
$graphcmd .= "LINE2:\"$curif-loggedinusers#{$colorcaptiveportalusers[0]}:$curif-loggedinusers\" "; |
|
924 |
$graphcmd .= "COMMENT:\"\\n\" "; |
|
925 |
$graphcmd .= "COMMENT:\"\t\t\t current\t\t average\t maximum\\n\" "; |
|
926 |
$graphcmd .= "COMMENT:\"Users Online\t\" "; |
|
927 |
$graphcmd .= "GPRINT:\"$curif-loggedinusers:LAST:%7.2lf \" "; |
|
928 |
$graphcmd .= "GPRINT:\"$curif-loggedinusers:AVERAGE:%7.2lf \" "; |
|
929 |
$graphcmd .= "GPRINT:\"$curif-loggedinusers:MAX:%7.2lf \" "; |
|
930 |
$graphcmd .= "COMMENT:\"\\n\" "; |
|
931 |
$graphcmd .= "COMMENT:\"\t\t\t\t\t\t\t\t\t\t\t\t\t`date +\"%b %d %H\:%M\:%S %Y\"`\" "; |
|
932 |
} |
|
933 |
elseif((strstr($curdatabase, "-concurrent.rrd")) && (file_exists("$rrddbpath$curdatabase"))) { |
|
934 |
/* define graphcmd for online Captive Portal users stats */ |
|
935 |
$graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$curgraph.png "; |
|
936 |
$graphcmd .= "--start $start --end $end "; |
|
937 |
$graphcmd .= "--vertical-label \"Captive Portal Users\" "; |
|
938 |
$graphcmd .= "--color SHADEA#eeeeee --color SHADEB#eeeeee "; |
|
939 |
$graphcmd .= "--title \"`hostname` - {$prettydb} - {$hperiod} - {$havg} average\" "; |
|
940 |
$graphcmd .= "--height 200 --width 620 "; |
|
941 |
$graphcmd .= "DEF:\"$curif-concurrentusers=$rrddbpath$curdatabase:concurrentusers:AVERAGE\" "; |
|
942 |
$graphcmd .= "LINE2:\"$curif-concurrentusers#{$colorcaptiveportalusers[0]}:$curif-concurrentusers\" "; |
|
943 |
$graphcmd .= "COMMENT:\"\\n\" "; |
|
944 |
$graphcmd .= "COMMENT:\"\t\t\t current\t\t average\t maximum\\n\" "; |
|
945 |
$graphcmd .= "COMMENT:\"Users Online\t\" "; |
|
946 |
$graphcmd .= "GPRINT:\"$curif-concurrentusers:LAST:%7.2lf \" "; |
|
947 |
$graphcmd .= "GPRINT:\"$curif-concurrentusers:AVERAGE:%7.2lf \" "; |
|
948 |
$graphcmd .= "GPRINT:\"$curif-concurrentusers:MAX:%7.2lf \" "; |
|
949 |
$graphcmd .= "COMMENT:\"\\n\" "; |
|
950 |
$graphcmd .= "COMMENT:\"\t\t\t\t\t\t\t\t\t\t\t\t\t`date +\"%b %d %H\:%M\:%S %Y\"`\" "; |
|
951 |
} |
|
913 | 952 |
else { |
914 | 953 |
$data = false; |
915 | 954 |
log_error(sprintf(gettext("Sorry we do not have data to graph for %s"),$curdatabase)); |
usr/local/www/status_rrd_graph_settings.php | ||
---|---|---|
54 | 54 |
'traffic' => gettext("Traffic"), |
55 | 55 |
'packets' => gettext("Packets"), |
56 | 56 |
'quality' => gettext("Quality"), |
57 |
'queues' => gettext("Queues")); |
|
57 |
'queues' => gettext("Queues"), |
|
58 |
'captiveportal' => gettext("Captive Portal")); |
|
58 | 59 |
$styles = array('inverse' => gettext("Inverse"), |
59 | 60 |
'absolute' => gettext("Absolute")); |
60 | 61 |
$periods = array("absolute" => gettext("Absolute Timespans"), |
... | ... | |
101 | 102 |
if(stristr($database, "-vpnusers")) { |
102 | 103 |
$vpnusers = true; |
103 | 104 |
} |
105 |
if(stristr($database, "captiveportal-") && isset($config['captiveportal']['enable'])) { |
|
106 |
$captiveportal = true; |
|
107 |
} |
|
104 | 108 |
} |
105 | 109 |
|
106 | 110 |
$pgtitle = array(gettext("Status"),gettext("RRD Graphs")); |
... | ... | |
143 | 147 |
if($curcat == "vpnusers") { $tabactive = True; } else { $tabactive = False; } |
144 | 148 |
$tab_array[] = array(gettext("VPN"), $tabactive, "status_rrd_graph.php?cat=vpnusers"); |
145 | 149 |
} |
150 |
if($captiveportal) { |
|
151 |
if($curcat == "captiveportal") { $tabactive = True; } else { $tabactive = False; } |
|
152 |
$tab_array[] = array(gettext("Captive Portal"), $tabactive, "status_rrd_graph.php?cat=captiveportal"); |
|
153 |
} |
|
146 | 154 |
if($curcat == "custom") { $tabactive = True; } else { $tabactive = False; } |
147 | 155 |
$tab_array[] = array(gettext("Custom"), $tabactive, "status_rrd_graph.php?cat=custom"); |
148 | 156 |
if($curcat == "settings") { $tabactive = True; } else { $tabactive = False; } |
Also available in: Unified diff
Added Captive Portal RRD graphs, there are two graphs one for the number of logged in users since last rrd poll, and concurrent number of users logged in.