added setServerAddr and isServerAddr to IPAddr.class.php to identify users connecting...
[PHP-P10.git] / Bots / Stats.class.php
index cacdc2bc8476dae4f2ed6533b3dfa0abc8dbef37..df3db8c1eaa902b3f465946c34f580b7c484aa10 100644 (file)
@@ -1,12 +1,12 @@
 <?php
 /******************************* PHP-P10 v2 *****************************
- * Copyright (C) 2011  Philipp Kreil (pk910)                            *
+ * Copyright (C) 2011-2012  Philipp Kreil (pk910)                       *
  *                                                                      *
  * This program is free software: you can redistribute it and/or modify *
  * it under the terms of the GNU General Public License as published by *
  * the Free Software Foundation, either version 3 of the License, or    *
  * (at your option) any later version.                                  *
- *                                                                      * 
+ *                                                                      *
  * This program is distributed in the hope that it will be useful,      *
  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
@@ -16,7 +16,7 @@
  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  *                                                                      *
  ************************************************************************
- * 
+ *
  *  Bots/Stats.class.php
  *
  * RRD Stats module...
@@ -26,7 +26,7 @@
 class {$_NAME} extends Bot {
        private $uplink;
        private $timer;
-       
+
        public function load($uplink, $old = false) {
                $this->uplink = $uplink;
                if(!file_exists("db/network.rrd")) {
@@ -45,13 +45,13 @@ class {$_NAME} extends Bot {
                                "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();
-                       }
+                               );
+                               $ret = rrd_create($fname, $opts, count($opts));
+                               if(!$ret) {
+                                       $err = rrd_error();
+                                       echo "Create error: $err\n";
+                                       die();
+                               }
                }
                if(!file_exists("db/network-away.rrd")) {
                        $fname = "db/network-away.rrd";
@@ -67,13 +67,13 @@ class {$_NAME} extends Bot {
                                "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();
-                       }
+                               );
+                               $ret = rrd_create($fname, $opts, count($opts));
+                               if(!$ret) {
+                                       $err = rrd_error();
+                                       echo "Create error: $err\n";
+                                       die();
+                               }
                }
                if(!file_exists("db/network-peruser.rrd")) {
                        $fname = "db/network-peruser.rrd";
@@ -89,21 +89,44 @@ class {$_NAME} extends Bot {
                                "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();
-                       }
+                               );
+                               $ret = rrd_create($fname, $opts, count($opts));
+                               if(!$ret) {
+                                       $err = rrd_error();
+                                       echo "Create error: $err\n";
+                                       die();
+                               }
+               }
+               if(!file_exists("db/network-connections.rrd")) {
+                       $fname = "db/network-connections.rrd";
+                       $opts = array(
+                               "--step", "300", "--start", "0",
+                               "DS:localhost:GAUGE:600:0:U",
+                               "DS:ipv4:GAUGE:600:0:U",
+                               "DS:ipv6: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());
        }
-       
+
        public function unload($rehash = false) {
                kill_timer($this->timer);
        }
-       
+
        function create_stats() {
                $this->timer = timer(5*60,array(&$this,"create_stats"),array());
                $stats = array(
@@ -112,7 +135,10 @@ class {$_NAME} extends Bot {
                        "away" => 0,
                        "here" => 0,
                        "chansperuser" => 0,
-                       "usersperchan" => 0
+                       "usersperchan" => 0,
+                       "local" => 0,
+                       "ipv4" => 0,
+                       "ipv6" => 0
                );
                foreach(P10_User::getAllUsers() as $user) {
                        $stats['total']++;
@@ -120,6 +146,9 @@ class {$_NAME} extends Bot {
                        if($user->isAway()) $stats['away']++;
                        else $stats['here']++;
                        if($user->getModes()->hasMode('o')) $stats['opers']++;
+                       if($user->getIP()->isLocalAddress(true)) $stats['local']++;
+                       if($user->getIP()->isIPv6()) $stats['ipv6']++;
+                       else $stats['ipv4']++;
                }
                $stats['chansperuser'] = $stats['chansperuser'] / $stats['total'];
                $channels = P10_Channel::getChannelCount();
@@ -131,6 +160,7 @@ class {$_NAME} extends Bot {
                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']);
+               rrd_update("db/network-connections.rrd", time().":".$stats['local'].":".$stats['ipv4'].":".$stats['ipv6']);
                foreach(P10_Server::getServers() as $snum => $server) {
                        $count = $server->getUserCount();
                        $fname="db/".$server->getName().".rrd";
@@ -146,13 +176,13 @@ class {$_NAME} extends Bot {
                                        "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));
+                                       );
+                                       $ret = rrd_create($fname, $opts, count($opts));
                        }
                        rrd_update($fname, time().":".$count);
                }
        }
-       
+
 }
 
 ?>
\ No newline at end of file