-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.php
126 lines (104 loc) · 3.08 KB
/
test.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
<?php
# Initialize Variables
$hostname = $_SERVER['HTTP_HOST'];
$unique = array();
$www_unique_count = 0;
$www_total_count = 0;
$proc_count = 0;
$display_www = false;
# Check if 'exec()' is enabled
if ( function_exists ( 'exec' ) )
{
$display_www = true;
# Get HTTP connections
@exec ( 'netstat -an | egrep \':80|:443\' | awk \'{print $5}\' | grep -v \':::\*\' | grep -v \'0.0.0.0\'', $results );
foreach ( $results as $result )
{
$array = explode ( ':', $result );
$www_total_count ++;
if ( preg_match ( '/^::/', $result ) )
{
$ipaddr = $array[3];
}
else
{
$ipaddr = $array[0];
}
if ( ! in_array ( $ipaddr, $unique ) )
{
$unique[] = $ipaddr;
$www_unique_count ++;
}
}
unset ( $results );
}
# Get Server Load
$loadavg = explode ( ' ', file_get_contents ( '/proc/loadavg' ) );
$loadavg = "{$loadavg[0]} {$loadavg[1]} {$loadavg[2]}";
# Get Disk Utilization
$disktotal = disk_total_space ( '/' );
$diskfree = disk_free_space ( '/' );
$diskuse = round ( 100 - ( ( $diskfree / $disktotal ) * 100 ) ) . "%";
# Get server uptime
$uptime = floor ( preg_replace ( '/\.[0-9]+/', '', file_get_contents ( '/proc/uptime' ) ) / 86400 );
# Get kernel version
$kernel = explode ( ' ', file_get_contents ( '/proc/version' ) );
$kernel = $kernel[2];
# Get number of processes
$dh = opendir ( '/proc' );
while ( $dir = readdir ( $dh ) )
{
if ( is_dir ( '/proc/' . $dir ) )
{
if ( preg_match ( '/^[0-9]+$/', $dir ) )
{
$proc_count ++;
}
}
}
# Get memory usage
foreach ( file ( '/proc/meminfo' ) as $result )
{
$array = explode ( ':', str_replace ( ' ', '', $result ) );
$value = preg_replace ( '/kb/i', '', $array[1] );
if ( preg_match ( '/^MemTotal/', $result ) )
{
$totalmem = $value;
}
elseif ( preg_match ( '/^MemFree/', $result ) )
{
$freemem = $value;
}
elseif ( preg_match ( '/^Buffers/', $result ) )
{
$buffers = $value;
}
elseif ( preg_match ( '/^Cached/', $result ) )
{
$cached = $value;
}
}
$freemem = ( $freemem + $buffers + $cached );
$usedmem = round ( 100 - ( ( $freemem / $totalmem ) * 100 ) ) . "%";
?>
<html>
<body>
<font size=5><b><?=$hostname?></b></font><br><br>
<?php
if ( $display_www === true )
{
?>
<font size=4><b>Web Server (80 and 443)</b></font><br>
<font size=3><b><i><?=$www_unique_count?></b></i></font><font size=2> unique connections</font><br>
<font size=3><b><i><?=$www_total_count?></b></i></font><font size=2> total connections</font><br>
<?php
}
?>
<font size=3><i><b>Kernel Version:</b> <?=$kernel?></i></font><br>
<font size=3><i><b>Uptime:</b> <?=$uptime?> days</i></font><br>
<font size=3><i><b>Load Average:</b> <?=$loadavg?></i></font><br>
<font size=3><i><b>Disk Use:</b> <?=$diskuse?></i></font><br>
<font size=3><i><b>Memory Utilization: </b><?=$usedmem?></i></font><br>
<font size=3><i><b>Total Processes: </b><?=$proc_count?></i></font><br>
</body>
</html>