2 /********************************* PHP-P10 ******************************
3 * P10 uplink class by pk910 (c)2011 pk910 *
4 ************************************************************************
7 * PHP-P10 is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
17 * You should have received a copy of the GNU General Public License *
18 * along with PHP-P10; if not, write to the Free Software Foundation, *
19 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 ************************************************************************
23 * Bots/Stats.class.php
29 class {$_NAME} extends Bot {
33 public function load($uplink, $old = false) {
34 $this->uplink = $uplink;
35 if(!file_exists("db/network.rrd")) {
36 $fname = "db/network.rrd";
38 "--step", "300", "--start", "0",
39 "DS:users:GAUGE:600:0:U",
40 "DS:channels:GAUGE:600:0:U",
41 "DS:opers:GAUGE:600:0:U",
42 "DS:servers:GAUGE:600:0:U",
43 "RRA:AVERAGE:0.5:1:600",
44 "RRA:AVERAGE:0.5:6:700",
45 "RRA:AVERAGE:0.5:24:775",
46 "RRA:AVERAGE:0.5:288:797",
52 $ret = rrd_create($fname, $opts, count($opts));
55 echo "Create error: $err\n";
59 if(!file_exists("db/network-away.rrd")) {
60 $fname = "db/network-away.rrd";
62 "--step", "300", "--start", "0",
63 "DS:useraway:GAUGE:600:0:U",
64 "DS:userhere:GAUGE:600:0:U",
65 "RRA:AVERAGE:0.5:1:600",
66 "RRA:AVERAGE:0.5:6:700",
67 "RRA:AVERAGE:0.5:24:775",
68 "RRA:AVERAGE:0.5:288:797",
74 $ret = rrd_create($fname, $opts, count($opts));
77 echo "Create error: $err\n";
81 if(!file_exists("db/network-peruser.rrd")) {
82 $fname = "db/network-peruser.rrd";
84 "--step", "300", "--start", "0",
85 "DS:userperchan:GAUGE:600:0:U",
86 "DS:chanperuser:GAUGE:600:0:U",
87 "RRA:AVERAGE:0.5:1:600",
88 "RRA:AVERAGE:0.5:6:700",
89 "RRA:AVERAGE:0.5:24:775",
90 "RRA:AVERAGE:0.5:288:797",
96 $ret = rrd_create($fname, $opts, count($opts));
99 echo "Create error: $err\n";
103 $this->timer = timer(5,array(&$this,"create_stats"),array());
106 public function unload($rehash = false) {
107 kill_timer($this->timer);
110 function create_stats() {
111 $this->timer = timer(5*60,array(&$this,"create_stats"),array());
120 foreach(P10_User::getAllUsers() as $user) {
122 $stats['chansperuser'] += $user->getChannelCount();
123 if($user->isAway()) $stats['away']++;
124 else $stats['here']++;
125 if($user->getModes()->hasMode('o')) $stats['opers']++;
127 $stats['chansperuser'] = $stats['chansperuser'] / $stats['total'];
128 $channels = P10_Channel::getChannelCount();
129 foreach(P10_Channel::getChannels() as $channel) {
130 $stats['usersperchan'] += $channel->getUserCount();
132 $stats['usersperchan'] = $stats['usersperchan'] / $channels;
133 $servers = P10_Server::getServerCount();
134 rrd_update("db/network.rrd", time().":".$stats['total'].":".$channels.":".$stats['opers'].":".$servers);
135 rrd_update("db/network-away.rrd", time().":".$stats['away'].":".$stats['here']);
136 rrd_update("db/network-peruser.rrd", time().":".$stats['usersperchan'].":".$stats['chansperuser']);
137 foreach(P10_Server::getServers() as $snum => $server) {
138 $count = $server->getUserCount();
139 $fname="db/".$server->getName().".rrd";
140 if(!file_exists($fname)) {
142 "--step", "300", "--start", "0",
143 "DS:users:GAUGE:600:0:U",
144 "RRA:AVERAGE:0.5:1:600",
145 "RRA:AVERAGE:0.5:6:700",
146 "RRA:AVERAGE:0.5:24:775",
147 "RRA:AVERAGE:0.5:288:797",
150 "RRA:MAX:0.5:24:775",
151 "RRA:MAX:0.5:288:797"
153 $ret = rrd_create($fname, $opts, count($opts));
155 rrd_update($fname, time().":".$count);