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 $this->timer = timer(5,array(&$this,"create_stats"),array());
84 public function unload($rehash = false) {
85 kill_timer($this->timer);
88 function create_stats() {
89 $this->timer = timer(5*60,array(&$this,"create_stats"),array());
96 foreach(P10_User::getAllUsers() as $num => $user) {
98 if($user->isAway()) $stats['away']++;
99 else $stats['here']++;
100 if($user->getModes()->hasMode('o')) $stats['opers']++;
102 $channels = P10_Channel::getChannelCount();
103 $servers = P10_Server::getServerCount();
104 rrd_update("db/network.rrd", time().":".$stats['total'].":".$channels.":".$stats['opers'].":".$servers);
105 rrd_update("db/network-away.rrd", time().":".$stats['away'].":".$stats['here']);
106 foreach(uplink::$uplink->servers as $snum => $server) {
107 $count = $server->getUserCount();
108 $fname="db/".$server->getName().".rrd";
109 if(!file_exists($fname)) {
111 "--step", "300", "--start", "0",
112 "DS:users:GAUGE:600:0:U",
113 "RRA:AVERAGE:0.5:1:600",
114 "RRA:AVERAGE:0.5:6:700",
115 "RRA:AVERAGE:0.5:24:775",
116 "RRA:AVERAGE:0.5:288:797",
119 "RRA:MAX:0.5:24:775",
120 "RRA:MAX:0.5:288:797"
122 $ret = rrd_create($fname, $opts, count($opts));
124 rrd_update($fname, time().":".$count);