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

释放双眼,带上耳机,听听看~!

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
 

  1. include("conn.php");  
  2.  include("head.php");  
  3.  include("head_device.php");  

 
?>
 

主要有
3个表,分别的作用为:

conn.php是连接数据库的

head.php是
php的head文件

head_device.php是设备的
head文件

B、
add_device.php

  1. <?

php
 

  1. include("conn.php");  
  2.  include("head.php");  
  3.  
  4.  if($_POST['submit']){  
  5.  
  6.  

  $
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]')"
;  

  1.   mysql_query($sql);  

  echo "
<
script
 
language
="javascript"

alert('添加成功');history.go(-1)
</
script

";  

  1.  
  2.  }  
  3. ##点击完提交后,就进行添加并返回添加成功按键  
  4.  include("head_device.php");  

?>
 
1.
<
SCRIPT
 
language

javascript

 

  1. function CheckPost()  
  2. {  

    if (
myform.name.value
=="")  

  1.     {  
  2.         alert("请填写设备名称");  
  3.         myform.name.focus();  
  4.         return false;  
  5.     }  

    if (myform.ip.value.length
<
5
)  

  1.     {  
  2.         alert("设备ip不能少于5个字符");  
  3.         myform.ip.focus();  
  4.         return false;  
  5.     }  

    if (myform.mac.value.length
<
23
)  

  1.     {  
  2.         alert("设备mac不能少于23位");  
  3.         myform.mac.focus();  
  4.         return false;  
  5.     }  

    if (
myform.type.value
=="")  

  1.     {  
  2.         alert("请填写设备类型");  
  3.         myform.type.focus();  
  4.         return false;  
  5.     }  

        if (
myform.jifang_name.value
=="")  

  1.     {  
  2.         alert("请填写机房名称");  
  3.         myform.jifang_name.focus();  
  4.         return false;  
  5.     }  

        if (
myform.raw_name.value
=="")  

  1.     {  
  2.         alert("请填写机架名称");  
  3.         myform.raw_name.focus();  
  4.         return false;  
  5.     }  

        if (
myform.raw_location.value
=="")  

  1.     {  
  2.         alert("请填写设备位置");  
  3.         myform.raw_location.focus();  
  4.         return false;  
  5.     }  

        if (
myform.assets_code.value
=="")  

  1.     {  
  2.         alert("请填写财产编号");  
  3.         myform.assets_code.focus();  
  4.         return false;  
  5.     }  

        if (
myform.state.value
=="")  

  1.     {  
  2.         alert("请填写设备状态");  
  3.         myform.state.focus();  
  4.         return false;  
  5.     }  

        if (
myform.price.value
=="")  

  1.     {  
  2.         alert("请填写设备价格");  
  3.         myform.price.focus();  
  4.         return false;  
  5.     }  
  6. }  

</
SCRIPT

 

  1. ##使用javascript方式进行约束各自的值  

 
<
form
 
action

"add_device.php"
 
method

"post"
 
name

"myform"
 
onsubmit

"return CheckPost();"

 
1.
 设备名称:
<
input
 
type

"text"
 
size

"10"
 
name

"name"
 
/>
<
br

 
1.
 设备I P: 
<
input
 
type

"text"
 
size

"10"
 
name

"ip"
 
/>
<
br
/>
 
1.
 设备MAC: 
<
input
 
type

"text"
 
size

"10"
 
name

"mac"
 
/>
<
br
/>
 
1.
 设备类型:
<
input
 
type

"text"
 
size

"10"
 
name

"type"
 
/>
<
br
/>
 
1.
  机房名称:
<
input
 
type

"text"
 
size

"10"
 
name

"jifang_name"
 
/>
<
br
/>
 
1.
  机架名称:
<
input
 
type

"text"
 
size

"10"
 
name

"raw_name"
 
/>
<
br
/>
 
1.
  机架位置:
<
input
 
type

"text"
 
size

"10"
 
name

"raw_location"
 
/>
<
br
/>
 
1.
 财产编号:
<
input
 
type

"text"
 
size

"10"
 
name

"assets_code"
 
/>
<
br
/>
 
1.
 设备状态:
<
input
 
type

"text"
 
size
="10"
name
="state" 
/>
<
br
/>
 
1.
 设备价格:
<
input
 
type

"text"
 
size

"10"
 
name

"price"
 
/>
<
br
/>
 
1.
 
<
input
 
