mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
Network: Each interface now keeps its own statistics
this allows more detailed analysis.
This commit is contained in:
parent
f933ce31dd
commit
7720a0534e
@ -68,4 +68,23 @@ interface AdvancedNetworkInterface extends NetworkInterface{
|
||||
* @param string $regex
|
||||
*/
|
||||
public function addRawPacketFilter(string $regex) : void;
|
||||
|
||||
/**
|
||||
* Returns the number of bytes sent on this network interface since the last statistics reset.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getBytesSent() : int;
|
||||
|
||||
/**
|
||||
* Returns the number of bytes received on this network interface since the last statistics reset.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getBytesReceived() : int;
|
||||
|
||||
/**
|
||||
* Resets the upload/download statistics to zero.
|
||||
*/
|
||||
public function resetTrafficStats() : void;
|
||||
}
|
||||
|
@ -49,9 +49,6 @@ class Network{
|
||||
/** @var int[] */
|
||||
private $bannedIps = [];
|
||||
|
||||
private $upload = 0;
|
||||
private $download = 0;
|
||||
|
||||
/** @var string */
|
||||
private $name;
|
||||
|
||||
@ -67,22 +64,26 @@ class Network{
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function addStatistics(float $upload, float $download) : void{
|
||||
$this->upload += $upload;
|
||||
$this->download += $download;
|
||||
}
|
||||
|
||||
public function getUpload() : float{
|
||||
return $this->upload;
|
||||
$result = 0;
|
||||
foreach($this->advancedInterfaces as $interface){
|
||||
$result += $interface->getBytesSent();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getDownload() : float{
|
||||
return $this->download;
|
||||
$result = 0;
|
||||
foreach($this->advancedInterfaces as $interface){
|
||||
$result += $interface->getBytesReceived();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function resetStatistics() : void{
|
||||
$this->upload = 0;
|
||||
$this->download = 0;
|
||||
foreach($this->advancedInterfaces as $interface){
|
||||
$interface->resetTrafficStats();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,6 +77,11 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{
|
||||
/** @var SleeperNotifier */
|
||||
private $sleeper;
|
||||
|
||||
/** @var int */
|
||||
private $sendBytes = 0;
|
||||
/** @var int */
|
||||
private $receiveBytes = 0;
|
||||
|
||||
public function __construct(Server $server){
|
||||
$this->server = $server;
|
||||
|
||||
@ -221,7 +226,8 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{
|
||||
public function handleOption(string $option, string $value) : void{
|
||||
if($option === "bandwidth"){
|
||||
$v = unserialize($value);
|
||||
$this->network->addStatistics($v["up"], $v["down"]);
|
||||
$this->sendBytes = $v["up"];
|
||||
$this->receiveBytes = $v["down"];
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,4 +249,16 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{
|
||||
$this->sessions[$sessionId]->updatePing($pingMS);
|
||||
}
|
||||
}
|
||||
|
||||
public function getBytesSent() : int{
|
||||
return $this->sendBytes;
|
||||
}
|
||||
|
||||
public function getBytesReceived() : int{
|
||||
return $this->receiveBytes;
|
||||
}
|
||||
|
||||
public function resetTrafficStats() : void{
|
||||
$this->sendBytes = $this->receiveBytes = 0;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user