运维自动化之使用PHP+MYSQL+SHELL打造私有监控系统(五)

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

4、监控视图

主要是通过 shell脚本进行收集mysql的数据,然后同gnuplot软件进行数据视图化,然后php加载这些图片到web里显示,用到的php文件为view.php
day.php、 month.php、year.php、gansu_day_view.php、gansu_day_web.php(各省安装服务器类型有各自的,比如甘肃当天的备用的程序为gansu_day_beiyong.php)、gansu_month_view.php 、gansu_month_web.php、gansu_year_view.php 、gansu_year_web.php.
详细的 php程序描述
A、 add.php
 
  1. <?php 
  2. include("conn.php");  
  3.  include("head.php");  
  4.  include("head_device.php");  
  5.  ?> 
主要有 3个表,分别的作用为:
conn.php是连接数据库的
head.php是 php的head文件
head_device.php是设备的 head文件
B、 add_device.php
 
  1. <?php 
  2. include("conn.php");  
  3.  include("head.php");  
  4.  
  5.  if($_POST['submit']){  
  6.  
  7.  
  8.   $sql="insert into device values ('','$_POST[name]','$_POST[ip]','$_POST[mac]','$_POST[type]','$_POST[jifang_name]','$_POST[raw_name]','$_POST[raw_location]','$_POST[assets_code]','$_POST[state]','$_POST[price]')";  
  9.   mysql_query($sql);  
  10.   echo "<script language=\"javascript\">alert('添加成功');history.go(-1)</script>";  
  11.  
  12.  }  
  13. ##点击完提交后,就进行添加并返回添加成功按键  
  14.  include("head_device.php");  
  15. ?> 
  16. <SCRIPT language=javascript> 
  17. function CheckPost()  
  18. {  
  19.     if (myform.name.value=="")  
  20.     {  
  21.         alert("请填写设备名称");  
  22.         myform.name.focus();  
  23.         return false;  
  24.     }  
  25.     if (myform.ip.value.length<5)  
  26.     {  
  27.         alert("设备ip不能少于5个字符");  
  28.         myform.ip.focus();  
  29.         return false;  
  30.     }  
  31.     if (myform.mac.value.length<23)  
  32.     {  
  33.         alert("设备mac不能少于23位");  
  34.         myform.mac.focus();  
  35.         return false;  
  36.     }  
  37.     if (myform.type.value=="")  
  38.     {  
  39.         alert("请填写设备类型");  
  40.         myform.type.focus();  
  41.         return false;  
  42.     }  
  43.         if (myform.jifang_name.value=="")  
  44.     {  
  45.         alert("请填写机房名称");  
  46.         myform.jifang_name.focus();  
  47.         return false;  
  48.     }  
  49.         if (myform.raw_name.value=="")  
  50.     {  
  51.         alert("请填写机架名称");  
  52.         myform.raw_name.focus();  
  53.         return false;  
  54.     }  
  55.         if (myform.raw_location.value=="")  
  56.     {  
  57.         alert("请填写设备位置");  
  58.         myform.raw_location.focus();  
  59.         return false;  
  60.     }  
  61.         if (myform.assets_code.value=="")  
  62.     {  
  63.         alert("请填写财产编号");  
  64.         myform.assets_code.focus();  
  65.         return false;  
  66.     }  
  67.         if (myform.state.value=="")  
  68.     {  
  69.         alert("请填写设备状态");  
  70.         myform.state.focus();  
  71.         return false;  
  72.     }  
  73.         if (myform.price.value=="")  
  74.     {  
  75.         alert("请填写设备价格");  
  76.         myform.price.focus();  
  77.         return false;  
  78.     }  
  79. }  
  80. </SCRIPT> 
  81. ##使用javascript方式进行约束各自的值  
  82.  <form action="add_device.php" method="post" name="myform" onsubmit="return CheckPost();"> 
  83.  设备名称:<input type="text" size="10" name="name" /><br> 
  84.  设备I P: <input type="text" size="10" name="ip" /><br/> 
  85.  设备MAC: <input type="text" size="10" name="mac" /><br/> 
  86.  设备类型:<input type="text" size="10" name="type" /><br/> 
  87.   机房名称:<input type="text" size="10" name="jifang_name" /><br/> 
  88.   机架名称:<input type="text" size="10" name="raw_name" /><br/> 
  89.   机架位置:<input type="text" size="10" name="raw_location" /><br/> 
  90.  财产编号:<input type="text" size="10" name="assets_code" /><br/> 
  91.  设备状态:<input type="text" size="10"name="state" /><br/> 
  92.  设备价格:<input type="text" size="10" name="price" /><br/> 
  93.  <input type="submit" name="submit" value="新增"/> 
  94.  <input name="reset" type="reset" value="重置" /> 
  95.  </form> 
  96. ##使用html表单  
