Browse code

Created repository.

DoubleBastionAdmin authored on 29/11/2024 03:10:08
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,60 @@
1
+<?php
2
+/**
3
+ * @copyright 2024 Double Bastion LLC <www.doublebastion.com>
4
+ *
5
+ * @author Double Bastion LLC
6
+ *
7
+ * @license GNU AGPL version 3 or any later version
8
+ *
9
+ * This program is free software; you can redistribute it and/or
10
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
11
+ * License as published by the Free Software Foundation; either
12
+ * version 3 of the License, or any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
18
+ *
19
+ * You should have received a copy of the GNU Affero General Public
20
+ * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
+ *
22
+ */
23
+
24
+session_start();
25
+
26
+if ($_SESSION['loggedtorspanel'] == true) {
27
+
28
+ $stat1 = file('/proc/stat');
29
+
30
+ sleep(1);
31
+
32
+ $stat2 = file('/proc/stat');
33
+ $info1 = explode(" ", preg_replace("!cpu +!", "", $stat1[0]));
34
+ $info2 = explode(" ", preg_replace("!cpu +!", "", $stat2[0]));
35
+
36
+ $dif = array();
37
+ $dif['user'] = $info2[0] - $info1[0];
38
+ $dif['nice'] = $info2[1] - $info1[1];
39
+ $dif['system'] = $info2[2] - $info1[2];
40
+ $dif['idle'] = $info2[3] - $info1[3];
41
+ $dif['iowait'] = $info2[4] - $info1[4];
42
+ $dif['irq'] = $info2[5] - $info1[5];
43
+ $dif['softirq'] = $info2[6] - $info1[6];
44
+ $dif['steal'] = $info2[7] - $info1[7];
45
+
46
+ $totaltime = array_sum($dif);
47
+ $totalidle = $dif['idle'] + $dif['iowait'];
48
+ $totalusage = $totaltime - $totalidle;
49
+
50
+ $cpu = array();
51
+ $cpu['total'] = round(($totalusage * 100) / $totaltime, 1);
52
+ $cpu['system'] = round(($dif['system'] * 100) / $totaltime, 1);
53
+
54
+ echo json_encode($cpu);
55
+
56
+} else {
57
+      header("Location: panel-login.php");
58
+}
59
+
60
+?>