X-Git-Url: http://git.pk910.de/?p=PHP-P10.git;a=blobdiff_plain;f=Bots%2FStats.class.php;h=ec4e2fb349c456d2beabc34e68796823a538749f;hp=66704850b09ea66aa3b88092638f43fbeb51dc25;hb=7f51193ddac01b0540000c756c50167ff015e02a;hpb=5c6c3365d28144516f0ade183189b256d8de03bc diff --git a/Bots/Stats.class.php b/Bots/Stats.class.php index 6670485..ec4e2fb 100644 --- a/Bots/Stats.class.php +++ b/Bots/Stats.class.php @@ -1,12 +1,10 @@ . * * * ************************************************************************ - * + * * Bots/Stats.class.php * * RRD Stats module... @@ -29,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")) { @@ -48,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"; @@ -70,40 +67,71 @@ 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"; + $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()); } - + public function unload($rehash = false) { kill_timer($this->timer); } - + function create_stats() { $this->timer = timer(5*60,array(&$this,"create_stats"),array()); $stats = array( "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']); - foreach(uplink::$uplink->servers as $snum => $server) { + 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"; if(!file_exists($fname)) { @@ -118,13 +146,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