2 /******************************* PHP-P10 v2 *****************************
3 * Copyright (C) 2011-2012 Philipp Kreil (pk910) *
5 * This program is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 3 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 ************************************************************************
20 * Bots/Stats.class.php
26 class {$_NAME} extends Bot {
30 public function load($uplink, $old = false) {
31 $this->uplink = $uplink;
32 if(!file_exists("db/network.rrd")) {
33 $fname = "db/network.rrd";
35 "--step", "300", "--start", "0",
36 "DS:users:GAUGE:600:0:U",
37 "DS:channels:GAUGE:600:0:U",
38 "DS:opers:GAUGE:600:0:U",
39 "DS:servers:GAUGE:600:0:U",
40 "RRA:AVERAGE:0.5:1:600",
41 "RRA:AVERAGE:0.5:6:700",
42 "RRA:AVERAGE:0.5:24:775",
43 "RRA:AVERAGE:0.5:288:797",
49 $ret = rrd_create($fname, $opts, count($opts));
52 echo "Create error: $err\n";
56 if(!file_exists("db/network-away.rrd")) {
57 $fname = "db/network-away.rrd";
59 "--step", "300", "--start", "0",
60 "DS:useraway:GAUGE:600:0:U",
61 "DS:userhere:GAUGE:600:0:U",
62 "RRA:AVERAGE:0.5:1:600",
63 "RRA:AVERAGE:0.5:6:700",
64 "RRA:AVERAGE:0.5:24:775",
65 "RRA:AVERAGE:0.5:288:797",
71 $ret = rrd_create($fname, $opts, count($opts));
74 echo "Create error: $err\n";
78 if(!file_exists("db/network-peruser.rrd")) {
79 $fname = "db/network-peruser.rrd";
81 "--step", "300", "--start", "0",
82 "DS:userperchan:GAUGE:600:0:U",
83 "DS:chanperuser:GAUGE:600:0:U",
84 "RRA:AVERAGE:0.5:1:600",
85 "RRA:AVERAGE:0.5:6:700",
86 "RRA:AVERAGE:0.5:24:775",
87 "RRA:AVERAGE:0.5:288:797",
93 $ret = rrd_create($fname, $opts, count($opts));
96 echo "Create error: $err\n";
100 if(!file_exists("db/network-connections.rrd")) {
101 $fname = "db/network-connections.rrd";
103 "--step", "300", "--start", "0",
104 "DS:localhost:GAUGE:600:0:U",
105 "DS:ipv4:GAUGE:600:0:U",
106 "DS:ipv6:GAUGE:600:0:U",
107 "RRA:AVERAGE:0.5:1:600",
108 "RRA:AVERAGE:0.5:6:700",
109 "RRA:AVERAGE:0.5:24:775",
110 "RRA:AVERAGE:0.5:288:797",
113 "RRA:MAX:0.5:24:775",
114 "RRA:MAX:0.5:288:797"
116 $ret = rrd_create($fname, $opts, count($opts));
119 echo "Create error: $err\n";
123 $this->timer = timer(5,array(&$this,"create_stats"),array());
126 public function unload($rehash = false) {
127 kill_timer($this->timer);
130 function create_stats() {
131 $this->timer = timer(5*60,array(&$this,"create_stats"),array());
143 foreach(P10_User::getAllUsers() as $user) {
145 $stats['chansperuser'] += $user->getChannelCount();
146 if($user->isAway()) $stats['away']++;
147 else $stats['here']++;
148 if($user->getModes()->hasMode('o')) $stats['opers']++;
149 if($user->getIP()->isLocalAddress(true)) $stats['local']++;
150 if($user->getIP()->isIPv6()) $stats['ipv6']++;
151 else $stats['ipv4']++;
153 $stats['chansperuser'] = $stats['chansperuser'] / $stats['total'];
154 $channels = P10_Channel::getChannelCount();
155 foreach(P10_Channel::getChannels() as $channel) {
156 $stats['usersperchan'] += $channel->getUserCount();
158 $stats['usersperchan'] = $stats['usersperchan'] / $channels;
159 $servers = P10_Server::getServerCount();
160 rrd_update("db/network.rrd", time().":".$stats['total'].":".$channels.":".$stats['opers'].":".$servers);
161 rrd_update("db/network-away.rrd", time().":".$stats['away'].":".$stats['here']);
162 rrd_update("db/network-peruser.rrd", time().":".$stats['usersperchan'].":".$stats['chansperuser']);
163 rrd_update("db/network-connections.rrd", time().":".$stats['local'].":".$stats['ipv4'].":".$stats['ipv6']);
164 foreach(P10_Server::getServers() as $snum => $server) {
165 $count = $server->getUserCount();
166 $fname="db/".$server->getName().".rrd";
167 if(!file_exists($fname)) {
169 "--step", "300", "--start", "0",
170 "DS:users:GAUGE:600:0:U",
171 "RRA:AVERAGE:0.5:1:600",
172 "RRA:AVERAGE:0.5:6:700",
173 "RRA:AVERAGE:0.5:24:775",
174 "RRA:AVERAGE:0.5:288:797",
177 "RRA:MAX:0.5:24:775",
178 "RRA:MAX:0.5:288:797"
180 $ret = rrd_create($fname, $opts, count($opts));
182 rrd_update($fname, time().":".$count);