C、 conn.php
 
  1. <?php 
  2. $conn = @ mysql_connect("1.1.1.1", "root", "****") or die("数据库链接错误");  
  3. mysql_select_db("monitor", $conn);  
  4. mysql_query("set names 'GBK'"); //使用GBK中文编码;  
  5. ##连接的数据库ip、用户名与密码,如果连接不成功,就返回数据库连接错误  
  6. #function htmtocode($content) {  
  7. #   $content = str_replace("\n", "<br>", str_replace(" ", "&nbsp;", $content));  
  8. #   return $content;  
  9. #}  
  10.  
  11. function htmtocode($status) {  
  12. str_replace("working", "test", $status);  
  13.  
  14.     return $status;  
  15. }  
  16. #function  
  17. //$content=str_replace("'","‘",$content);  
  18.  //htmlspecialchars();  
  19.  
  20. ?> 
D、 gansu.php
 
  1. <?php  
  2. include("conn.php");  
  3. include("head.php");  
  4. include("province.php");  
  5. ?>  
  6.  <font size="3" color="red"><B>应用服务</B></font>  
  7.  
  8.  <table border="1" cellspacing="0" >  
  9.     <tr>  
  10.     <th width="55">编号</th>  
  11.     <th width="55">省份</th>  
  12.     <th width="160">被监控服务器</th>  
  13.     <th width="100">IP</th>  
  14.     <th width="100">监控服务器</th>  
  15.     <th width="130">监控服务</th>  
  16.     <th width="70">当前状态</th>  
  17.     <th width="100">监控时间</th>  
  18.   </tr>  
  19.   </table>  
  20. <?  
  21.  
  22.  $SQL="SELECT * FROM `gansu_service` order by date desc limit 0,13";  
  23.   $query=mysql_query($SQL);  
  24.   while($row=mysql_fetch_array($query)){  
  25. ?>  
  26. <table border="1" cellspacing="0" cellpadding="0">  
  27.   <tr>  
  28.     <td width="55"><?=$row[id]?> </td>  
  29.     <td width="55"><?=$row[province]?></td>  
  30.     <td width="160"><?=$row[server]?> </td>  
  31.     <td width="100"><?=$row[ip]?></td>  
  32.     <td width="100"><?=$row[monitor_server]?></td>  
  33.     <td width="130"><?=$row[service]?></td>  
  34.     <td width="70"><?=$row[status]?></td>  
  35.     <td width="100"><?=$row[date]?></td>  
  36.   </tr>  
  37.  
  38. </table>  
  39. <?  
  40.   }  
  41. ?>  
  42. <font size="3" color="red"><B>硬盘使用率</B></font>  
  43.  <table border="1" cellspacing="0" >  
  44.     <tr>  
  45.     <th width="55">编号</th>  
  46.     <th width="55">省份</th>  
  47.     <th width="160">被监控服务器</th>  
  48.     <th width="100">IP</th>  
  49.     <th width="100">监控服务器</th>  
  50.     <th width="130">监控服务</th>  
  51.     <th width="70">阀值</th>  
  52.     <th width="90">当期分区</th>  
  53.     <th width="70">当前值</th>  
  54.     <th width="70">当前状态</th>  
  55.     <th width="100">监控时间</th>  
  56.   </tr>  
  57.   </table>  
  58. <?  
  59.  $SQL="SELECT * FROM `gansu_disk` order by date desc limit 0,5";  
  60.   $query=mysql_query($SQL);  
  61.   while($row=mysql_fetch_array($query)){  
  62. ?>  
  63.   <table border="1" cellspacing="0" cellpadding="0">  
  64.   <tr>  
  65.     <td width="55"><?=$row[id]?> </td>  
  66.     <td width="55"><?=$row[province]?></td>  
  67.     <td width="160"><?=$row[server]?> </td>  
  68.     <td width="100"><?=$row[ip]?></td>  
  69.     <td width="100"><?=$row[monitor_server]?></td>  
  70.     <td width="130"><?=$row[service]?></td>  
  71.     <td width="70"><?=$row[alert]?></td>  
  72.     <td width="90"><?=$row[partition]?></td>  
  73.     <td width="70"><?=$row[value]?></td>  
  74.     <td width="70"><?=$row[status]?></td>  
  75.     <td width="100"><?=$row[date]?></td>  
  76.   </tr>  
  77.  
  78. </table>  
  79. <?  
  80.   }  
  81. ?>  
  82. <font size="3" color="red"><B>CPU使用率</B></font>  
  83.  <table border="1" cellspacing="0" >  
  84.     <tr>  
  85.     <th width="55">编号</th>  
  86.     <th width="55">省份</th>  
  87.     <th width="160">被监控服务器</th>  
  88.     <th width="100">IP</th>  
  89.     <th width="100">监控服务器</th>  
  90.     <th width="130">监控服务</th>  
  91.     <th width="70">阀值</th>  
  92.     <th width="70">当前值</th>  
  93.     <th width="70">当前状态</th>  
  94.     <th width="100">监控时间</th>  
  95.   </tr>  
  96.   </table>  
  97. <?  
  98.  $SQL="SELECT * FROM `gansu_cpu` order by date desc limit 0,5";  
  99.   $query=mysql_query($SQL);  
  100.   while($row=mysql_fetch_array($query)){  
  101. ?>  
  102. <table border="1" cellspacing="0" cellpadding="0">  
  103.   <tr>  
  104.     <td width="55"><?=$row[id]?> </td>  
  105.     <td width="55"><?=$row[province]?></td>  
  106.     <td width="160"><?=$row[server]?> </td>  
  107.     <td width="100"><?=$row[ip]?></td>  
  108.     <td width="100"><?=$row[monitor_server]?></td>  
  109.     <td width="130"><?=$row[service]?></td>  
  110.     <td width="70"><?=$row[alert]?></td>  
  111.     <td width="70"><?=$row[value]?></td>  
  112.     <td width="70"><?=$row[status]?></td>  
  113.     <td width="100"><?=$row[date]?></td>  
  114.   </tr>  
  115.  
  116. </table>  
  117. <?  
  118.   }  
  119. ?>  
  120.  
  121.  
  122. <font size="3" color="red"><B>硬件错误信息</B></font>  
  123.  <table border="1" cellspacing="0" >  
  124.     <tr>  
  125.     <th width="55">编号</th>  
  126.     <th width="55">省份</th>  
  127.     <th width="160">被监控服务器</th>  
  128.     <th width="100">IP</th>  
  129.     <th width="100">监控服务器</th>  
  130.     <th width="130">监控服务</th>  
  131.     <th width="70">阀值</th>  
  132.     <th width="70">当前值</th>  
  133.     <th width="70">当前状态</th>  
  134.     <th width="100">监控时间</th>  
  135.   </tr>  
  136.   </table>  
  137. <?  
  138.  $SQL="SELECT * FROM `gansu_hardware` order by date desc limit 0,5";  
  139.   $query=mysql_query($SQL);  
  140.   while($row=mysql_fetch_array($query)){  
  141. ?>  
  142. <table border="1" cellspacing="0" cellpadding="0">  
  143.   <tr>  
  144.     <td width="55"><?=$row[id]?> </td>  
  145.     <td width="55"><?=$row[province]?></td>  
  146.     <td width="160"><?=$row[server]?> </td>  
  147.     <td width="100"><?=$row[ip]?></td>  
  148.     <td width="100"><?=$row[monitor_server]?></td>  
  149.     <td width="130"><?=$row[service]?></td>  
  150.     <td width="70"><?=$row[alert]?></td>  
  151.     <td width="70"><?=$row[value]?></td>  
  152.     <td width="70"><?=$row[status]?></td>  
  153.     <td width="100"><?=$row[date]?></td>  
  154.   </tr>  
  155.  
  156. </table>  
  157. <?  
  158.   }  
  159. ?>  
  160.  
  161. <font size="3" color="red"><B>I/O使用率</B></font>  
  162.  <table border="1" cellspacing="0" >  
  163.     <tr>  
  164.     <th width="55">编号</th>  
  165.     <th width="55">省份</th>  
  166.     <th width="160">被监控服务器</th>  
  167.     <th width="100">IP</th>  
  168.     <th width="100">监控服务器</th>  
  169.     <th width="130">监控服务</th>  
  170.     <th width="70">阀值</th>  
  171.     <th width="70">当前值</th>  
  172.     <th width="70">当前状态</th>  
  173.     <th width="100">监控时间</th>  
  174.   </tr>  
  175.   </table>  
  176. <?  
  177.  $SQL="SELECT * FROM `gansu_io` order by date desc limit 0,5";  
  178.   $query=mysql_query($SQL);  
  179.   while($row=mysql_fetch_array($query)){  
  180. ?>  
  181. <table border="1" cellspacing="0" cellpadding="0">  
  182.   <tr>  
  183.     <td width="55"><?=$row[id]?> </td>  
  184.     <td width="55"><?=$row[province]?></td>  
  185.     <td width="160"><?=$row[server]?> </td>  
  186.     <td width="100"><?=$row[ip]?></td>  
  187.     <td width="100"><?=$row[monitor_server]?></td>  
  188.     <td width="130"><?=$row[service]?></td>  
  189.     <td width="70"><?=$row[alert]?></td>  
  190.     <td width="70"><?=$row[value]?></td>  
  191.     <td width="70"><?=$row[status]?></td>  
  192.     <td width="100"><?=$row[date]?></td>  
  193.   </tr>  
  194.  
  195. </table>  
  196. <?  
  197.   }  
  198. ?>  
  199.  
  200. <font size="3" color="red"><B>15分钟内的负载</B></font>  
  201.  <table border="1" cellspacing="0" >  
  202.     <tr>  
  203.     <th width="55">编号</th>  
  204.     <th width="55">省份</th>  
  205.     <th width="160">被监控服务器</th>  
  206.     <th width="100">IP</th>  
  207.     <th width="100">监控服务器</th>  
  208.     <th width="130">监控服务</th>  
  209.     <th width="70">阀值</th>  
  210.     <th width="70">当前值</th>  
  211.     <th width="70">当前状态</th>  
  212.     <th width="100">监控时间</th>  
  213.   </tr>  
  214.   </table>  
  215. <?  
  216.  $SQL="SELECT * FROM `gansu_load` order by date desc limit 0,5";  
  217.   $query=mysql_query($SQL);  
  218.   while($row=mysql_fetch_array($query)){  
  219. ?>  
  220.   <table border="1" cellspacing="0" cellpadding="0">  
  221.   <tr>  
  222.     <td width="55"><?=$row[id]?> </td>  
  223.     <td width="55"><?=$row[province]?></td>  
  224.     <td width="160"><?=$row[server]?> </td>  
  225.     <td width="100"><?=$row[ip]?></td>  
  226.     <td width="100"><?=$row[monitor_server]?></td>  
  227.     <td width="130"><?=$row[service]?></td>  
  228.     <td width="70"><?=$row[alert]?></td>  
  229.     <td width="70"><?=$row[value]?></td>  
  230.     <td width="70"><?=$row[status]?></td>  
  231.     <td width="100"><?=$row[date]?></td>  
  232.   </tr>  
  233.  
  234.  
  235. </table>  
  236. <?  
  237.   }  
  238. ?>  
  239.  
  240. <font size="3" color="red"><B>内存使用率</B></font>  
  241.  <table border="1" cellspacing="0" >  
  242.     <tr>  
  243.     <th width="55">编号</th>  
  244.     <th width="55">省份</th>  
  245.     <th width="160">被监控服务器</th>  
  246.     <th width="100">IP</th>  
  247.     <th width="100">监控服务器</th>  
  248.     <th width="130">监控服务</th>  
  249.     <th width="70">阀值</th>  
  250.     <th width="70">当前值</th>  
  251.     <th width="70">当前状态</th>  
  252.     <th width="100">监控时间</th>  
  253.   </tr>  
  254.   </table>  
  255. <?  
  256.  $SQL="SELECT * FROM `gansu_memory` order by date desc limit 0,10";  
  257.   $query=mysql_query($SQL);  
  258.   while($row=mysql_fetch_array($query)){  
  259. ?>  
  260. <table border="1" cellspacing="0" cellpadding="0">  
  261.   <tr>  
  262.     <td width="55"><?=$row[id]?> </td>  
  263.     <td width="55"><?=$row[province]?></td>  
  264.     <td width="160"><?=$row[server]?> </td>  
  265.     <td width="100"><?=$row[ip]?></td>  
  266.     <td width="100"><?=$row[monitor_server]?></td>  
  267.     <td width="130"><?=$row[service]?></td>  
  268.     <td width="70"><?=$row[alert]?></td>  
  269.     <td width="70"><?=$row[value]?></td>  
  270.     <td width="70"><?=$row[status]?></td>  
  271.     <td width="100"><?=$row[date]?></td>  
  272.   </tr>  
  273.  
  274. </table>  
  275. <?  
  276.   }  
  277. ?>  
  278.  
  279. <font size="3" color="red"><B>日志错误信息</B></font>  
  280.  <table border="1" cellspacing="0" >  
  281.     <tr>  
  282.     <th width="55">编号</th>  
  283.     <th width="55">省份</th>  
  284.     <th width="160">被监控服务器</th>  
  285.     <th width="100">IP</th>  
  286.     <th width="100">监控服务器</th>  
  287.     <th width="130">监控服务</th>  
  288.     <th width="70">阀值</th>  
  289.     <th width="70">当前值</th>  
  290.     <th width="70">当前状态</th>  
  291.     <th width="100">监控时间</th>  
  292.   </tr>  
  293.   </table>  
  294.  
  295. <?  
  296.  $SQL="SELECT * FROM `gansu_message` order by date desc limit 0,5";  
  297.   $query=mysql_query($SQL);  
  298.   while($row=mysql_fetch_array($query)){  
  299. ?>  
  300.  <table border="1" cellspacing="0" cellpadding="0">  
  301.   <tr>  
  302.     <td width="55"><?=$row[id]?> </td>  
  303.     <td width="55"><?=$row[province]?></td>  
  304.     <td width="160"><?=$row[server]?> </td>  
  305.     <td width="100"><?=$row[ip]?></td>  
  306.     <td width="100"><?=$row[monitor_server]?></td>  
  307.     <td width="130"><?=$row[service]?></td>  
  308.     <td width="70"><?=$row[alert]?></td>  
  309.     <td width="70"><?=$row[value]?></td>  
  310.     <td width="70"><?=$row[status]?></td>  
  311.     <td width="100"><?=$row[date]?></td>  
  312.   </tr>  
  313.  
  314. </table>  
  315. <?  
  316.   }  
  317. ?>  
  318.  
  319. <font size="3" color="red"><B>用户登录数</B></font>  
  320.  <table border="1" cellspacing="0" >  
  321.     <tr>  
  322.     <th width="55">编号</th>  
  323.     <th width="55">省份</th>  
  324.     <th width="160">被监控服务器</th>  
  325.     <th width="100">IP</th>  
  326.     <th width="100">监控服务器</th>  
  327.     <th width="130">监控服务</th>  
  328.     <th width="70">阀值</th>  
  329.     <th width="70">当前值</th>  
  330.     <th width="70">当前状态</th>  
  331.     <th width="100">监控时间</th>  
  332.   </tr>  
  333.   </table>  
  334. <?  
  335.  $SQL="SELECT * FROM `gansu_user` order by date desc limit 0,5";  
  336.   $query=mysql_query($SQL);  
  337.   while($row=mysql_fetch_array($query)){  
  338. ?>  
  339.  
  340. <table border="1" cellspacing="0" cellpadding="0">  
  341.   <tr>  
  342.     <td width="55"><?=$row[id]?> </td>  
  343.     <td width="55"><?=$row[province]?></td>  
  344.     <td width="160"><?=$row[server]?> </td>  
  345.     <td width="100"><?=$row[ip]?></td>  
  346.     <td width="100"><?=$row[monitor_server]?></td>  
  347.     <td width="130"><?=$row[service]?></td>  
  348.     <td width="70"><?=$row[alert]?></td>  
  349.     <td width="70"><?=$row[value]?></td>  
  350.     <td width="70"><?=$row[status]?></td>  
  351.     <td width="100"><?=$row[date]?></td>  
  352.   </tr>  
  353.  
  354. </table>  
  355. <?  
  356.   }  
  357. ?>  

