Ignore:
Timestamp:
Apr 6, 2020, 11:17:40 PM (5 years ago)
Author:
chronos
Message:
  • Modified: Improved code format.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/TimeMeasure/Measurement/System.php

    r660 r873  
    1111    set_error_handler('ErrorHandler');
    1212    //error_reporting(0);
    13     if($Fp1 = fsockopen($Ip, $Port, $ERROR_NO, $ERROR_STR, (float)$Timeout))
     13    if ($Fp1 = fsockopen($Ip, $Port, $ERROR_NO, $ERROR_STR, (float)$Timeout))
    1414    {
    1515      fclose($Fp1);
    16       return(TRUE);
     16      return (TRUE);
    1717    } else
    1818    {
    1919      //echo($ERROR_NO.','.$ERROR_STR);
    20       return(FALSE);
     20      return (FALSE);
    2121    }
    2222    restore_error_handler();
     
    3030    // c - ping count
    3131    $Parts = explode(' ', $Row[0]);
    32     if(count($Parts) > 6)
     32    if (count($Parts) > 6)
    3333    {
    3434      $Time = $Parts[7];
    3535      $TimeParts = explode('=', $Time);
    36       return($TimeParts[1]);
    37     } else return(0);
     36      return ($TimeParts[1]);
     37    } else return (0);
    3838  }
    3939
     
    4343    exec('free -b', $Output);
    4444    $Row = $Output[2];
    45     while(strpos($Row, '  ') !== false) $Row = str_replace('  ', ' ', $Row);
     45    while (strpos($Row, '  ') !== false) $Row = str_replace('  ', ' ', $Row);
    4646    $RowParts = explode(' ', $Row);
    4747    $Row = $Output[3];
    48     while(strpos($Row, '  ') !== false) $Row = str_replace('  ', ' ', $Row);
     48    while (strpos($Row, '  ') !== false) $Row = str_replace('  ', ' ', $Row);
    4949    $RowParts2 = explode(' ', $Row);
    50     return($RowParts[2] + $RowParts2[2]);
     50    return ($RowParts[2] + $RowParts2[2]);
    5151  }
    5252
     
    8181    }
    8282    file_put_contents($CpuStateFileName, serialize($CpuUsage));
    83     return(100 - round($CpuUsagePercent['Idle'], 2));
     83    return (100 - round($CpuUsagePercent['Idle'], 2));
    8484  }
    8585
     
    9393    array_shift($Output); // Skip header
    9494    array_shift($Output); // Skip header
    95     foreach($Output as $Item)
     95    foreach ($Output as $Item)
    9696    {
    97       while(strpos($Item, '  ') !== false) $Item = str_replace('  ', ' ', $Item);  // Rrmove multiple spaces
     97      while (strpos($Item, '  ') !== false) $Item = str_replace('  ', ' ', $Item);  // Rrmove multiple spaces
    9898      $Item = explode(':', $Item);
    9999      $Interface = trim($Item[0]);
    100100      $Item = explode(' ', trim($Item[1]));
    101101      $NetworkState[$Interface] = array('Down' => $Item[0], 'Up' => $Item[8]);
    102       if(array_key_exists($Interface, $LastNetworkState))
     102      if (array_key_exists($Interface, $LastNetworkState))
    103103      {
    104104        $Period = time() - $LastNetworkState['Time'];
     
    110110        $NetworkState[$Interface]['UpAverage'] = 0;
    111111      }
    112       if($NetworkState[$Interface]['DownAverage'] < 0) $NetworkState[$Interface]['DownAverage'] = 0;
    113       if($NetworkState[$Interface]['UpAverage'] < 0) $NetworkState[$Interface]['UpAverage'] = 0;
     112      if ($NetworkState[$Interface]['DownAverage'] < 0) $NetworkState[$Interface]['DownAverage'] = 0;
     113      if ($NetworkState[$Interface]['UpAverage'] < 0) $NetworkState[$Interface]['UpAverage'] = 0;
    114114    }
    115115    file_put_contents($NetworkStateFile, serialize($NetworkState));
    116     return($NetworkState);
     116    return ($NetworkState);
    117117  }
    118118
     
    120120  {
    121121    $NetworkState = $this->GetNetworkState();
    122     return($NetworkState['Interface']['DownAverage']);
     122    return ($NetworkState['Interface']['DownAverage']);
    123123  }
    124124
     
    126126  {
    127127    $NetworkState = $this->GetNetworkState();
    128     return($NetworkState['Interface']['UpAverage']);
     128    return ($NetworkState['Interface']['UpAverage']);
    129129  }
    130130
     
    134134    $Output = array();
    135135    exec('cat /proc/net/nf_conntrack|grep "dst='.$HostIP.' "|grep "dport='.$Port.' "|grep "ASSURED"', $Output);
    136     return(count($Output));
     136    return (count($Output));
    137137  }
    138138
     
    142142    exec('iostat -d '.$Device.' -x -m 2 2', $Output);   // 2 second measure delay
    143143    $Row = $Output[6];
    144     while(strpos($Row, '  ') !== false) $Row = str_replace('  ', ' ', $Row);
     144    while (strpos($Row, '  ') !== false) $Row = str_replace('  ', ' ', $Row);
    145145    $Parts = explode(' ', $Row);
    146146    $Value = str_replace(',', '.', $Parts[11]);
    147     return($Value);
     147    return ($Value);
    148148  }
    149149
    150150  function DiskFree($Path)
    151151  {
    152     return(disk_free_space($Path));
     152    return (disk_free_space($Path));
    153153  }
    154154
     
    157157    $Output = array();
    158158    exec('/usr/bin/sensors', $Output);
    159     foreach($Output as $Line)
     159    foreach ($Output as $Line)
    160160    {
    161       if(substr($Line, 0, strlen($Sensor)) == $Sensor)
     161      if (substr($Line, 0, strlen($Sensor)) == $Sensor)
    162162      {
    163163        $Line = substr($Line, strpos($Line, '+') + 1);
    164164        $Line = substr($Line, 0, strpos($Line, '°'));
    165         return($Line);
     165        return ($Line);
    166166      }
    167167    }
    168     return(0);
     168    return (0);
    169169  }
    170170
     
    175175    fclose($File);
    176176    $UptimeParts = explode(' ', $Uptime);
    177     return($UptimeParts[0]);
     177    return ($UptimeParts[0]);
    178178  }
    179179}
Note: See TracChangeset for help on using the changeset viewer.