Changeset 39 for trunk/measure_scripts/system.php
- Timestamp:
- Mar 21, 2009, 9:38:58 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/measure_scripts/system.php
r37 r39 23 23 } 24 24 25 function Ping( )25 function Ping($Host = 'nix.cz') 26 26 { 27 exec('ping nix.cz-c 1 -W 1|grep time=', $Row);27 exec('ping '.$Host.' -c 1 -W 1|grep time=', $Row); 28 28 // W - timeout in seconds 29 29 // c - ping count … … 47 47 while(strpos($Row, ' ') !== false) $Row = str_replace(' ', ' ', $Row); 48 48 $RowParts2 = explode(' ', $Row); 49 return($RowParts[2] + $RowParts2[2]); 49 return($RowParts[2] + $RowParts2[2]); 50 50 } 51 51 52 52 function CpuUsage() 53 { 54 global $cpuIDLEprev, $cpuSYSTprev, $cpuUSERprev; 53 { 54 global $LastCpuUsage; 55 //$cpuIDLEprev, $cpuSYSTprev, $cpuUSERprev; 56 55 57 // get processor usage seconds for pct stats ### 56 58 $File = fopen('/proc/stat', 'r'); … … 58 60 fclose($File); 59 61 $Parts = explode(' ', $Row); 60 $ cpuUSER= $Parts[2] + $Parts[3];61 $ cpuSYST= $Parts[4];62 $ cpuIDLE= $Parts[5];63 $ cpuUSERdiff = ($cpuUSER - $cpuUSERprev);64 $ cpuSYSTdiff = ($cpuSYST - $cpuSYSTprev);65 $ cpuIDLEdiff = ($cpuIDLE - $cpuIDLEprev);66 $ cpuIDLEdiffTOTAL = (($cpuUSERdiff + $cpuSYSTdiff) + $cpuIDLEdiff);67 if ($ cpuIDLEdiffTOTAL> 0)62 $CpuUsage['User'] = $Parts[2] + $Parts[3]; 63 $CpuUsage['System'] = $Parts[4]; 64 $CpuUsage['Idle'] = $Parts[5]; 65 $CpuUsageDiff['User'] = ($CpuUsage['User'] - $LastCpuUsage['User']); 66 $CpuUsageDiff['System'] = ($CpuUsage['System'] - $LastCpuUsage['System']); 67 $CpuUsageDiff['Idle'] = ($CpuUsage['Idle'] - $LastCpuUsage['Idle']); 68 $CpuUsageDiffTotal = (($CpuUsageDiff['User'] + $CpuUsageDiff['System']) + $CpuUsageDiff['Idle']); 69 if ($CpuUsageDiffTotal > 0) 68 70 { 69 $ cpuUSERcent = ($cpuUSERdiff / $cpuIDLEdiffTOTAL) * 100;70 $ cpuSYSTcent = ($cpuSYSTdiff / $cpuIDLEdiffTOTAL) * 100;71 $ cpuIDLEcent = ($cpuIDLEdiff / $cpuIDLEdiffTOTAL* 100);71 $CpuUsagePercent['User'] = ($CpuUsageDiff['User'] / $CpuUsageDiffTotal) * 100; 72 $CpuUsagePercent['System'] = ($CpuUsageDiff['System'] / $CpuUsageDiffTotal) * 100; 73 $CpuUsagePercent['Idle'] = ($CpuUsageDiff['Idle'] / $CpuUsageDiffTotal * 100); 72 74 } else 73 75 { 74 $ cpuUSERcent =0;75 $ cpuSYSTcent= 0;76 $ cpuIDLEcent= 0;76 $CpuUsagePercent['User'] = 0; 77 $CpuUsagePercent['System'] = 0; 78 $CpuUsagePercent['Idle'] = 0; 77 79 } 78 $cpuUSERprev = $cpuUSER; 79 $cpuSYSTprev = $cpuSYST; 80 $cpuIDLEprev = $cpuIDLE; 81 return(100 - round($cpuIDLEcent * 100) / 100); 80 $LastCpuUsage = $CpuUsage; 81 return(100 - round($CpuUsagePercent['Idle'], 2)); 82 82 } 83 83 84 84 function GetNetworkState() 85 { 85 { 86 86 global $LastNetworkState; 87 87 … … 124 124 } 125 125 126 function DiskUtilization( )126 function DiskUtilization($Device) 127 127 { 128 128 $Output = array(); 129 exec('iostat -d sda-x -m 2 2', $Output); // 2 second measure delay129 exec('iostat -d '.$Device.' -x -m 2 2', $Output); // 2 second measure delay 130 130 $Row = $Output[6]; 131 131 while(strpos($Row, ' ') !== false) $Row = str_replace(' ', ' ', $Row); … … 135 135 } 136 136 137 function DiskFree( )137 function DiskFree($Path) 138 138 { 139 return(disk_free_space( '/'));139 return(disk_free_space($Path)); 140 140 } 141 141
Note:
See TracChangeset
for help on using the changeset viewer.