此页面主要是各省展示自己的监控服务与资源详情的页面。

主要是通过从 mysql里获取各自表的数据,插入到我设定好的表单里,在web里显示,这些表单的格式都是通过css进行控制的。
E、 css.css
 
  1. td {  
  2.     line-height: 16pt;  
  3.     font-size: 10pt;  
  4.     font-family: "Verdana", "Arial", "Helvetica", "sans-serif";  
  5. }  
  6. a:link {  
  7.     text-decoration: none;  
  8.     color: #000000;  
  9. }  
  10. a:visited {  
  11.     text-decoration: none;  
  12.     color: #000000;  
  13. }  
  14. a:hover {  
  15.     text-decoration: underline;  
  16.     color: #FF3333;  
  17. }  
  18. body {  
  19.     font-size: 10pt;  
  20.     line-height: 13pt;  
  21.     background-color: #ECF5FF;  
  22. }  
  23. .border {  
  24.     border: 1px solid #1D5892;  
  25. }  
  26. textarea {  
  27.     font-size: 8pt;  
  28.     font-family: "Verdana", "Arial", "Helvetica", "sans-serif";  
  29.     border: 1px solid #999999;  
  30.     padding: 5px;  
  31.  
  32.  
  33. }  
  34. select {  
  35.     font-size: 8pt;  
  36.     padding: 1px;  
  37.     font-family: "Tahoma";  
  38. }  
  39. .a1:link {  
  40.     color: #FFFFFF;  
  41. }  
  42. .a1:visited {  
  43.     color: #FFFFFF;  
  44. }  
  45. .a1:hover {  
  46.     color: #FF9900;  
  47. }  
  48. .font14 {  
  49.     font-size: 14px;  
  50.     font-family: "Tahoma";  
  51. }  
  52. form {  
  53.     margin: 0px;  
  54.     padding: 0px;  
  55. }  
  56. .alpha {  
  57.     filter: Alpha(Opacity=20);  
  58. }  
  59. .filearea {  
  60.     font-size: 9pt;  
  61. }  
  62. .textdrow {  
  63.     color:#666666;  
  64.     filter: DropShadow(Color=whiteOffX=1OffY=1Positive=1);  
  65. }  
  66. .font18 {  
  67.     font-size: 19px;  
  68. }  
  69. .p {  
  70.     text-indent: 24px;  
  71. }  
  72. .font16 {  
  73.     font-size: 16px;  
  74. }  
  75. .border2 {  
  76.     border: 1px solid #D5E4F4;  
  77. }  
  78. .xborder {  
  79.     border: 2px dotted #EBF5FE;  
  80. }  
  81. table {  
  82. width: 1100px;  
  83. }  
  84.  
  85. td {  
  86. text-align:center;  
  87. }  
