forked from joshplant/Codiad-System-Information
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoller.php
More file actions
30 lines (22 loc) · 712 Bytes
/
poller.php
File metadata and controls
30 lines (22 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
function measureDisk($disk){
return round(100 - ((disk_free_space($disk) / 1024 / 1024 / 1024) / (disk_total_space($disk) / 1024 / 1024 / 1024) * 100), 2);
}
if(isset($_POST['systemInformation']) AND !empty($_POST['systemInformation'])){
$systemInformation = $_POST['systemInformation'];
switch($systemInformation){
case "cpu":
$cpuUsage = exec('top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk \'{print 100 - $1}\'');
echo $cpuUsage;
break;
case "memory":
$memoryUsage = round(shell_exec("free | grep Mem | awk '{print $3/$2 * 100.0}'"), 2);
echo $memoryUsage;
break;
case "disk":
$diskUsage = measureDisk("/");
echo $diskUsage;
break;
}
}
?>