Changeset 39
- Timestamp:
- Mar 21, 2009, 9:38:58 AM (16 years ago)
- Location:
- trunk/measure_scripts
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/measure_scripts/monitor_sample.php
r37 r39 2 2 3 3 // Toto je ukázkový skript pro aktualizaci dat. Zkopírujte si jej jako monitor.php a upravte podle potřeby. 4 // Skript spouštět přes crona každou minutu 4 5 5 6 include('../global.php'); … … 7 8 include('wow.php'); 8 9 9 //GetNetworkState(); 10 while(1) 11 { 12 $NetworkState = GetNetworkState(); 13 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=3&Value='.MemoryUsage()); 14 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=4&Value='.CpuUsage()); 15 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=5&Value='.WoWPlayersOnline()); 16 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=6&Value='.WoWEmulatorRestartCount()); 17 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=7&Value='.DiskFree()); 18 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=8&Value='.WoWAccountCount()); 19 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=10&Value='.WoWGMOnline()); 20 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=11&Value='.round($NetworkState['eth1']['DownAverage'])); 21 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=12&Value='.round($NetworkState['eth1']['UpAverage'])); 22 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=13&Value='.WoWCharacterCount()); 23 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=14&Value='.WoWGuildCount()); 24 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=15&Value='.WoWEmulatorAvailability()); 25 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=16&Value='.Ping()); 26 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=17&Value='.TeamSpeak()); 27 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=18&Value='.WoWTranslatedQuestsCount()); 28 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=19&Value='.DiskUtilization()); 10 $LastNetworkState = unserializa(file_get_contents('/tmp/LastNetworkState')); 11 $LastCpuUsage = unserializa(file_get_contents('/tmp/LastCpuUsage')); 29 12 30 sleep(58); // 60(measure period) - 2(disk utilization) 31 } 13 $NetworkState = GetNetworkState(); 14 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=3&Value='.MemoryUsage()); 15 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=4&Value='.CpuUsage()); 16 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=5&Value='.WoWPlayersOnline()); 17 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=6&Value='.WoWEmulatorRestartCount()); 18 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=7&Value='.DiskFree()); 19 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=8&Value='.WoWAccountCount()); 20 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=10&Value='.WoWGMOnline()); 21 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=11&Value='.round($NetworkState['eth1']['DownAverage'])); 22 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=12&Value='.round($NetworkState['eth1']['UpAverage'])); 23 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=13&Value='.WoWCharacterCount()); 24 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=14&Value='.WoWGuildCount()); 25 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=15&Value='.WoWEmulatorAvailability()); 26 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=16&Value='.Ping()); 27 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=17&Value='.TeamSpeak()); 28 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=18&Value='.WoWTranslatedQuestsCount()); 29 file_get_contents($Config['AddNewValueUrl'].'?MeasureId=19&Value='.DiskUtilization()); 30 31 file_put_contents('/tmp/LastNetworkState', serialize($LastNetworkState)); 32 file_put_contents('/tmp/LastCpuUsage', serialize($LastCpuUsage)); 33 32 34 ?> -
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.