-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckserverstatus.php
176 lines (153 loc) · 7.75 KB
/
checkserverstatus.php
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!DOCTYPE html>
<html lang="en">
<head>
<title>Server status</title>
<meta content="text/html" charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<!--<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
--><style>
pre {
overflow-x: auto;
max-width: 60vw;
}
pre code {
word-wrap: normal;
white-space: pre;
}
</style>
</head>
<html>
<div class="container">
<?php
//Get ram usage
$total_mem_ram = preg_split('/ +/', @exec('grep MemTotal /proc/meminfo'));
$total_mem_ram = round($total_mem_ram[1] / 1000000, 2);
$free_mem_ram = preg_split('/ +/', @exec('grep MemFree /proc/meminfo'));
$free_mem_ram = round($free_mem_ram[1] / 1000000, 2);
$cache_mem_ram = preg_split('/ +/', @exec('grep ^Cached /proc/meminfo'));
$cache_mem_ram = round($cache_mem_ram[1] / 1000000, 2);
$free_mem_with_cache = $free_mem_ram + $cache_mem_ram;
$percent_ram_with_cache = round($free_mem_ram / $total_mem_ram, 2);
$percent_ram_with_cache = $percent_ram_with_cache * 100;
$percent_value_ram = $free_mem_ram / $total_mem_ram;
$percent_value_ram = $percent_value_ram * 100;
/*The disks array list all mountpoint you wan to check freespace
* Display name and path to the moutpoint have to be provide
*/
$disk_free = round(disk_free_space(".") / 1000000000);
$disk_total = round(disk_total_space(".") / 1000000000);
$disk_used = round($disk_total - $disk_free);
$disk_usage = round($disk_used / $disk_total * 100);
$percent_disk_free = 100 - round($disk_free * 1.0 / $disk_total * 100, 2);
$phpload = round(memory_get_usage() / 1000000, 2);
$start_time = microtime(TRUE);
$end_time = microtime(TRUE);
$time_taken = $end_time - $start_time;
$total_time = round($time_taken, 4);
//CPU USAGE
$load = sys_getloadavg();
$load = $load[0];
?>
<body>
<div class="card mb-2">
<h4 class="card-header text-center">
Server information
</h4>
<div>
<h6>Ram Memory (<?php echo $free_mem_ram . "GB" . "/" ?> <?php echo $total_mem_ram . "GB" ?>)</h6>
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="<?php echo $free_mem_ram ?>" aria-valuemin="0" aria-valuemax="<?php echo $total_mem_ram ?>" style="width:<?php echo $percent_value_ram . "%" ?>">
<?php echo round($percent_value_ram, 2) . "%" ?> (<?php echo $total_mem_ram . "GB in total" ?>)
</div>
</div>
</div>
<div>
<h6>Ram Memory with cache (<?php echo $free_mem_with_cache . "GB" . "/" ?> <?php echo $total_mem_ram . "GB" ?>)</h6>
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="<?php echo $free_mem_with_cache ?>" aria-valuemin="0" aria-valuemax="<?php echo $total_mem_ram ?>" style="width:<?php echo $percent_ram_with_cache . "%" ?>">
<?php echo round($percent_ram_with_cache, 2) . "%" ?> (<?php echo $total_mem_ram . "GB in total" ?>)
</div>
</div>
</div>
<div>
<h6>Hard Drive Space (<?php echo $disk_used . "GB" . "/" ?> <?php echo $disk_total . "GB" ?>)</h6>
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="<?php echo $disk_used ?>" aria-valuemin="0" aria-valuemax="<?php echo $disk_total ?>" style="width:<?php echo $percent_disk_free . "%" ?>">
<?php echo round($percent_disk_free, 2) . "%" ?> (<?php echo $disk_used . "GB in total" ?>)
</div>
</div>
</div>
</br>
<div>
<table class='table table-striped table-sm'>
<tr>
<th>Others</th>
</tr>
<tbody>
<tr>
<td><span>Server Address:</span> <span><?php echo $_SERVER['SERVER_ADDR']; ?></span></td>
</tr>
<tr>
<td><span>PHP Version:</span> <span><?php echo phpversion(); ?></span></td>
</tr>
<tr>
<td><span>PHP Load:</span> <span><?php echo $phpload . "GB"; ?></span></td>
</tr>
<tr>
<td><span>Load Time:</span> <span><?php echo $total_time . "Sec"; ?></span></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="card mb-2">
<h4 class="card-header text-center">
Service Status
</h4>
<div>
<table class='table table-striped table-sm'>
<tr>
<th>Service</th>
<th>Port</th>
<th>Status</th>
</tr>
<tbody>
<?php
$services = array();
$services[] = array("port" => "80", "service" => "Web server", "ip" => "");
$services[] = array("port" => "21", "service" => "FTP", "ip" => "");
$services[] = array("port" => "3306", "service" => "MYSQL", "ip" => "");
$services[] = array("port" => "22", "service" => "Open SSH", "ip" => "");
$services[] = array("port" => "58846", "service" => "Deluge", "ip" => "");
$services[] = array("port" => "8112", "service" => "Deluge Web", "ip" => "");
$services[] = array("port" => "80", "service" => "Internet Connection", "ip" => "google.com");
$services[] = array("port" => "8083", "service" => "Vesta panel", "ip" => "");
foreach ($services as $service) : ?>
<tr>
<td><?php echo $service['service']; ?></td>
<td><?php echo $service['port']; ?></td>
<td><?php
if ($service['ip'] == "") {
$service['ip'] = "localhost";
}
$fp = @fsockopen($service['ip'], $service['port'], $errno, $errstr, $timeout);
if (!$fp) {
$status_offline = "Offline";
echo $status_offline;
} else {
$status_online = "Online";
echo $status_online;
}
?></td>
</tr>
<?php endforeach; ?>
</tbody>
<?php
?>
</table>
</div>
</div>
</body>
</div>
</html>