Fix latency feature thanks to Marc
This commit is contained in:
parent
c286c56d87
commit
540bef3e12
@ -428,7 +428,13 @@ class LookingGlass
|
|||||||
*/
|
*/
|
||||||
private static function getLatencyFromSs(string $ip): array
|
private static function getLatencyFromSs(string $ip): array
|
||||||
{
|
{
|
||||||
$lines = shell_exec('/usr/sbin/ss -Hti state established');
|
$ssPath = exec('which ss 2>/dev/null');
|
||||||
|
if (empty($ssPath)) {
|
||||||
|
// RHEL based systems
|
||||||
|
$ssPath = '/usr/sbin/ss';
|
||||||
|
}
|
||||||
|
$lines = shell_exec("$ssPath -Hnti state established");
|
||||||
|
|
||||||
$ss = [];
|
$ss = [];
|
||||||
$i = 0;
|
$i = 0;
|
||||||
$j = 0;
|
$j = 0;
|
||||||
@ -445,26 +451,22 @@ class LookingGlass
|
|||||||
$output = [];
|
$output = [];
|
||||||
foreach ($ss as $socket) {
|
foreach ($ss as $socket) {
|
||||||
$socket = preg_replace('!\s+!', ' ', $socket);
|
$socket = preg_replace('!\s+!', ' ', $socket);
|
||||||
$explodedsocket = explode(' ', $socket);
|
preg_match('/^\d+\s+\d+\s+(?:\[::ffff:)?(?<localIp>[a-f0-9.:]+)]?:(?<localPort>\d+)\s+(?:\[::ffff:)?(?<remoteIp>[a-f0-9.:]+)]?:(?<remotePort>\d+)/', $line, $matches);
|
||||||
preg_match('/\d+\.\d+\.\d+\.\d+/', $explodedsocket[2], $temp);
|
if ($matches['remoteIp'] !== $ip) {
|
||||||
if (!isset($temp[0])) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$sock['local'] = $temp[0];
|
$sock['local'] = $matches['localIp'];
|
||||||
preg_match('/\d+\.\d+\.\d+\.\d+/', $explodedsocket[3], $temp);
|
$sock['remote'] = $matches['remoteIp'];
|
||||||
$sock['remote'] = $temp[0];
|
|
||||||
preg_match('/segs_out:(\d+)/', $socket, $temp);
|
preg_match('/segs_out:(\d+)/', $socket, $temp);
|
||||||
$sock['segs_out'] = $temp[1];
|
$sock['segs_out'] = $temp[1];
|
||||||
preg_match('/segs_in:(\d+)/', $socket, $temp);
|
preg_match('/segs_in:(\d+)/', $socket, $temp);
|
||||||
$sock['segs_in'] = $temp[1];
|
$sock['segs_in'] = $temp[1];
|
||||||
preg_match_all('/rtt:(\d+\.\d+)\/(\d+\.\d+)/', $socket, $temp);
|
preg_match('/rtt:(\d+\.\d+)\/(\d+\.\d+)/', $socket, $temp);
|
||||||
$sock['latency'] = $temp[1][0];
|
$sock['latency'] = $temp[1];
|
||||||
$sock['jitter'] = $temp[2][0];
|
$sock['jitter'] = $temp[2];
|
||||||
preg_match_all('/retrans:\d+\/(\d+)/', $socket, $temp);
|
preg_match('/retrans:\d+\/(\d+)/', $socket, $temp);
|
||||||
$sock['retransmissions'] = (isset($temp[1][0]) ? $temp[1][0] : 0);
|
$sock['retransmissions'] = ($temp[1] ?? 0);
|
||||||
if ($sock['remote'] == $ip) {
|
$output[] = $sock;
|
||||||
$output[] = $sock;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user