Added bandwidth usage measurement to Window Status

This commit is contained in:
Shoghi Cervantes 2013-06-11 11:00:02 +02:00
parent 6563169527
commit c8e157156e
2 changed files with 8 additions and 1 deletions

View File

@ -94,9 +94,11 @@ class PocketMinecraftServer{
}
public function titleTick(){
$time = microtime(true);
if(ENABLE_ANSI === true){
echo "\x1b]0;PocketMine-MP ".MAJOR_VERSION." | Online ". count($this->clients)."/".$this->maxClients." | RAM ".round((memory_get_usage() / 1024) / 1024, 2)."MB | TPS ".$this->getTPS()."\x07";
echo "\x1b]0;PocketMine-MP ".MAJOR_VERSION." | Online ". count($this->clients)."/".$this->maxClients." | RAM ".round((memory_get_usage() / 1024) / 1024, 2)."MB | U ".round(($this->interface->bandwidth[0] / max(1, $time - $this->interface->bandwidth[2])) / 1024, 2)." D ".round(($this->interface->bandwidth[1] / max(1, $time - $this->interface->bandwidth[2])) / 1024, 2)." kB/s | TPS ".$this->getTPS()."\x07";
}
$this->interface->bandwidth = array(0, 0, $time);
}
public function loadEvents(){

View File

@ -27,6 +27,7 @@ the Free Software Foundation, either version 3 of the License, or
class MinecraftInterface{
public $client;
public $bandwidth;
private $socket;
private $data;
private $chunked;
@ -38,6 +39,7 @@ class MinecraftInterface{
console("[ERROR] Couldn't bind to $serverip:".$port, true, true, 0);
exit(1);
}
$this->bandwidth = array(0, 0, microtime(true));
$this->client = (bool) $client;
$this->start = microtime(true);
$this->chunked = array();
@ -69,6 +71,7 @@ class MinecraftInterface{
if($len === false){
return $pk;
}
$this->bandwidth[0] += $len;
$this->parsePacket($buf, $source, $port);
return ($pk !== false ? $pk : $this->popPacket());
}
@ -244,6 +247,7 @@ class MinecraftInterface{
$write = strlen($packet->raw);
}else{
$write = $this->socket->write($packet->raw, $dest, $port);
$this->bandwidth[1] += $write;
}
}else{
if($force === false and $this->isChunked($CID)){
@ -254,6 +258,7 @@ class MinecraftInterface{
$write = strlen($data);
}else{
$write = $this->socket->write($data, $dest, $port);
$this->bandwidth[1] += $write;
}
}
return $write;