source: trunk/Modules/NetworkConfigLinux/Generators/Latency.php

Last change on this file was 929, checked in by chronos, 3 years ago
  • Modified: Removed commended out print_r and echo commands used only for debugging.
File size: 1.2 KB
Line 
1<?php
2
3class ConfigLatency extends NetworkConfigItem
4{
5 function PingHosts(): void
6 {
7 $Timeout = 2000; // ms
8 $RetryLimit = 1;
9 $Hosts = array();
10 $HostInterface = array();
11 $Time = time();
12 $DbResult = $this->Database->query('SELECT `NetworkInterface`.`Id`, '.
13 '`NetworkInterface`.`LocalIP` '.
14 'FROM `NetworkInterface` '.
15 'WHERE (`NetworkInterface`.`Enabled`=1) AND (`NetworkInterface`.`LocalIP` !="")');
16 while ($DbRow = $DbResult->fetch_assoc())
17 {
18 $Hosts[] = $DbRow['LocalIP'];
19 $HostInterface[$DbRow['LocalIP']] = $DbRow['Id'];
20 }
21
22 exec('fping -e -r '.$RetryLimit.' -t '.$Timeout.' -a '.implode(' ', $Hosts).' 2>/dev/null', $Output);
23
24 $Queries = array();
25 foreach ($Output as $Index => $Line)
26 {
27 $IP = substr($Line, 0, strPos($Line, ' '));
28 $Line = substr($Line, strpos($Line, '(') + 1);
29 $Value = substr($Line, 0, strpos($Line, ' '));
30 $Queries[] = $this->Database->GetInsert('NetworkInterfaceLatency', array('Interface' => $HostInterface[$IP],
31 'Value' => $Value, 'Time' => TimeToMysqlDateTime($Time)));
32 }
33 $this->Database->Transaction($Queries);
34 }
35
36 function Run(): void
37 {
38 RepeatFunction(10 * 60, array($this, 'PingHosts'));
39 }
40}
Note: See TracBrowser for help on using the repository browser.