Products
GG网络技术分享 2025-03-18 16:14 0
大家好,这里是关于[使用PHP Server Monitor自建服务器网络监控系统],[php开发一个测试机静态网页数据监控的网页]问题的解答,希望对您有所帮助。如果你还想了解更多这方面的信息,请关注本站其他相关内容,共同学习吧!
教程大全PHP Server Monitor,服务器ping监控,服务器网络监控
使用PHP Server Monitor自建服务器网络监控系统
这类监控服务器网络和运行状态的源码还是挺多的,今天给大家介绍一下PHP Server Monitor的安装和使用。
另一个更简单轻便的监控源码Uptime Status:
Uptime Status–使用UptimeRobot自建服务器Ping和网站在线率监控
PHP Server Monitor官网:http://www.phpservermonitor.org
demo预览网站:https://www.feitutu.com/?login=test
1.Ping监控
2.端口连通性监控
3.网站内容匹配监控(这一项有很多玩法,比如监测库存!)
程序官方下载地址:http://www.phpservermonitor.org/download/
官方网站下载不是最新版,最新版请到github下载:
GitHub:https://github.com/phpservermon/phpservermon
安装地址http://youdomain.com/install.php
这里会显示你是用的PHP版本和cURL扩展是否安装。宝塔面板的PHP默认已安装cURL。
首先是网站地址,默认即可
数据库信息填写后如果下一步提示不能写入配置文件,则可以直接编辑config.php文件写入数据库信息。
define(\'PSM_DB_PREFIX\', \'psm_\');#表前缀,保持默认
define(\'PSM_DB_USER\', \'yonghu\');#数据库用户
define(\'PSM_DB_PASS\', \'mima\');#数据库密码
define(\'PSM_DB_NAME\', \'yonghuming\');#数据库用户名
define(\'PSM_DB_HOST\', \'localhost\');#数据库连接地址
define(\'PSM_DB_PORT\', \'3306\');#数据库连接端口,一般默认3306
define(\'PSM_BASE_URL\', \'https://www.feitutu.com\');#网站地址
默认站点目录内只有个config.php.sample文件,就是这个,我们把后面的.sample删掉即可。程序找不到config.php肯定会提示无法写入啦。
下一步直接就安装完成了,会显示添加了哪些数据库数据等信息。注意看下是否有提示错误。
这时候访问网站首页就到了登录页面
宝塔用户比较方便可以直接在计划任务里添加。
/www/server/php/72/bin/php /www/wwwroot/www.feitutu.com/cron/status.cron.php
定时任务设置的执行周期越小,监控频率就越高。本人设置的1分钟。
提示:注意定时任务代码里面的PHP环境目录和网站目录,改成自己的。
其他环境需要手动安装crontab然后添加任务。其中*/1 * * * *这里面的1就是监控执行周期,1就是1分钟。自己修改即可。
#安装crontab
yum -y install crontabs
#添加定时任务
crontab -e
#计划任务中添加如下内容,请根据实际情况修改路径
*/1 * * * * /www/server/php/72/bin/php /www/wwwroot/www.feitutu.com/cron/status.cron.php
#重载crontab
service crond reload到这里教程就结束了,剩下的大家自己研究下吧。
提示:官网网站下载的3.2.0版本,如果是用PHP7.2可能无法打开用户页面,换成php7.1即可解决。
其他文章:PHP Server Monitor开启公共访问,访客用户自动登录并删除可操作菜单选项
1. php作为网页数据后端处理开发语言, 它类似于perl语言的语法,学习上手都是比较容易。下面可以简单的做一个monitor 测试机运行状态的php网页,帮助你更好的监控和了解测试机运行状态。
php源码:
php name : tester_info_monitor.php
<meta name=\"Author\" content=\"JIM\">
<meta http-equiv=\"pragma\" content=\"no-cache\">
<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">
<link rel=stylesheet href=\"/css/common.css\" type=\"text/css\">
<title>Tester Status Monitor</title>
<br />
<meta charset=\"utf-8\">
<head><font color=\"blue\" size=\"6\" >All Linux Tester Disk And Tester Status Monitor</font></head>
<?php
echo \"<br>\";
echo \"今天是\".date(\"Y-m-d\").\"-\".date(\"l\").\"<br>\";
echo \"<br>\";
echo \"<hr>\";
echo \"<p>\";
echo \"<b>注意:</b><br>\";
echo \"1.如果Tester Run Time(Power on time) > 30days ,请在不测试时重启tester,避免tester长时间待机导致正常测试出现异常。<br>\";
echo \"2.如果Tester 硬盘分区使用率Use% > 90% ,请联系工程师清理tester 的磁盘分区。<br>\";
echo \"</p>\";
$file = fopen(\"/var/www/html/upload/tester_disk_info.txt\",\"rb\")or die (\"the file not open\");
$i=1;
echo \"<table align=\'left\' width=\'70%\' border=\'1\' cellspacing=0 >
<tr bgcolor=orange>
<th >#</th>
<th >Filesystem</th>
<th >Total Size</th>
<th >Used</th>
<th >Available</th>
<th >Use%</th>
<th >Mounted on</th>
<th >Filesystem</th>
<th >Total Size</th>
<th >Used</th>
<th >Available</th>
<th >Use%</th>
<th >Mounted on</th>
<th >Use Slot</th>
<th >Idel Slot</th>
<th >Total slot</th>
<th >Tester Run Time(Power on time)</th>
<th >Hostname</th>
<th >Tester IP</th>
</tr>\";
while(!feof($file)){
$line = fgets($file); //每读取一行
if (preg_match(\"/\\/dev\\/sda1.*/\", $line,$match)){
$info=explode(\"\\t\",$line);
echo \"<tr align=\'center\' bgcolor=FFFFDF>\";
echo \"<td>\" . $i . \"</td>\";
echo \"<td>\" . $info[0] . \"</td>\";
echo \"<td>\" . $info[1] . \"</td>\";
echo \"<td>\" . $info[2] . \"</td>\";
echo \"<td>\" . $info[3] . \"</td>\";
$use_per = trim($info[4]);
$use_per1 = explode(\"%\" ,$use_per);
if (($use_per1[0] >= 60) and ($use_per1[0] <= 90)){
echo \"<td bgcolor=yellow>\".$info[4].\"</td>\";
}elseif(($use_per1[0] > 90)){
echo \"<td bgcolor=red>\".$info[4].\"</td>\";
}else{
echo \"<td>\".$info[4].\"</td>\";
}
echo \"<td>\" . $info[5] . \"</td>\";
echo \"<td>\" . $info[6] . \"</td>\";
echo \"<td>\" . $info[7] . \"</td>\";
echo \"<td>\" . $info[8] . \"</td>\";
echo \"<td>\" . $info[9] . \"</td>\";
$use_per = trim($info[10]);
$use_per1 = explode(\"%\" ,$use_per);
if (($use_per1[0] >= 60) and ($use_per1[0] <= 90)){
echo \"<td bgcolor=yellow>\".$info[10].\"</td>\";
}elseif(($use_per1[0] > 90)){
echo \"<td bgcolor=red>\".$info[10].\"</td>\";
}else{
echo \"<td>\".$info[10].\"</td>\";
}
echo \"<td>\".$info[11].\"</td>\";
echo \"<td>\".$info[12].\"</td>\";
echo \"<td>\".$info[13].\"</td>\";
echo \"<td>\".$info[14].\"</td>\";
$run_time = trim($info[15]);
if (preg_match(\"/(\\d+)days/\", $info[15],$mat)){
if (($mat[1] > 30)){
echo \"<td bgcolor=yellow>\".$info[15].\"</td>\";
}else{
echo \"<td>\".$info[15].\"</td>\";
}
}else{
echo \"<td>\".$info[15].\"</td>\";
}
echo \"<td>\".$info[16].\"</td>\"
echo \"<td>\".\"<a href=\\\"http://$info[17]:/iss/view\\\" target=\'_blank\'>\" . $info[17] .\"</a>\". \"</td>\";
echo \"</tr>\";
$i++;
}
}
fclose($file);
?>
2. tester information sample,仅为后面网页显示效果。
sample data name : tester_disk_info.txt
/dev/sda192G22G66G25%//dev/sda2367G25G324G8%/export08817dayscsst2ibmfct-0110.194.100.45 /dev/sda147G11G34G24%//dev/sda2870G27G800G4%/export26814dayscsst2ibmfct-0310.194.100.46 /dev/sda147G19G27G42%//dev/sda2870G12G815G2%/export088162dayscsst2ibmfct-0210.194.100.47 /dev/sda147G13G33G28%//dev/sda2870G25G802G3%/export26814dayscsst2ibmfct-0410.194.100.48 /dev/sda147G14G31G31%//dev/sda2870G28G799G4%/export44814dayscsst2ibmfct-0510.194.100.49 /dev/sda147G12G34G26%//dev/sda2870G27G800G4%/export62814dayscsst2ibmfct-0610.194.100.50 /dev/sda194G13G77G15%//dev/sda2823G19G763G3%/export0889dayscsst2ibmfct-0710.194.100.51 /dev/sda147G12G33G27%//dev/sda2870G23G803G3%/export53814dayscsst2ibmfct-0810.194.100.52 /dev/sda147G19G27G42%//dev/sda2870G23G803G3%/export08818dayscsst2ibmfct-0910.194.100.53 /dev/sda147G17G29G37%//dev/sda2870G18G808G3%/export80818dayscsst2ibmfct-1010.194.100.54 /dev/sda147G18G27G40%//dev/sda2870G16G810G2%/export08818dayscsst2ibmfct-1110.194.100.55
3. 网页显示的效果:
Demand feedback