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 $this->timer = timer(5,array(&$this,"create_stats"),array());
103 public function unload($rehash = false) {
104 kill_timer($this->timer);
107 function create_stats() {
108 $this->timer = timer(5*60,array(&$this,"create_stats"),array());
117 foreach(P10_User::getAllUsers() as $user) {
119 $stats['chansperuser'] += $user->getChannelCount();
120 if($user->isAway()) $stats['away']++;
121 else $stats['here']++;
122 if($user->getModes()->hasMode('o')) $stats['opers']++;
124 $stats['chansperuser'] = $stats['chansperuser'] / $stats['total'];
125 $channels = P10_Channel::getChannelCount();
126 foreach(P10_Channel::getChannels() as $channel) {
127 $stats['usersperchan'] += $channel->getUserCount();
129 $stats['usersperchan'] = $stats['usersperchan'] / $channels;
130 $servers = P10_Server::getServerCount();
131 rrd_update("db/network.rrd", time().":".$stats['total'].":".$channels.":".$stats['opers'].":".$servers);
132 rrd_update("db/network-away.rrd", time().":".$stats['away'].":".$stats['here']);
133 rrd_update("db/network-peruser.rrd", time().":".$stats['usersperchan'].":".$stats['chansperuser']);
134 foreach(P10_Server::getServers() as $snum => $server) {
135 $count = $server->getUserCount();
136 $fname="db/".$server->getName().".rrd";
137 if(!file_exists($fname)) {
139 "--step", "300", "--start", "0",
140 "DS:users:GAUGE:600:0:U",
141 "RRA:AVERAGE:0.5:1:600",
142 "RRA:AVERAGE:0.5:6:700",
143 "RRA:AVERAGE:0.5:24:775",
144 "RRA:AVERAGE:0.5:288:797",
147 "RRA:MAX:0.5:24:775",
148 "RRA:MAX:0.5:288:797"
150 $ret = rrd_create($fname, $opts, count($opts));
152 rrd_update($fname, time().":".$count);