📄 Viewing: mojo_nagios_memory_check.php
<html>
<head>
<meta http-equiv="refresh" content="120">
</head>
<body>
<?php
$max_usage = 80;
$free = file_get_contents("/proc/meminfo");
if ($free == false) {
die("Unable to load meminfo".PHP_EOL);
}
$free = (string)trim($free);
$free_arr = explode("\n", $free);
for($x = 0; $x < count($free_arr); $x++) {
$mem_tmp = explode(":", $free_arr[$x]);
$mem[$mem_tmp[0]]=(int)trim($mem_tmp[1]);
}
$free = ($mem['MemFree'] + $mem['Buffers'] + $mem['Cached']);
$total = $mem['MemTotal'];
$used = ($total - $free);
$memory_usage = number_format((($used / $total) * 100),2);
if ($memory_usage > $max_usage) {
echo "RAM Usage is high: $memory_usage%".PHP_EOL;
} else {
echo "OK: $memory_usage%".PHP_EOL;
}
?>
</body>
</html>
🌑 DarkStealth — WP Plugin Edition
Directory: /home/httpd/html