1
This commit is contained in:
parent
eec520f969
commit
a9c4408722
@ -3,25 +3,32 @@ namespace Laysense\Monitor;
|
|||||||
|
|
||||||
use WebSocket\Client;
|
use WebSocket\Client;
|
||||||
|
|
||||||
class Detection
|
class Detect
|
||||||
{
|
{
|
||||||
var $dest='ws://172.83.153.167:2345';
|
var $dest='ws://172.83.153.167:2345';
|
||||||
var $nodeinfo;
|
var $nodeinfo;
|
||||||
public function getNode()
|
var $ping;
|
||||||
|
var $delay;
|
||||||
|
public function node()
|
||||||
{
|
{
|
||||||
$nodeinfo = $this->callWebSocet('{"msg":"getnodelist"}');
|
$nodeinfo = $this->callWebSocet('{"msg":"getnodelist"}');
|
||||||
$this->nodeinfo=$nodeinfo;
|
$this->nodeinfo=$nodeinfo;
|
||||||
}
|
}
|
||||||
|
public function getNode(){
|
||||||
|
if(!isset($this->nodeinfo)){
|
||||||
|
$this->node();
|
||||||
|
}
|
||||||
|
return $this->nodeinfo;
|
||||||
|
}
|
||||||
public function ping($host,$count)
|
public function ping($host,$count)
|
||||||
{
|
{
|
||||||
|
if(!isset($this->nodeinfo)){
|
||||||
|
$this->node();
|
||||||
|
}
|
||||||
$ping = $this->callWebSocet('{"msg":"ping","target:'.$host.'","type":"ICMP","count":'.$count.'}');
|
$ping = $this->callWebSocet('{"msg":"ping","target:'.$host.'","type":"ICMP","count":'.$count.'}');
|
||||||
foreach($this->nodeinfo as $node){
|
foreach($this->nodeinfo as $node){
|
||||||
$ping[$node->nodeid]['nodeinfo']=$node;
|
$ping[$node->nodeid]['nodeinfo']=$node;
|
||||||
}
|
}
|
||||||
$this->ping=$ping;
|
|
||||||
}
|
|
||||||
public function getDelay()
|
|
||||||
{
|
|
||||||
$alldelay = 0;
|
$alldelay = 0;
|
||||||
foreach($this->ping as $id=>$node){
|
foreach($this->ping as $id=>$node){
|
||||||
if((!isset($node['nodeinfo'])) || (!isset($node['delay'])) || $node['delay']<=10){
|
if((!isset($node['nodeinfo'])) || (!isset($node['delay'])) || $node['delay']<=10){
|
||||||
@ -30,8 +37,15 @@ class Detection
|
|||||||
$alldelay += $node['delay'];
|
$alldelay += $node['delay'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$alldelay = $alldelay/count($this->ping);
|
$this->ping=$ping;
|
||||||
return $alldelay;
|
$this->delay=$alldelay/count($this->ping);
|
||||||
|
}
|
||||||
|
public function getDelay()
|
||||||
|
{
|
||||||
|
if(!isset($this->delay)){
|
||||||
|
$this->ping();
|
||||||
|
}
|
||||||
|
return $this->delay;
|
||||||
}
|
}
|
||||||
private function callWebSocet(){
|
private function callWebSocet(){
|
||||||
$client = new Client($this->dest);
|
$client = new Client($this->dest);
|
||||||
|
Loading…
Reference in New Issue
Block a user