Fix latency feature thanks to Marc

This commit is contained in:
dqos 2023-11-01 18:57:19 +01:00
parent c286c56d87
commit 540bef3e12
No known key found for this signature in database

View file

@ -428,7 +428,13 @@ class LookingGlass
*/
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 = [];
$i = 0;
$j = 0;
@ -445,26 +451,22 @@ class LookingGlass
$output = [];
foreach ($ss as $socket) {
$socket = preg_replace('!\s+!', ' ', $socket);
$explodedsocket = explode(' ', $socket);
preg_match('/\d+\.\d+\.\d+\.\d+/', $explodedsocket[2], $temp);
if (!isset($temp[0])) {
preg_match('/^\d+\s+\d+\s+(?:\[::ffff:)?(?<localIp>[a-f0-9.:]+)]?:(?<localPort>\d+)\s+(?:\[::ffff:)?(?<remoteIp>[a-f0-9.:]+)]?:(?<remotePort>\d+)/', $line, $matches);
if ($matches['remoteIp'] !== $ip) {
continue;
}
$sock['local'] = $temp[0];
preg_match('/\d+\.\d+\.\d+\.\d+/', $explodedsocket[3], $temp);
$sock['remote'] = $temp[0];
$sock['local'] = $matches['localIp'];
$sock['remote'] = $matches['remoteIp'];
preg_match('/segs_out:(\d+)/', $socket, $temp);
$sock['segs_out'] = $temp[1];
preg_match('/segs_in:(\d+)/', $socket, $temp);
$sock['segs_in'] = $temp[1];
preg_match_all('/rtt:(\d+\.\d+)\/(\d+\.\d+)/', $socket, $temp);
$sock['latency'] = $temp[1][0];
$sock['jitter'] = $temp[2][0];
preg_match_all('/retrans:\d+\/(\d+)/', $socket, $temp);
$sock['retransmissions'] = (isset($temp[1][0]) ? $temp[1][0] : 0);
if ($sock['remote'] == $ip) {
$output[] = $sock;
}
preg_match('/rtt:(\d+\.\d+)\/(\d+\.\d+)/', $socket, $temp);
$sock['latency'] = $temp[1];
$sock['jitter'] = $temp[2];
preg_match('/retrans:\d+\/(\d+)/', $socket, $temp);
$sock['retransmissions'] = ($temp[1] ?? 0);
$output[] = $sock;
}
return $output;
}