added per user / per channel stats
authorpk910 <philipp@zoelle1.de>
Thu, 28 Jul 2011 02:26:29 +0000 (04:26 +0200)
committerpk910 <philipp@zoelle1.de>
Thu, 28 Jul 2011 02:26:29 +0000 (04:26 +0200)
Bots/Stats.class.php
Uplink/P10_Channel.class.php
Uplink/P10_User.class.php

index 7c83105e82209e4f776314a034c136caa74d84d0..33e8e5fc619acdc51100d5bc247eeac8ea2067a5 100644 (file)
@@ -78,6 +78,28 @@ class {$_NAME} extends Bot {
                                die();
                        }
                }
+               if(!file_exists("db/network-peruser.rrd")) {
+                       $fname = "db/network-peruser.rrd";
+                       $opts = array(
+                               "--step", "300", "--start", "0",
+                               "DS:userperchan:GAUGE:600:0:U",
+                               "DS:chanperuser:GAUGE:600:0:U",
+                               "RRA:AVERAGE:0.5:1:600",
+                               "RRA:AVERAGE:0.5:6:700",
+                               "RRA:AVERAGE:0.5:24:775",
+                               "RRA:AVERAGE:0.5:288:797",
+                               "RRA:MAX:0.5:1:600",
+                               "RRA:MAX:0.5:6:700",
+                               "RRA:MAX:0.5:24:775",
+                               "RRA:MAX:0.5:288:797"
+                       );
+                       $ret = rrd_create($fname, $opts, count($opts));
+                       if(!$ret) {
+                               $err = rrd_error();
+                               echo "Create error: $err\n";
+                               die();
+                       }
+               }
                $this->timer = timer(5,array(&$this,"create_stats"),array());
        }
        
@@ -91,18 +113,27 @@ class {$_NAME} extends Bot {
                        "opers" => 0,
                        "total" => 0,
                        "away" => 0,
-                       "here" => 0
+                       "here" => 0,
+                       "chansperuser" => 0,
+                       "usersperchan" => 0
                );
-               foreach(P10_User::getAllUsers() as $num => $user) {
+               foreach(P10_User::getAllUsers() as $user) {
                        $stats['total']++;
+                       $stats['chansperuser'] += $user->getChannelCount();
                        if($user->isAway()) $stats['away']++;
                        else $stats['here']++;
                        if($user->getModes()->hasMode('o')) $stats['opers']++;
                }
+               $stats['chansperuser'] = $stats['chansperuser'] / $stats['total'];
                $channels = P10_Channel::getChannelCount();
+               foreach(P10_Channel::getChannels() as $channel) {
+                       $stats['usersperchan'] += $channel->getUserCount();
+               }
+               $stats['usersperchan'] = $stats['usersperchan'] / $channels;
                $servers = P10_Server::getServerCount();
                rrd_update("db/network.rrd", time().":".$stats['total'].":".$channels.":".$stats['opers'].":".$servers);
                rrd_update("db/network-away.rrd", time().":".$stats['away'].":".$stats['here']);
+               rrd_update("db/network-peruser.rrd", time().":".$stats['usersperchan'].":".$stats['chansperuser']);
                foreach(P10_Server::getServers() as $snum => $server) {
                        $count = $server->getUserCount();
                        $fname="db/".$server->getName().".rrd";
index e373d55c75b3988acaa90f530b37a3d3ac02c825..a0d9fb8aa3550b8bce1d37ce448c33acf4317758 100644 (file)
@@ -153,6 +153,10 @@ class P10_Channel {
                }
        }
        
+       public function getUserCount() {
+               return count($this->users);
+       }
+       
        public function getUsers() {
                return $this->users;
        }
index 8d4e5a35ffa2381679cecb64d0a8f8f8e87f4060..bcc17c2d7ede8169899e411854152c41486d2005 100644 (file)
@@ -165,6 +165,10 @@ class P10_User {
                return $this->channels;
        }
        
+       public function getChannelCount() {
+               return count($this->channels);
+       }
+       
        public function isOnChannel($channel) {
                return array_key_exists(strtolower($channel->getName()),$this->channels);
        }