-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTinyMTR.php
202 lines (157 loc) · 4.8 KB
/
TinyMTR.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?php
/*
TinyMTR Web Monitor
Version 1.5.0
https://picotory.com
TinyMTR.php
*/
#################################
// For TinyMTR External Server //
#################################
# Define the class
$TinyMTR = new TinyMTR();
# Get the information on System Memory
$jsonInfo = json_encode($TinyMTR->getSystemMemInfo());
$jsonInfo = stripslashes($jsonInfo);
# Get the information on System Load
$jsonLoad = json_encode($TinyMTR->getSystemLoad());
$jsonLoad = stripslashes($jsonLoad);
# Get the information on System Disk
$jsonDisk = json_encode($TinyMTR->getSystemDisk());
$jsonDisk = stripslashes($jsonDisk);
# Get the information on System Uptime
$jsonUptime = json_encode($TinyMTR->getSystemUptime());
$jsonUptime = stripslashes($jsonUptime);
# Get the information from RAID
$jsonRaid = json_encode($TinyMTR->getRaidInfo());
$jsonRaid = stripslashes($jsonRaid);
###########
// CHECK //
###########
# Respond to checks of this file
if(isset($_GET['verify'])) {
exit('active');
}
###########
// CHECK //
###########
############
// MEMORY //
############
# Decode the JSON and get the server memory usage
$jsonDecMem = json_decode($jsonInfo, true);
$jsonDecMemTotal = explode(' ', $jsonDecMem['MemTotal']);
$jsonDecMemFree = explode(' ', $jsonDecMem['MemFree']);
$jsonDecMemBuff = explode(' ', $jsonDecMem['Buffers']);
$jsonDecMemCache = explode(' ', $jsonDecMem['Cached']);
$jsonCurrentMem = $jsonDecMemTotal[0] - $jsonDecMemFree[0] - $jsonDecMemBuff[0] - $jsonDecMemCache[0];
$jsonCurrentMem = round($jsonCurrentMem/1024);
$jsonDecMemTotal = round($jsonDecMemTotal[0]/1024);
//$Memory = array('memory' => $jsonCurrentMem);
$Memory = array('memoryused' => $jsonCurrentMem, 'memorytotal' => $jsonDecMemTotal);
$Memory = json_encode($Memory);
echo $Memory;
############
// MEMORY //
############
echo '::';
##########
// LOAD //
##########
# Decode the JSON and get the server load
$jsonDecLoad = json_decode($jsonLoad, true);
$jsonDecLoad = explode(' ', $jsonDecLoad['load']);
$Load = array('load1' => $jsonDecLoad[0], 'load5' => $jsonDecLoad[1], 'load15' => $jsonDecLoad[2]);
$Load = json_encode($Load);
echo $Load;
##########
// LOAD //
##########
echo '::';
##########
// DISK //
##########
# Decode the JSON and get the server disk
$jsonDecDisk = json_decode($jsonDisk, true);
$Disk = json_encode($jsonDecDisk);
echo $Disk;
##########
// DISK //
##########
echo '::';
############
// UPTIME //
############
$jsonDecUptime = json_decode($jsonUptime, true);
$Uptime = json_encode($jsonDecUptime);
echo $Uptime;
############
// UPTIME //
############
echo '::';
############
// RAID //
############
$jsonDecRaid = json_decode($jsonRaid, true);
$Raid = json_encode($jsonDecRaid);
echo $Raid;
############
// RAID //
############
class TinyMTR {
function getSystemMemInfo() {
$memData = explode("\n", file_get_contents("/proc/meminfo"));
$memInfo = array();
foreach ($memData as $line) {
list($key, $val) = explode(":", $line);
$memInfo[$key] = trim($val);
}
return $memInfo;
}
function getRaidInfo() {
$memData = explode("\n", file_get_contents("/proc/mdstat"));
if (in_array("(F)", $memData)) {
return array('raid' => "unhealthy");
}else{
return array('raid' => "healthy");
}
}
function getSystemLoad() {
if(file_exists('/proc/loadavg')) {
$load = file_get_contents('/proc/loadavg');
$load = explode(' ', $load, 1);
$load = $load[0];
}
elseif(function_exists('shell_exec')) {
$load = explode(' ', `uptime`);
$load = $load[count($load)-1];
}else {
return false;
}
if(function_exists('shell_exec')) {
$cpu_count = shell_exec('cat /proc/cpuinfo | grep processor | wc -l');
}
return array('load' => $load, 'procs' => $cpu_count);
}
function getSystemDisk() {
$dSpaceKB = (disk_total_space("/")/1024);
$dSpaceMB = $dSpaceKB/1024;
$dSpaceGB = round($dSpaceMB/1024, 2);
$dFSpaceKB = (disk_free_space("/")/1024);
$dFSpaceMB = round($dFSpaceKB/1024);
$dFSpaceGB = round($dFSpaceMB/1024, 1);
$dsUsed = round($dSpaceGB - $dFSpaceGB, 1);
$getSpPercent = round(($dsUsed / $dSpaceGB) * 100);
return array('diskMB' => "$dSpaceMB", 'diskGB' => "$dSpaceGB", 'diskMBfree' => "$dFSpaceMB", 'diskGBfree' => "$dFSpaceGB", 'diskused' => "$dsUsed", 'diskpercent' => "$getSpPercent");
}
function getSystemUptime() {
$up = file_get_contents('/proc/uptime');
$data = explode(" ", $up); # from split()
$days = floor($data[0]/60/60/24);
$hours = $data[0]/60/60%24;
$minutes = $data[0]/60%60;
$seconds = $data[0]%60;
return array('days' => "$days", 'hours' => "$hours", 'minutes' => "$minutes", 'seconds' => "$seconds");
}
}
?>