type

"submit"
 
name

"submit"
 
value

"新增"
/>
 
1.
 
<
input
 
name

"reset"
 
type

"reset"
 
value

"重置"
 
/>
 
1.
 
</
form

 

  1. ##使用html表单  

C、
conn.php

  1. <?

php
 
1.
$
conn
 = @ mysql_connect("1.1.1.1", "root", "****") or die("数据库链接错误");  

  1. mysql_select_db("monitor", $conn);  
  2. mysql_query("set names 'GBK'"); //使用GBK中文编码;  
  3. ##连接的数据库ip、用户名与密码,如果连接不成功,就返回数据库连接错误  
  4. #function htmtocode($content) {  

#   $
content
 = 
str_replace
("\n", "
<
br

", str_replace(" ", " ", $content));  

  1. #   return $content;  
  2. #}  
  3.  
  4. function htmtocode($status) {  
  5. str_replace("working", "test", $status);  
  6.  
  7.     return $status;  
  8. }  
  9. #function  

//$
content

str_replace
("'","‘",$content);  

  1.  //htmlspecialchars();  
  2.  

?>
 

D、
gansu.php

  1. <?php  

include(
"conn.php"
);  
1.
include(
"head.php"
);  
1.
include(
"province.php"
);  

  1. ?>  

 <font size=
"3"
 color=
"red"

<B>应用服务</B></font>  

  1.  

 <table border=
"1"
 cellspacing=
"0"
 >  

  1.     <tr>  

    <th width=
"55"

编号</th>  

    <th width=
"55"

省份</th>  

    <th width=
"160"

被监控服务器</th>  

    <th width=
"100"

IP</th>  

    <th width=
"100"

监控服务器</th>  

    <th width=
"130"

监控服务</th>  

    <th width=
"70"

当前状态</th>  

    <th width=
"100"

监控时间</th>  

  1.   </tr>  
  2.   </table>  
  3. <?  
  4.  

 $SQL=
"SELECT * FROM 

1
1`

gansu_service

1
1`

 order by date desc limit 0,13"
;  

  1.   $query=mysql_query($SQL);  

  
while
($row=mysql_fetch_array($query)){  

  1. ?>  

<table border=
"1"
 cellspacing=
"0"
 cellpadding=
"0"

 

  1.   <tr>  

    <td width=
"55"

<?=$row[id]?> </td>  

    <td width=
"55"

<?=$row[province]?></td>  

    <td width=
"160"

<?=$row[server]?> </td>  

    <td width=
"100"

<?=$row[ip]?></td>  

    <td width=
"100"

<?=$row[monitor_server]?></td>  

    <td width=
"130"

<?=$row[service]?></td>  

    <td width=
"70"

<?=$row[status]?></td>  

    <td width=
"100"

<?=$row[date]?></td>  

  1.   </tr>  
  2.  
  3. </table>  
  4. <?  
  5.   }  
  6. ?>  

<font size=
"3"
 color=
"red"

<B>硬盘使用率</B></font>  

 <table border=
"1"
 cellspacing=
"0"
 >  

  1.     <tr>  

    <th width=
"55"

编号</th>  

    <th width=
"55"

省份</th>  

    <th width=
"160"

被监控服务器</th>  

    <th width=
"100"

IP</th>  

    <th width=
"100"

监控服务器</th>  

    <th width=
"130"

监控服务</th>  

    <th width=
"70"

阀值</th>  

    <th width=
"90"

当期分区</th>  

    <th width=
"70"

当前值</th>  

    <th width=
"70"

当前状态</th>  

    <th width=
"100"

监控时间</th>  

  1.   </tr>  
  2.   </table>  
  3. <?  

 $SQL=
"SELECT * FROM 

1
1`

gansu_disk

1
1`

 order by date desc limit 0,5"
;  

  1.   $query=mysql_query($SQL);  

  
while
($row=mysql_fetch_array($query)){  

  1. ?>  

  <table border=
"1"
 cellspacing=
"0"
 cellpadding=
"0"

 

  1.   <tr>  

    <td width=
"55"

<?=$row[id]?> </td>  

    <td width=
"55"

<?=$row[province]?></td>  

    <td width=
"160"

<?=$row[server]?> </td>  

    <td width=
"100"

<?=$row[ip]?></td>  

    <td width=
"100"

<?=$row[monitor_server]?></td>  

    <td width=
"130"

<?=$row[service]?></td>  

    <td width=
"70"

<?=$row[alert]?></td>  

    <td width=
"90"

<?=$row[partition]?></td>  

    <td width=
"70"

<?=$row[value]?></td>  

    <td width=
"70"

<?=$row[status]?></td>  

    <td width=
"100"

<?=$row[date]?></td>  

  1.   </tr>  
  2.  
  3. </table>  
  4. <?  
  5.   }  
  6. ?>  

<font size=
"3"
 color=
"red"

<B>CPU使用率</B></font>  

 <table border=
"1"
 cellspacing=
"0"
 >  

  1.     <tr>  

    <th width=
"55"

编号</th>  

    <th width=
"55"

省份</th>  

    <th width=
"160"

被监控服务器</th>  

    <th width=
"100"

IP</th>  

    <th width=
"100"

监控服务器</th>  

    <th width=
"130"

监控服务</th>  

    <th width=
"70"

阀值</th>  

    <th width=
"70"

当前值</th>  

    <th width=
"70"

当前状态</th>  

    <th width=
"100"

监控时间</th>  

  1.   </tr>  
  2.   </table>  
  3. <?  

 $SQL=
"SELECT * FROM 

1
1`

gansu_cpu

1
1`

 order by date desc limit 0,5"
;  

  1.   $query=mysql_query($SQL);  

  
while
($row=mysql_fetch_array($query)){  

  1. ?>  

<table border=
"1"
 cellspacing=
"0"
 cellpadding=
"0"

 

  1.   <tr>  

    <td width=
"55"

<?=$row[id]?> </td>  

    <td width=
"55"

<?=$row[province]?></td>  

    <td width=
"160"

<?=$row[server]?> </td>  

    <td width=
"100"

<?=$row[ip]?></td>  

    <td width=
"100"

<?=$row[monitor_server]?></td>  

    <td width=
"130"

<?=$row[service]?></td>  

    <td width=
"70"

<?=$row[alert]?></td>  

    <td width=
"70"

<?=$row[value]?></td>  

    <td width=
"70"

<?=$row[status]?></td>  

    <td width=
"100"

<?=$row[date]?></td>  

  1.   </tr>  
  2.  
  3. </table>  
  4. <?  
  5.   }  
  6. ?>  
  7.  
  8.  

<font size=
"3"
 color=
"red"

<B>硬件错误信息</B></font>  

 <table border=
"1"
 cellspacing=
"0"
 >  

  1.     <tr>  

    <th width=
"55"

编号</th>  

    <th width=
"55"

省份</th>  

    <th width=
"160"

被监控服务器</th>  

    <th width=
"100"

IP</th>  

    <th width=
"100"

监控服务器</th>  

    <th width=
"130"

监控服务</th>  

    <th width=
"70"

阀值</th>  

    <th width=
"70"

当前值</th>  

    <th width=
"70"

当前状态</th>  

    <th width=
"100"

监控时间</th>  

  1.   </tr>  
  2.   </table>  
  3. <?  

 $SQL=
"SELECT * FROM 

1
1`

gansu_hardware

1
1`

 order by date desc limit 0,5"
;  

  1.   $query=mysql_query($SQL);  

  
while
($row=mysql_fetch_array($query)){  

  1. ?>  

<table border=
"1"
 cellspacing=
"0"
 cellpadding=
"0"

 

  1.   <tr>  

    <td width=
"55"

<?=$row[id]?> </td>  

    <td width=
"55"

<?=$row[province]?></td>  

    <td width=
"160"

<?=$row[server]?> </td>  

    <td width=
"100"

<?=$row[ip]?></td>  

    <td width=
"100"

<?=$row[monitor_server]?></td>  

    <td width=
"130"

<?=$row[service]?></td>  

    <td width=
"70"

<?=$row[alert]?></td>  

    <td width=
"70"

<?=$row[value]?></td>  

    <td width=
"70"

<?=$row[status]?></td>  

    <td width=
"100"

<?=$row[date]?></td>  

  1.   </tr>  
  2.  
  3. </table>  
  4. <?  
  5.   }  
  6. ?>  
  7.  

<font size=
"3"
 color=
"red"

<B>I/O使用率</B></font>  

 <table border=
"1"
 cellspacing=
"0"
 >  

  1.     <tr>  

    <th width=
"55"

编号</th>  

    <th width=
"55"

省份</th>  

    <th width=
"160"

被监控服务器</th>  

    <th width=
"100"

IP</th>  

    <th width=
"100"

监控服务器</th>  

    <th width=
"130"

监控服务</th>  

    <th width=
"70"

阀值</th>  

    <th width=
"70"

当前值</th>  

    <th width=
"70"

当前状态</th>  

    <th width=
"100"

监控时间</th>  

  1.   </tr>  
  2.   </table>  
  3. <?  

 $SQL=
"SELECT * FROM 

1
1`

gansu_io

1
1`

 order by date desc limit 0,5"
;  

  1.   $query=mysql_query($SQL);  

  
while
($row=mysql_fetch_array($query)){  

  1. ?>  

<table border=
"1"
 cellspacing=
"0"
 cellpadding=
"0"

 

  1.   <tr>  

    <td width=
"55"

<?=$row[id]?> </td>  

    <td width=
"55"

<?=$row[province]?></td>  

    <td width=
"160"

<?=$row[server]?> </td>  

    <td width=
"100"

<?=$row[ip]?></td>  

    <td width=
"100"

<?=$row[monitor_server]?></td>  

    <td width=
"130"

<?=$row[service]?></td>  

    <td width=
"70"

<?=$row[alert]?></td>  

    <td width=
"70"

<?=$row[value]?></td>  

    <td width=
"70"

<?=$row[status]?></td>  

    <td width=
"100"

<?=$row[date]?></td>  

  1.   </tr>  
  2.  
  3. </table>  
  4. <?  
  5.   }  
  6. ?>  
  7.  

<font size=
"3"
 color=
"red"

<B>15分钟内的负载</B></font>  

 <table border=
"1"
 cellspacing=
"0"
 >  

  1.     <tr>  

    <th width=
"55"

编号</th>  

    <th width=
"55"

省份</th>  

    <th width=
"160"

被监控服务器</th>  

    <th width=
"100"

IP</th>  

    <th width=
"100"

监控服务器</th>  

    <th width=
"130"

监控服务</th>  

    <th width=
"70"

阀值</th>  

    <th width=
"70"

当前值</th>  

    <th width=
"70"

当前状态</th>  

    <th width=
"100"

监控时间</th>  

  1.   </tr>  
  2.   </table>  
  3. <?  

 $SQL=
"SELECT * FROM 

1
1`

gansu_load

1
1`

 order by date desc limit 0,5"
;  

  1.   $query=mysql_query($SQL);  

  
while
($row=mysql_fetch_array($query)){  

  1. ?>  

  <table border=
"1"
 cellspacing=
"0"
 cellpadding=
"0"

 

  1.   <tr>  

    <td width=
"55"

<?=$row[id]?> </td>  

    <td width=
"55"

<?=$row[province]?></td>  

    <td width=
"160"

<?=$row[server]?> </td>  

    <td width=
"100"

<?=$row[ip]?></td>  

    <td width=
"100"

<?=$row[monitor_server]?></td>  

    <td width=
"130"

<?=$row[service]?></td>  

    <td width=
"70"

<?=$row[alert]?></td>  

    <td width=
"70"

<?=$row[value]?></td>  

    <td width=
"70"

<?=$row[status]?></td>  

    <td width=
"100"

<?=$row[date]?></td>  

  1.   </tr>  
  2.  
  3.  
  4. </table>  
  5. <?  
  6.   }  
  7. ?>  
  8.  

<font size=
"3"
 color=
"red"

<B>内存使用率</B></font>  

 <table border=
"1"
 cellspacing=
"0"
 >  

  1.     <tr>  

    <th width=
"55"

编号</th>  

    <th width=
"55"

省份</th>  

    <th width=
"160"

被监控服务器</th>  

    <th width=
"100"

IP</th>  

    <th width=
"100"

监控服务器</th>  

    <th width=
"130"

监控服务</th>  

    <th width=
"70"

阀值</th>  

    <th width=
"70"

当前值</th>  

    <th width=
"70"

当前状态</th>  

    <th width=
"100"

监控时间</th>  

  1.   </tr>  
  2.   </table>  
  3. <?  

 $SQL=
"SELECT * FROM 

1
1`

gansu_memory

1
1`

 order by date desc limit 0,10"
;  

  1.   $query=mysql_query($SQL);  

  
while
($row=mysql_fetch_array($query)){  

  1. ?>  

<table border=
"1"
 cellspacing=
"0"
 cellpadding=
"0"

 

  1.   <tr>  

    <td width=
"55"

<?=$row[id]?> </td>  

    <td width=
"55"

<?=$row[province]?></td>  

    <td width=
"160"

<?=$row[server]?> </td>  

    <td width=
"100"

<?=$row[ip]?></td>  

    <td width=
"100"

<?=$row[monitor_server]?></td>  

    <td width=
"130"

<?=$row[service]?></td>  

    <td width=
"70"

<?=$row[alert]?></td>  

    <td width=
"70"

<?=$row[value]?></td>  

    <td width=
"70"

<?=$row[status]?></td>  

    <td width=
"100"

<?=$row[date]?></td>  

  1.   </tr>  
  2.  
  3. </table>  
  4. <?  
  5.   }  
  6. ?>  
  7.  

<font size=
"3"
 color=
"red"

<B>日志错误信息</B></font>  

 <table border=
"1"
 cellspacing=
"0"
 >  

  1.     <tr>  

    <th width=
"55"

编号</th>  

    <th width=
"55"

省份</th>  

    <th width=
"160"

被监控服务器</th>  

    <th width=
"100"

IP</th>  

    <th width=
"100"

监控服务器</th>  

    <th width=
"130"

监控服务</th>  

    <th width=
"70"

阀值</th>  

    <th width=
"70"

当前值</th>  

    <th width=
"70"

当前状态</th>  

    <th width=
"100"

监控时间</th>  

  1.   </tr>  
  2.   </table>  
  3.  
  4. <?  

 $SQL=
"SELECT * FROM 

1
1`

gansu_message

1
1`

 order by date desc limit 0,5"
;  

  1.   $query=mysql_query($SQL);  

  
while
($row=mysql_fetch_array($query)){  

  1. ?>  

 <table border=
"1"
 cellspacing=
"0"
 cellpadding=
"0"

 

  1.   <tr>  

    <td width=
"55"

<?=$row[id]?> </td>  

    <td width=
"55"

<?=$row[province]?></td>  

    <td width=
"160"

<?=$row[server]?> </td>  

    <td width=
"100"

<?=$row[ip]?></td>  

    <td width=
"100"

<?=$row[monitor_server]?></td>  

    <td width=
"130"

<?=$row[service]?></td>  

    <td width=
"70"

<?=$row[alert]?></td>  

    <td width=
"70"

<?=$row[value]?></td>  

    <td width=
"70"

<?=$row[status]?></td>  

    <td width=
"100"

<?=$row[date]?></td>  

  1.   </tr>  
  2.  
  3. </table>  
  4. <?  
  5.   }  
  6. ?>  
  7.  

<font size=
"3"
 color=
"red"

<B>用户登录数</B></font>  

 <table border=
"1"
 cellspacing=
"0"
 >  

  1.     <tr>  

    <th width=
"55"

编号</th>  

    <th width=
"55"

省份</th>  

    <th width=
"160"

被监控服务器</th>  

    <th width=
"100"

IP</th>  

    <th width=
"100"

监控服务器</th>  

    <th width=
"130"

监控服务</th>  

    <th width=
"70"

阀值</th>  

    <th width=
"70"

当前值</th>  

    <th width=
"70"

当前状态</th>  

    <th width=
"100"

监控时间</th>  

  1.   </tr>  
  2.   </table>  
  3. <?  

 $SQL=
"SELECT * FROM 

1
1`

gansu_user

1
1`

 order by date desc limit 0,5"
;  

  1.   $query=mysql_query($SQL);  

  
while
($row=mysql_fetch_array($query)){  

  1. ?>  
  2.  

<table border=
"1"
 cellspacing=
"0"
 cellpadding=
"0"

 

  1.   <tr>  

    <td width=
"55"

<?=$row[id]?> </td>  

    <td width=
"55"

<?=$row[province]?></td>  

    <td width=
"160"

<?=$row[server]?> </td>  

    <td width=
"100"

<?=$row[ip]?></td>  

    <td width=
"100"

<?=$row[monitor_server]?></td>  

    <td width=
"130"

<?=$row[service]?></td>  

    <td width=
"70"

<?=$row[alert]?></td>  

    <td width=
"70"

<?=$row[value]?></td>  

    <td width=
"70"

<?=$row[status]?></td>  

    <td width=
"100"

<?=$row[date]?></td>  

  1.   </tr>  
  2.  
  3. </table>  
  4. <?  
  5.   }  
  6. ?>  

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

主要是通过从
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 {  

    filter: Alpha(
Opacity

20
);  

  1. }  
  2. .filearea {  
  3.     font-size: 9pt;  
  4. }  
  5. .textdrow {  
  6.     color:#666666;  

    filter: DropShadow(
Color

white

OffX

1

OffY

1

Positive

1
);  

  1. }  
  2. .font18 {  
  3.     font-size: 19px;  
  4. }  
  5. .p {  
  6.     text-indent: 24px;  
  7. }  
  8. .font16 {  
  9.     font-size: 16px;  
  10. }  
  11. .border2 {  
  12.     border: 1px solid #D5E4F4;  
  13. }  
  14. .xborder {  
  15.     border: 2px dotted #EBF5FE;  
  16. }  
  17. table {  
  18. width: 1100px;  
  19. }  
  20.  
  21. td {  
  22. text-align:center;  
  23. }  

主要是观察最后
2项,是控制表的宽度与表里单元格的内容显示方法。

F、
gansu_warn.php

  1. <?

php
 

  1. include ("conn.php");  
  2. include ("head.php");  
  3. include("warn_province.php");  

?>
 
1.

<?
 
1. /\*检测服务报警  
1.  \*  
1.  \*/  
1.
 $
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'"
;  
1.
 $
query
=
mysql_query
($SQL);  
1.  
1.  
1.
$
result
=
mysql_fetch_row
($query);  
1.
if($
result
==''){  
1.
echo '
<
font
 
size
=
"3"
 
color
=
"red"
>
<
B
>
甘肃省份今天没有发现服务报警
</
B
>
</
font
>
<
br
>
';  
1. }  
1. else {  
1.  
1.
echo '
<
font
 
size
=
"3"
 
color
=
"red"
>
<
B
>
甘肃省份今天的服务报警为:
</
B
>
</
font
>
<
br
>
';  
1. include ("service_warning.php");  
1. }  
1.
?>

 
1.

<?
 
1. /\*检测磁盘报警  
1.  \*  
1.  \*/  
1.
 $
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'"
;  
1.
 $
query
=
mysql_query
($SQL);  
1.  
1.  
1.
$
result
=
mysql_fetch_row
($query);  
1.
if($
result
==''){  
1.
echo '
<
font
 
size
=
"3"
 
color
=
"red"
>
<
B
>
甘肃省份今天没有发现磁盘报警
</
B
>
</
font
>
<
br
>
';  
1. }  
1. else {  
1.  
1.
echo '
<
font
 
size
=
"3"
 
color
=
"red"
>
<
B
>
甘肃省份今天的磁盘报警为:
</
B
>
</
font
>
<
br
>
';  
1. include ("disk_warning.php");  
1. }  
1.
?>

 
1.

<?
 
1. /\*检测CPU报警  
1.  \*  
1.  \*/  
1.
 $
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'"
;  
1.
 $
query
=
mysql_query
($SQL);  
1.  
1.  
1.
$
result
=
mysql_fetch_row
($query);  
1.
if($
result
==''){  
1.
echo '
<
font
 
size
=
"3"
 
color
=
"red"
>
<
B
>
甘肃省份今天没有发现CPU报警
</
B
>
</
font
>
<
br
>
';  
1. }  
1. else {  
1.  
1.
echo '
<
font
 
size
=
"3"
 
color
=
"red"
>
<
B
>
甘肃省份今天的CPU报警为:
</
B
>
</
font
>
<
br
>
';  
1. include ("resource_warning.php");  
1. }  
1.
?>

 
1.

<?
 
1. /\*检测硬件信息错误报警  
1.  \*  
1.  \*/  
1.
 $
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'"
;  
1.
 $
query
=
mysql_query
($SQL);  
1.  
1.  
1.
$
result
=
mysql_fetch_row
($query);  
1.
if($
result
==''){  
1.
echo '
<
font
 
size
=
"3"
 
color
=
"red"
>
<
B
>
甘肃省份今天没有发现硬件信息错误(hardware)报警
</
B
>
</
font
>
<
br
>
';  
1. }  
1. else {  
1.  
1.
echo '
<
font
 
size
=
"3"
 
color
=
"red"
>
<
B
>
甘肃省份今天的硬件信息错误(hardware)报警为:
</
B
>
</
font
>
<
br
>
';  
1. include ("resource_warning.php");  
1. }  
1.
?>

 
1.

<?
 
1. /\*检测I/O报警  
1.  \*  
1.  \*/  
1.
 $
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'"
;  
1.
 $
query
=
mysql_query
($SQL);  
1.  
1.  
1.
$
result
=
mysql_fetch_row
($query);  
1.
if($
result
==''){  
1.
echo '
<
font
 
size
=
"3"
 
color
=
"red"
>
<
B
>
甘肃省份今天没有发现I/O报警
</
B
>
</
font
>
<
br
>
';  
1. }  
1. else {  
1.  
1.
echo '
<
font
 
size
=
"3"
 
color
=
"red"
>
<
B
>
甘肃省份今天的I/O报警为:
</
B
>
</
font
>
<
br
>
';  
1. include ("resource_warning.php");  
1. }  
1.
?>

 
1.

<?
 
1. /\*检测load报警  
1.  \*  
1.  \*/  
1.
 $
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';"
;  
1.
 $
query
=
mysql_query
($SQL);  
1.  
1.
$
result
=
mysql_fetch_row
($query);  
1.
if($
result
==''){  
1.
echo '
<
font
 
size
=
"3"
 
color
=
"red"
>
<
B
>
甘肃省份今天没有发现负载(load)报警
</
B
>
</
font
>
<
br
>
';  
1. }  
1. else{  
1.
echo '
<
font
 
size
=
"3"
 
color
=
"red"
>
<
B
>
甘肃省份今天的负载(load)报警为:
</
B
>
</
font
>
<
br
>
';  
1. include ("resource_warning.php");  
1. }  
1.
?>

 
1.

<?
 
1. /\*检测内存报警  
1.  \*  
1.  \*/  
1.
 $
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'"
;  
1.
 $
query
=
mysql_query
($SQL);  
1.  
1.  
1.
$
result
=
mysql_fetch_row
($query);  
1.
if($
result
==''){  
1.
echo '
<
font
 
size
=
"3"
 
color
=
"red"
>
<
B
>
甘肃省份今天没有发现内存(memory)报警
</
B
>
</
font
>
<
br
>
';  
1. }  
1. else {  
1.  
1.
echo '
<
font
 
size
=
"3"
 
color
=
"red"
>
<
B
>
甘肃省份今天的内存(memory)报警为:
</
B
>
</
font
>
<
br
>
';  
1. include ("resource_warning.php");  
1. }  
1.
?>

 
1.

<?
 
1. /\*检测日志信息报警  
1.  \*  
1.  \*/  
1.
 $
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'"
;  
1.
 $
query
=
mysql_query
($SQL);  
1.  
1.  
1.
$
result
=
mysql_fetch_row
($query);  
1.
if($
result
==''){  
1.
echo '
<
font
 
size
=
"3"
 
color
=
"red"
>
<
B
>
甘肃省份今天没有发现日志信息(message)报警
</
B
>
</
font
>
<
br
>
';  
1. }  
1. else {  
1.  
1.
echo '
<
font
 
size
=
"3"
 
color
=
"red"
>
<
B
>
甘肃省份今天的日志信息(message)报警为:
</
B
>
</
font
>
<
br
>
';  
1. include ("resource_warning.php");  
1. }  
1.
?>

 
1.

<?
 
1. /\*检测用户报警  
1.  \*  
1.  \*/  
1.
 $
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'"
;  
1.
 $
query
=
mysql_query
($SQL);  
1.  
1.  
1.
$
result
=
mysql_fetch_row
($query);  
1.
if($
result
==''){  
1.
echo '
<
font
 
size
=
"3"
 
color
=
"red"
>
<
B
>
甘肃省份今天没有发现用户登录数(user)报警
</
B
>
</
font
>
<
br
>
';  
1. }  
1. else {  
1.  
1.
echo '
<
font
 
size
=
"3"
 
color
=
"red"
>
<
B
>
甘肃省份今天的用户登录数(user)报警为:
</
B
>
</
font
>
<
br
>
';  
1. include ("resource_warning.php");  
1. }  
1.
?>

 

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

下一篇文章地址:

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

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

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

给TA打赏
共{{data.count}}人
人已打赏
安全技术安全运维

Windows服务器如何发现被黑

2018-5-20 12:24:31

安全技术

详解Node.js API系列 Crypto加密模块(2) Hmac

2021-12-21 16:36:11

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索