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
- php
- include("conn.php");
- include("head.php");
- include("head_device.php");
- ?>
主要有
3个表,分别的作用为:
conn.php是连接数据库的
head.php是
php的head文件
head_device.php是设备的
head文件
B、
add_device.php
- php
- include("conn.php");
- include("head.php");
- if($_POST['submit']){
- $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]')";
- mysql_query($sql);
- echo "<script language=\"javascript\">alert('添加成功');history.go(-1)script>";
- }
- ##点击完提交后,就进行添加并返回添加成功按键
- include("head_device.php");
- ?>
- <SCRIPT language=javascript>
- function CheckPost()
- {
- if (myform.name.value=="")
- {
- alert("请填写设备名称");
- myform.name.focus();
- return false;
- }
- if (myform.ip.value.length<5)
- {
- alert("设备ip不能少于5个字符");
- myform.ip.focus();
- return false;
- }
- if (myform.mac.value.length<23)
- {
- alert("设备mac不能少于23位");
- myform.mac.focus();
- return false;
- }
- if (myform.type.value=="")
- {
- alert("请填写设备类型");
- myform.type.focus();
- return false;
- }
- if (myform.jifang_name.value=="")
- {
- alert("请填写机房名称");
- myform.jifang_name.focus();
- return false;
- }
- if (myform.raw_name.value=="")
- {
- alert("请填写机架名称");
- myform.raw_name.focus();
- return false;
- }
- if (myform.raw_location.value=="")
- {
- alert("请填写设备位置");
- myform.raw_location.focus();
- return false;
- }
- if (myform.assets_code.value=="")
- {
- alert("请填写财产编号");
- myform.assets_code.focus();
- return false;
- }
- if (myform.state.value=="")
- {
- alert("请填写设备状态");
- myform.state.focus();
- return false;
- }
- if (myform.price.value=="")
- {
- alert("请填写设备价格");
- myform.price.focus();
- return false;
- }
- }
- SCRIPT>
- ##使用javascript方式进行约束各自的值
- <form action="add_device.php" method="post" name="myform" onsubmit="return CheckPost();">
- 设备名称:<input type="text" size="10" name="name" /><br>
- 设备I P: <input type="text" size="10" name="ip" /><br/>
- 设备MAC: <input type="text" size="10" name="mac" /><br/>
- 设备类型:<input type="text" size="10" name="type" /><br/>
- 机房名称:<input type="text" size="10" name="jifang_name" /><br/>
- 机架名称:<input type="text" size="10" name="raw_name" /><br/>
- 机架位置:<input type="text" size="10" name="raw_location" /><br/>
- 财产编号:<input type="text" size="10" name="assets_code" /><br/>
- 设备状态:<input type="text" size="10"name="state" /><br/>
- 设备价格:<input type="text" size="10" name="price" /><br/>
- <input type="submit" name="submit" value="新增"/>
- <input name="reset" type="reset" value="重置" />
- form>
- ##使用html表单
C、
conn.php
- php
- $conn = @ mysql_connect("1.1.1.1", "root", "****") or die("数据库链接错误");
- mysql_select_db("monitor", $conn);
- mysql_query("set names 'GBK'"); //使用GBK中文编码;
- ##连接的数据库ip、用户名与密码,如果连接不成功,就返回数据库连接错误
- #function htmtocode($content) {
- # $content = str_replace("\n", "<br>", str_replace(" ", " ", $content));
- # return $content;
- #}
- function htmtocode($status) {
- str_replace("working", "test", $status);
- return $status;
- }
- #function
- //$content=str_replace("'","‘",$content);
- //htmlspecialchars();
- ?>
D、
gansu.php
- include("conn.php");
- include("head.php");
- include("province.php");
- ?>
- "3" color="red">应用服务
"1" cellspacing="0" >
"55">编号 "55">省份 "160">被监控服务器 "100">IP "100">监控服务器 "130">监控服务 "70">当前状态 "100">监控时间 - $SQL="SELECT * FROM `gansu_service` order by date desc limit 0,13";
- $query=mysql_query($SQL);
- while($row=mysql_fetch_array($query)){
- ?>
"1" cellspacing="0" cellpadding="0">
"55">=$row[id]?> "55">=$row[province]?> "160">=$row[server]?> "100">=$row[ip]?> "100">=$row[monitor_server]?> "130">=$row[service]?> "70">=$row[status]?> "100">=$row[date]?> - }
- ?>
- "3" color="red">硬盘使用率
"1" cellspacing="0" >
"55">编号 "55">省份 "160">被监控服务器 "100">IP "100">监控服务器 "130">监控服务 "70">阀值 "90">当期分区 "70">当前值 "70">当前状态 "100">监控时间 - $SQL="SELECT * FROM `gansu_disk` order by date desc limit 0,5";
- $query=mysql_query($SQL);
- while($row=mysql_fetch_array($query)){
- ?>
"1" cellspacing="0" cellpadding="0">
"55">=$row[id]?> "55">=$row[province]?> "160">=$row[server]?> "100">=$row[ip]?> "100">=$row[monitor_server]?> "130">=$row[service]?> "70">=$row[alert]?> "90">=$row[partition]?> "70">=$row[value]?> "70">=$row[status]?> "100">=$row[date]?> - }
- ?>
- "3" color="red">CPU使用率
"1" cellspacing="0" >
"55">编号 "55">省份 "160">被监控服务器 "100">IP "100">监控服务器 "130">监控服务 "70">阀值 "70">当前值 "70">当前状态 "100">监控时间 - $SQL="SELECT * FROM `gansu_cpu` order by date desc limit 0,5";
- $query=mysql_query($SQL);
- while($row=mysql_fetch_array($query)){
- ?>
"1" cellspacing="0" cellpadding="0">
"55">=$row[id]?> "55">=$row[province]?> "160">=$row[server]?> "100">=$row[ip]?> "100">=$row[monitor_server]?> "130">=$row[service]?> "70">=$row[alert]?> "70">=$row[value]?> "70">=$row[status]?> "100">=$row[date]?> - }
- ?>
- "3" color="red">硬件错误信息
"1" cellspacing="0" >
"55">编号 "55">省份 "160">被监控服务器 "100">IP "100">监控服务器 "130">监控服务 "70">阀值 "70">当前值 "70">当前状态 "100">监控时间 - $SQL="SELECT * FROM `gansu_hardware` order by date desc limit 0,5";
- $query=mysql_query($SQL);
- while($row=mysql_fetch_array($query)){
- ?>
"1" cellspacing="0" cellpadding="0">
"55">=$row[id]?> "55">=$row[province]?> "160">=$row[server]?> "100">=$row[ip]?> "100">=$row[monitor_server]?> "130">=$row[service]?> "70">=$row[alert]?> "70">=$row[value]?> "70">=$row[status]?> "100">=$row[date]?> - }
- ?>
- "3" color="red">I/O使用率
"1" cellspacing="0" >
"55">编号 "55">省份 "160">被监控服务器 "100">IP "100">监控服务器 "130">监控服务 "70">阀值 "70">当前值 "70">当前状态 "100">监控时间 - $SQL="SELECT * FROM `gansu_io` order by date desc limit 0,5";
- $query=mysql_query($SQL);
- while($row=mysql_fetch_array($query)){
- ?>
"1" cellspacing="0" cellpadding="0">
"55">=$row[id]?> "55">=$row[province]?> "160">=$row[server]?> "100">=$row[ip]?> "100">=$row[monitor_server]?> "130">=$row[service]?> "70">=$row[alert]?> "70">=$row[value]?> "70">=$row[status]?> "100">=$row[date]?> - }
- ?>
- "3" color="red">15分钟内的负载
"1" cellspacing="0" >
"55">编号 "55">省份 "160">被监控服务器 "100">IP "100">监控服务器 "130">监控服务 "70">阀值 "70">当前值 "70">当前状态 "100">监控时间 - $SQL="SELECT * FROM `gansu_load` order by date desc limit 0,5";
- $query=mysql_query($SQL);
- while($row=mysql_fetch_array($query)){
- ?>
"1" cellspacing="0" cellpadding="0">
"55">=$row[id]?> "55">=$row[province]?> "160">=$row[server]?> "100">=$row[ip]?> "100">=$row[monitor_server]?> "130">=$row[service]?> "70">=$row[alert]?> "70">=$row[value]?> "70">=$row[status]?> "100">=$row[date]?> - }
- ?>
- "3" color="red">内存使用率
"1" cellspacing="0" >
"55">编号 "55">省份 "160">被监控服务器 "100">IP "100">监控服务器 "130">监控服务 "70">阀值 "70">当前值 "70">当前状态 "100">监控时间 - $SQL="SELECT * FROM `gansu_memory` order by date desc limit 0,10";
- $query=mysql_query($SQL);
- while($row=mysql_fetch_array($query)){
- ?>
"1" cellspacing="0" cellpadding="0">
"55">=$row[id]?> "55">=$row[province]?> "160">=$row[server]?> "100">=$row[ip]?> "100">=$row[monitor_server]?> "130">=$row[service]?> "70">=$row[alert]?> "70">=$row[value]?> "70">=$row[status]?> "100">=$row[date]?> - }
- ?>
- "3" color="red">日志错误信息
"1" cellspacing="0" >
"55">编号 "55">省份 "160">被监控服务器 "100">IP "100">监控服务器 "130">监控服务 "70">阀值 "70">当前值 "70">当前状态 "100">监控时间 - $SQL="SELECT * FROM `gansu_message` order by date desc limit 0,5";
- $query=mysql_query($SQL);
- while($row=mysql_fetch_array($query)){
- ?>
"1" cellspacing="0" cellpadding="0">
"55">=$row[id]?> "55">=$row[province]?> "160">=$row[server]?> "100">=$row[ip]?> "100">=$row[monitor_server]?> "130">=$row[service]?> "70">=$row[alert]?> "70">=$row[value]?> "70">=$row[status]?> "100">=$row[date]?> - }
- ?>
- "3" color="red">用户登录数
"1" cellspacing="0" >
"55">编号 "55">省份 "160">被监控服务器 "100">IP "100">监控服务器 "130">监控服务 "70">阀值 "70">当前值 "70">当前状态 "100">监控时间 - $SQL="SELECT * FROM `gansu_user` order by date desc limit 0,5";
- $query=mysql_query($SQL);
- while($row=mysql_fetch_array($query)){
- ?>
"1" cellspacing="0" cellpadding="0">
"55">=$row[id]?> "55">=$row[province]?> "160">=$row[server]?> "100">=$row[ip]?> "100">=$row[monitor_server]?> "130">=$row[service]?> "70">=$row[alert]?> "70">=$row[value]?> "70">=$row[status]?> "100">=$row[date]?> - }
- ?>
此页面主要是各省展示自己的监控服务与资源详情的页面。
主要是通过从
mysql里获取各自表的数据,插入到我设定好的表单里,在web里显示,这些表单的格式都是通过css进行控制的。
E、
css.css
- td {
- line-height: 16pt;
- font-size: 10pt;
- font-family: "Verdana", "Arial", "Helvetica", "sans-serif";
- }
- a:link {
- text-decoration: none;
- color: #000000;
- }
- a:visited {
- text-decoration: none;
- color: #000000;
- }
- a:hover {
- text-decoration: underline;
- color: #FF3333;
- }
- body {
- font-size: 10pt;
- line-height: 13pt;
- background-color: #ECF5FF;
- }
- .border {
- border: 1px solid #1D5892;
- }
- textarea {
- font-size: 8pt;
- font-family: "Verdana", "Arial", "Helvetica", "sans-serif";
- border: 1px solid #999999;
- padding: 5px;
- }
- select {
- font-size: 8pt;
- padding: 1px;
- font-family: "Tahoma";
- }
- .a1:link {
- color: #FFFFFF;
- }
- .a1:visited {
- color: #FFFFFF;
- }
- .a1:hover {
- color: #FF9900;
- }
- .font14 {
- font-size: 14px;
- font-family: "Tahoma";
- }
- form {
- margin: 0px;
- padding: 0px;
- }
- .alpha {
- filter: Alpha(Opacity=20);
- }
- .filearea {
- font-size: 9pt;
- }
- .textdrow {
- color:#666666;
- filter: DropShadow(Color=white, OffX=1, OffY=1, Positive=1);
- }
- .font18 {
- font-size: 19px;
- }
- .p {
- text-indent: 24px;
- }
- .font16 {
- font-size: 16px;
- }
- .border2 {
- border: 1px solid #D5E4F4;
- }
- .xborder {
- border: 2px dotted #EBF5FE;
- }
- table {
- width: 1100px;
- }
- td {
- text-align:center;
- }
主要是观察最后
2项,是控制表的宽度与表里单元格的内容显示方法。
F、
gansu_warn.php
- php
- include ("conn.php");
- include ("head.php");
- include("warn_province.php");
- ?>
- /*检测服务报警
- *
- */
- $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'";
- $query=mysql_query($SQL);
- $result=mysql_fetch_row($query);
- if($result==''){
- echo '<font size="3" color="red"><B>甘肃省份今天没有发现服务报警B>font><br>';
- }
- else {
- echo '<font size="3" color="red"><B>甘肃省份今天的服务报警为:B>font><br>';
- include ("service_warning.php");
- }
- ?>
- /*检测磁盘报警
- *
- */
- $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'";
- $query=mysql_query($SQL);
- $result=mysql_fetch_row($query);
- if($result==''){
- echo '<font size="3" color="red"><B>甘肃省份今天没有发现磁盘报警B>font><br>';
- }
- else {
- echo '<font size="3" color="red"><B>甘肃省份今天的磁盘报警为:B>font><br>';
- include ("disk_warning.php");
- }
- ?>
- /*检测CPU报警
- *
- */
- $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'";
- $query=mysql_query($SQL);
- $result=mysql_fetch_row($query);
- if($result==''){
- echo '<font size="3" color="red"><B>甘肃省份今天没有发现CPU报警B>font><br>';
- }
- else {
- echo '<font size="3" color="red"><B>甘肃省份今天的CPU报警为:B>font><br>';
- include ("resource_warning.php");
- }
- ?>
- /*检测硬件信息错误报警
- *
- */
- $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'";
- $query=mysql_query($SQL);
- $result=mysql_fetch_row($query);
- if($result==''){
- echo '<font size="3" color="red"><B>甘肃省份今天没有发现硬件信息错误(hardware)报警B>font><br>';
- }
- else {
- echo '<font size="3" color="red"><B>甘肃省份今天的硬件信息错误(hardware)报警为:B>font><br>';
- include ("resource_warning.php");
- }
- ?>
- /*检测I/O报警
- *
- */
- $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'";
- $query=mysql_query($SQL);
- $result=mysql_fetch_row($query);
- if($result==''){
- echo '<font size="3" color="red"><B>甘肃省份今天没有发现I/O报警B>font><br>';
- }
- else {
- echo '<font size="3" color="red"><B>甘肃省份今天的I/O报警为:B>font><br>';
- include ("resource_warning.php");
- }
- ?>
- /*检测load报警
- *
- */
- $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';";
- $query=mysql_query($SQL);
- $result=mysql_fetch_row($query);
- if($result==''){
- echo '<font size="3" color="red"><B>甘肃省份今天没有发现负载(load)报警B>font><br>';
- }
- else{
- echo '<font size="3" color="red"><B>甘肃省份今天的负载(load)报警为:B>font><br>';
- include ("resource_warning.php");
- }
- ?>
- /*检测内存报警
- *
- */
- $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'";
- $query=mysql_query($SQL);
- $result=mysql_fetch_row($query);
- if($result==''){
- echo '<font size="3" color="red"><B>甘肃省份今天没有发现内存(memory)报警B>font><br>';
- }
- else {
- echo '<font size="3" color="red"><B>甘肃省份今天的内存(memory)报警为:B>font><br>';
- include ("resource_warning.php");
- }
- ?>
- /*检测日志信息报警
- *
- */
- $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'";
- $query=mysql_query($SQL);
- $result=mysql_fetch_row($query);
- if($result==''){
- echo '<font size="3" color="red"><B>甘肃省份今天没有发现日志信息(message)报警B>font><br>';
- }
- else {
- echo '<font size="3" color="red"><B>甘肃省份今天的日志信息(message)报警为:B>font><br>';
- include ("resource_warning.php");
- }
- ?>
- /*检测用户报警
- *
- */
- $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'";
- $query=mysql_query($SQL);
- $result=mysql_fetch_row($query);
- if($result==''){
- echo '<font size="3" color="red"><B>甘肃省份今天没有发现用户登录数(user)报警B>font><br>';
- }
- else {
- echo '<font size="3" color="red"><B>甘肃省份今天的用户登录数(user)报警为:B>font><br>';
- include ("resource_warning.php");
- }
- ?>
此页面主要是展现甘肃省当日的服务与资源的报警。
下一篇文章地址:
运维自动化之使用PHP+MYSQL+SHELL打造私有监控系统(六)
http://dl528888.blog.51cto.com/2382721/1035297