-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-data.php
More file actions
149 lines (133 loc) · 5.66 KB
/
get-data.php
File metadata and controls
149 lines (133 loc) · 5.66 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
require('conf.php');
require('info.php');
$server_check_version = '1.0.4';
$start_time = microtime(TRUE);
$operating_system = PHP_OS_FAMILY;
if ($operating_system === 'Windows') {
// Win CPU
$wmi = new COM('WinMgmts:\\\\.');
$cpus = $wmi->InstancesOf('Win32_Processor');
$cpuload = 0;
$cpu_count = 0;
foreach ($cpus as $key => $cpu) {
$cpuload += $cpu->LoadPercentage;
$cpu_count++;
}
// WIN MEM
$res = $wmi->ExecQuery('SELECT FreePhysicalMemory,FreeVirtualMemory,TotalSwapSpaceSize,TotalVirtualMemorySize,TotalVisibleMemorySize FROM Win32_OperatingSystem');
$mem = $res->ItemIndex(0);
$memtotal = round($mem->TotalVisibleMemorySize / 1000000,2);
$memavailable = round($mem->FreePhysicalMemory / 1000000,2);
$memused = round($memtotal-$memavailable,2);
// WIN CONNECTIONS
$connections = shell_exec('netstat -nt | findstr :80 | findstr ESTABLISHED | find /C /V ""');
$totalconnections = shell_exec('netstat -nt | findstr :80 | find /C /V ""');
} else {
// Linux CPU
$load = sys_getloadavg();
$cpuload = $load[0];
$cpu_count = shell_exec('nproc');
// Linux MEM
$free = shell_exec('free');
$free = (string)trim($free);
$free_arr = explode("\n", $free);
$mem = explode(" ", $free_arr[1]);
$mem = array_filter($mem, function($value) { return ($value !== null && $value !== false && $value !== ''); }); // removes nulls from array
$mem = array_merge($mem); // puts arrays back to [0],[1],[2] after
$memtotal = round($mem[1] / 1000000,2);
$memused = round($mem[2] / 1000000,2);
$memfree = round($mem[3] / 1000000,2);
$memshared = round($mem[4] / 1000000,2);
$memcached = round($mem[5] / 1000000,2);
$memavailable = round($mem[6] / 1000000,2);
// Linux Connections
$connections = `netstat -ntu | grep :80 | grep ESTABLISHED | grep -v LISTEN | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -rn | grep -v 127.0.0.1 | wc -l`;
$totalconnections = `netstat -ntu | grep :80 | grep -v LISTEN | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -rn | grep -v 127.0.0.1 | wc -l`;
}
//$memusage = round(($memavailable/$memtotal)*100);
$memusage = round(($memused/$memtotal)*100);
$phpload = round(memory_get_usage() / 1000000,2);
$diskfree = round(disk_free_space(".") / 1000000000);
$disktotal = round(disk_total_space(".") / 1000000000);
$diskused = round($disktotal - $diskfree);
$diskusage = round($diskused/$disktotal*100);
if ($memusage > 85 || $cpuload > 85 || $diskusage > 85) {
$trafficlight = 'red';
} elseif ($memusage > 50 || $cpuload > 50 || $diskusage > 50) {
$trafficlight = 'orange';
} else {
$trafficlight = '#2F2';
}
$end_time = microtime(TRUE);
$time_taken = $end_time - $start_time;
$total_time = round($time_taken,4);
// use servercheck.php?json=1
if (isset($_GET['json'])) {
echo '{"ram":'.$memusage.',"cpu":'.$cpuload.',"disk":'.$diskusage.',"connections":'.$totalconnections.'}';
exit;
}
?>
<div class="mb-3">
<h1 class="display-5 d-flex align-items-center"> <i class="ph-fill ph-hard-drives me-3"></i> Alžběta</h1>
<p class="description">Naše nadupané VPS. Zde běží naše hlavní služby jako webovky, Discord boti a další.</p>
</div>
<div class="server-stats row row-cols-1">
<div class="col-12 mb-4">
<div class="row m-0 w-100 gap-1">
<div class="col-2 col-lg-1 progress-section">
<h6 class="mb-0"><i class="ph-fill ph-cpu"></i> CPU</h6>
</div>
<div class="col progress-section bar">
<div class="progress h-100">
<div class="progress-bar" role="progressbar" style="width: <?php echo $cpuload; ?>%"
aria-valuenow="<?php echo $cpuload; ?>" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
<div class="col-2 col-lg-1 progress-section">
<h6 class="mb-0"><?php echo $cpuload; ?>%</h6>
</div>
</div>
<div class="row m-0 w-100 gap-1 mt-2">
<div class="col-2 col-lg-1 progress-section">
<h6 class="mb-0"><i class="ph-fill ph-stack"></i> RAM</h6>
</div>
<div class="col progress-section bar">
<div class="progress h-100">
<div class="progress-bar" role="progressbar" style="width: <?php echo $memusage; ?>%"
aria-valuenow="<?php echo $memusage; ?>" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
<div class="col-2 col-lg-1 progress-section">
<h6 class="mb-0"><?php echo $memused; ?> GB</h6>
</div>
</div>
<div class="row m-0 w-100 gap-1 mt-2">
<div class="col-2 col-lg-1 progress-section">
<h6 class="mb-0"><i class="ph-fill ph-stack"></i> RAM</h6>
</div>
<div class="col progress-section bar">
<div class="progress h-100">
<div class="progress-bar" role="progressbar" style="width: <?php echo $diskusage; ?>%"
aria-valuenow="<?php echo $diskusage; ?>" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
<div class="col-2 col-lg-1 progress-section">
<h6 class="mb-0"><?php echo $diskused; ?>/<?php echo $disktotal; ?> GB</h6>
</div>
</div>
</div>
<div class="row m-0 w-100 gap-1 mt-2">
<div class="col-md progress-section justify-content-between">
<h5 class="mb-0 d-flex align-items-center"><i class="ph-fill ph-linux-logo fs-3 me-2"></i> Operační systém:</h5>
<p class="mb-0">Ubuntu</p>
</div>
<div class="col-md progress-section justify-content-between">
<h5 class="mb-0 d-flex align-items-center"><i class="ph-fill ph-clock fs-3 me-2"></i> Doba od zapnutí:</h5>
<p class="mb-0"><?php echo $uptime_days; ?>d <?php echo $uptime_hours; ?>h <?php echo $uptime_minutes; ?>m </p>
</div>
<div class="col-md progress-section justify-content-between">
<h5 class="mb-0 d-flex align-items-center"><i class="ph-fill ph-code fs-3 me-2"></i> PHP verze:</h5>
<p class="mb-0"><?php echo phpversion(); ?></p>
</div>
</div>