| Conditions | 4 |
| Paths | 8 |
| Total Lines | 27 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | public function collect(): array |
||
| 8 | { |
||
| 9 | $totalMem = (int) shell_exec("grep MemTotal /proc/meminfo | awk '{print $2}'"); |
||
| 10 | $freeMem = (int) shell_exec("grep MemAvailable /proc/meminfo | awk '{print $2}'"); |
||
| 11 | |||
| 12 | $usedMemPercent = ($totalMem > 0) |
||
| 13 | ? round((($totalMem - $freeMem) / $totalMem) * 100, 1) |
||
| 14 | : 0; |
||
| 15 | |||
| 16 | $loadAvg = (float) sys_getloadavg()[1]; |
||
| 17 | $cpuCores = (int) shell_exec("nproc"); |
||
| 18 | |||
| 19 | $cpuUsagePercent = ($cpuCores > 0) |
||
| 20 | ? round(($loadAvg / $cpuCores) * 100, 1) |
||
| 21 | : 0; |
||
| 22 | |||
| 23 | $diskTotal = disk_total_space('/'); |
||
| 24 | $diskFree = disk_free_space('/'); |
||
| 25 | |||
| 26 | $diskUsedPercent = ($diskTotal > 0) |
||
| 27 | ? round((($diskTotal - $diskFree) / $diskTotal) * 100, 1) |
||
| 28 | : 0; |
||
| 29 | |||
| 30 | return [ |
||
| 31 | 'memory.usage' => $usedMemPercent, |
||
| 32 | 'cpu.usage' => $cpuUsagePercent, |
||
| 33 | 'disk.usage' => $diskUsedPercent |
||
| 34 | ]; |
||
| 36 | } |