Heartbeat script to watch vital server

/* Heartbeat script - to run regularly on crontab and gather server
status from Well House Manor. This script runs on a remote server and
will email us if:
a) The Router at Well House Manor is not responding
e.g. changed IP, power failure
b) The Manor Web server is down
e.g. switched off / disconnected / has no power
c) Software issue on web server
i.e. the httpd daemon is not running or is overloaded */

/* Crontab line on main server
9,24,39,54 * * * * /usr/local/bin/php /home/welho/private/zzppxping.php
*/


/* Script that runs at heartbeat.php
<?php
$result = `uptime`;
print $result;
?>
*/

$robo = @file_get_contents("http://zzppx.welho.net/heartbeat.php");
$message = "";
$subject = "";
if (strlen ($robo) > 0) {
# Page status is fine
# Add Logging
$fields = explode(" ",trim($robo));
$ld = 0 + $fields[count($fields)-3];
if ($ld > 4) {
$subject = "[zzppx] Server Overloaded zzppx.welho.net";
$message = "Load $ld at $fields[0]";
}
} else {
# No response
$subject = "[zzppx] Server FAILED TO RESPOND zzppx.welho.net";
$message = "No response from server";
}
if ($message) {
$extras = "From: G.E. /n".
"cc: lisa@welho.net, chris@welho.net/n";
"Reply-to: graham@welho.net/n";
mail ("graham@welho.net",$subject,$message,$extras);
}
# print ("Test - $ld - $message - $subject");
?>

-------------------------------------------------------

# Heartbeat script to watch vital server
/* This is a heartbeat script that tests a server (and a page
on that server) and should be run through crontab at an
appropriate interval ... sample crontab line:
8,23,38,53 * * * * /home/wellho/private/phping.php
*/
# Test the server
$robo = @file_get_contents("http://www.wellho.net/demo/rs.php");
# Sample response:
# 06:46:38 * 8 2 9 5 3 2 4 6 13 4 * 136 d 3:58 *
# 1 user * 0.38, 0.44, 0.67
$message = "";
$subject = "";
# Did we get a good response?
if (strlen ($robo) > 0) {
# Page status is fine
# In our particular example, the page we have called up is
# a server status report so we can analyse it. Usually, there
# would be no code in this section.
$fields = explode(" ",trim($robo));
$ld = 0 + $fields[count($fields)-3];
# Is the cpu load over 4? If so - report an issue
if ($ld > 4) {
$subject = "Server Overloaded www.wellho.net";
$message = "Load $ld at $fields[0]";
}
} else {
# No response from server or blank page
$subject = "Server FAILED TO RESPOND www.wellho.net";
$message = "No response from server";
}
# Use email to alter the admin
# No email sent if nothing is wrong
if ($message) {
$extras = "From: G.E. /n".
"cc: lisa@wellho.net, chris@wellho.net/n";
"Reply-to: graham@wellho.net/n";
mail ("graham@wellho.net",$subject,$message,$extras);
}
# print ("Test - $ld - $message - $subject");
?>

------------------------------------------------------------------------------------

http://www.wellho.net/resources/ex.php4?item=h307/hb.php

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值