主要是观察最后 2项,是控制表的宽度与表里单元格的内容显示方法。
F、 gansu_warn.php
 
  1. <?php 
  2. include ("conn.php");  
  3. include ("head.php");  
  4. include("warn_province.php");  
  5. ?> 
  6. <? 
  7. /*检测服务报警  
  8.  *  
  9.  */  
  10.  $SQL="select * from gansu_service where 1=1 AND DATE_FORMAT(gansu_service.date,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d') AND status='downing'";  
  11.  $query=mysql_query($SQL);  
  12.  
  13.  
  14. $result=mysql_fetch_row($query);  
  15. if($result==''){  
  16. echo '<font size="3" color="red"><B>甘肃省份今天没有发现服务报警</B></font><br>';  
  17. }  
  18. else {  
  19.  
  20. echo '<font size="3" color="red"><B>甘肃省份今天的服务报警为:</B></font><br>';  
  21. include ("service_warning.php");  
  22. }  
  23. ?> 
  24. <? 
  25. /*检测磁盘报警  
  26.  *  
  27.  */  
  28.  $SQL="select * from gansu_disk where 1=1 AND DATE_FORMAT(gansu_disk.date,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d') AND status='abnormal'";  
  29.  $query=mysql_query($SQL);  
  30.  
  31.  
  32. $result=mysql_fetch_row($query);  
  33. if($result==''){  
  34. echo '<font size="3" color="red"><B>甘肃省份今天没有发现磁盘报警</B></font><br>';  
  35. }  
  36. else {  
  37.  
  38. echo '<font size="3" color="red"><B>甘肃省份今天的磁盘报警为:</B></font><br>';  
  39. include ("disk_warning.php");  
  40. }  
  41. ?> 
  42. <? 
  43. /*检测CPU报警  
  44.  *  
  45.  */  
  46.  $SQL="select * from gansu_cpu where 1=1 AND DATE_FORMAT(gansu_cpu.date,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d') AND status='abnormal'";  
  47.  $query=mysql_query($SQL);  
  48.  
  49.  
  50. $result=mysql_fetch_row($query);  
  51. if($result==''){  
  52. echo '<font size="3" color="red"><B>甘肃省份今天没有发现CPU报警</B></font><br>';  
  53. }  
  54. else {  
  55.  
  56. echo '<font size="3" color="red"><B>甘肃省份今天的CPU报警为:</B></font><br>';  
  57. include ("resource_warning.php");  
  58. }  
  59. ?> 
  60. <? 
  61. /*检测硬件信息错误报警  
  62.  *  
  63.  */  
  64.  $SQL="select * from gansu_hardware where 1=1 AND DATE_FORMAT(gansu_hardware.date,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d') AND status='abnormal'";  
  65.  $query=mysql_query($SQL);  
  66.  
  67.  
  68. $result=mysql_fetch_row($query);  
  69. if($result==''){  
  70. echo '<font size="3" color="red"><B>甘肃省份今天没有发现硬件信息错误(hardware)报警</B></font><br>';  
  71. }  
  72. else {  
  73.  
  74. echo '<font size="3" color="red"><B>甘肃省份今天的硬件信息错误(hardware)报警为:</B></font><br>';  
  75. include ("resource_warning.php");  
  76. }  
  77. ?> 
  78. <? 
  79. /*检测I/O报警  
  80.  *  
  81.  */  
  82.  $SQL="select * from gansu_io where 1=1 AND DATE_FORMAT(gansu_io.date,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d') AND status='abnormal'";  
  83.  $query=mysql_query($SQL);  
  84.  
  85.  
  86. $result=mysql_fetch_row($query);  
  87. if($result==''){  
  88. echo '<font size="3" color="red"><B>甘肃省份今天没有发现I/O报警</B></font><br>';  
  89. }  
  90. else {  
  91.  
  92. echo '<font size="3" color="red"><B>甘肃省份今天的I/O报警为:</B></font><br>';  
  93. include ("resource_warning.php");  
  94. }  
  95. ?> 
  96. <? 
  97. /*检测load报警  
  98.  *  
  99.  */  
  100.  $SQL="select * from gansu_load where 1=1 AND DATE_FORMAT(gansu_load.date,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d') AND status='abnormal';";  
  101.  $query=mysql_query($SQL);  
  102.  
  103. $result=mysql_fetch_row($query);  
  104. if($result==''){  
  105. echo '<font size="3" color="red"><B>甘肃省份今天没有发现负载(load)报警</B></font><br>';  
  106. }  
  107. else{  
  108. echo '<font size="3" color="red"><B>甘肃省份今天的负载(load)报警为:</B></font><br>';  
  109. include ("resource_warning.php");  
  110. }  
  111. ?> 
  112. <? 
  113. /*检测内存报警  
  114.  *  
  115.  */  
  116.  $SQL="select * from gansu_memory where 1=1 AND DATE_FORMAT(gansu_memory.date,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d') AND status='abnormal'";  
  117.  $query=mysql_query($SQL);  
  118.  
  119.  
  120. $result=mysql_fetch_row($query);  
  121. if($result==''){  
  122. echo '<font size="3" color="red"><B>甘肃省份今天没有发现内存(memory)报警</B></font><br>';  
  123. }  
  124. else {  
  125.  
  126. echo '<font size="3" color="red"><B>甘肃省份今天的内存(memory)报警为:</B></font><br>';  
  127. include ("resource_warning.php");  
  128. }  
  129. ?> 
  130. <? 
  131. /*检测日志信息报警  
  132.  *  
  133.  */  
  134.  $SQL="select * from gansu_message where 1=1 AND DATE_FORMAT(gansu_message.date,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d') AND status='abnormal'";  
  135.  $query=mysql_query($SQL);  
  136.  
  137.  
  138. $result=mysql_fetch_row($query);  
  139. if($result==''){  
  140. echo '<font size="3" color="red"><B>甘肃省份今天没有发现日志信息(message)报警</B></font><br>';  
  141. }  
  142. else {  
  143.  
  144. echo '<font size="3" color="red"><B>甘肃省份今天的日志信息(message)报警为:</B></font><br>';  
  145. include ("resource_warning.php");  
  146. }  
  147. ?> 
  148. <? 
  149. /*检测用户报警  
  150.  *  
  151.  */  
  152.  $SQL="select * from gansu_user where 1=1 AND DATE_FORMAT(gansu_user.date,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d') AND status='abnormal'";  
  153.  $query=mysql_query($SQL);  
  154.  
  155.  
  156. $result=mysql_fetch_row($query);  
  157. if($result==''){  
  158. echo '<font size="3" color="red"><B>甘肃省份今天没有发现用户登录数(user)报警</B></font><br>';  
  159. }  
  160. else {  
  161.  
  162. echo '<font size="3" color="red"><B>甘肃省份今天的用户登录数(user)报警为:</B></font><br>';  
  163. include ("resource_warning.php");  
  164. }  
  165. ?> 

