PHP教學-監測主機
<?php
// 監測的主機, 可以是 ip 或 hostname
$hosts = array(
"192.168.1.10",
"192.168.1.212"
);
$admin_email = "XXXX@gmail.com"; // 管理員的電郵
$load_avg = 2; // 當 load average 達到這個數值, 通知管理員
// function for check server status
function server_check($addr) {
if (($content = file_get_contents("http://" . $addr . "/server-status.php")) !== False) {
if ($content > $GLOBALS["load_avg"]) {
mail($GLOBALS["admin_email"], "Server $addr Busy", "Server $addr Busy\nloading average: $content");
}
} else {
mail($GLOBALS["admin_email"], "Server $addr Down", "Server $addr Down");
}
}
foreach ($hosts as $value) {
server_check($value);
}
?>
// 監測的主機, 可以是 ip 或 hostname
$hosts = array(
"192.168.1.10",
"192.168.1.212"
);
$admin_email = "XXXX@gmail.com"; // 管理員的電郵
$load_avg = 2; // 當 load average 達到這個數值, 通知管理員
// function for check server status
function server_check($addr) {
if (($content = file_get_contents("http://" . $addr . "/server-status.php")) !== False) {
if ($content > $GLOBALS["load_avg"]) {
mail($GLOBALS["admin_email"], "Server $addr Busy", "Server $addr Busy\nloading average: $content");
}
} else {
mail($GLOBALS["admin_email"], "Server $addr Down", "Server $addr Down");
}
}
foreach ($hosts as $value) {
server_check($value);
}
?>
留言
張貼留言