此页面主要是展现甘肃省当日的服务与资源的报警。

下一篇文章地址:

运维自动化之使用PHP+MYSQL+SHELL打造私有监控系统(六)

http://dl528888.blog.51cto.com/2382721/1035297



 本文转自 reinxu 51CTO博客,原文链接:http://blog.51cto.com/dl528888/1035252,如需转载请自行联系原作者



相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
3月前
|
缓存 关系型数据库 MySQL
mysql shell如何查看服务器状态
mysql shell如何查看服务器状态
252 1
|
3月前
|
关系型数据库 MySQL PHP
|
3月前
|
缓存 运维 监控
shell监控系统状态和资源使用命令
shell监控系统状态和资源使用命令
55 2
|
3天前
|
PHP
web简易开发——通过php与HTML+css+mysql实现用户的登录,注册
web简易开发——通过php与HTML+css+mysql实现用户的登录,注册
|
2月前
|
监控 关系型数据库 MySQL
PHP与MySQL的结合:实现局域网上网行为监控软件的数据库管理
在当今信息化时代,网络安全日益成为重要的话题。为了有效监控和管理局域网上网行为,开发一个基于PHP和MySQL的数据库管理系统是一个理想的选择。本文将介绍如何结合PHP和MySQL,开发一款简单而高效的局域网上网行为监控软件,并重点关注数据库管理方面的实现。
184 0
|
3月前
|
存储 运维 Shell
Shell内置命令大全,Linux运维工程师收藏!
Shell内置命令大全,Linux运维工程师收藏!
161 0
Shell内置命令大全,Linux运维工程师收藏!
|
3月前
|
运维 Linux 网络安全
利用群晖NAS+shell脚本实现运维命令执行结果文件自动上传
利用群晖NAS+shell脚本实现运维命令执行结果文件自动上传
122 0
|
3月前
|
关系型数据库 MySQL BI
python报表自动化系列 - 通过Python使用MySQL数据库
python报表自动化系列 - 通过Python使用MySQL数据库
73 0
|
3月前
|
关系型数据库 MySQL Shell
linux shell脚本实现自动备份Mysql数据库脚本
linux shell脚本实现自动备份Mysql数据库脚本
182 3
|
3月前
|
SQL 关系型数据库 MySQL
mysql数据库备份shell
mysql数据库备份shell
24 0