画IDC状态趋势图

 2023-09-15 阅读 18 评论 0

摘要:[背景]公司以前对IDC状态的测试都是通过perl+crond结合,向指定某IDC的IP发送icmp包,并将其结果保存到test.log下,对于后斯的分析,是采取手工的方式(格式化数据,结合excel),这样操作下来很浪费时间,今天我

[背景]公司以前对IDC状态的测试都是通过perl+crond结合,向指定某IDC的IP发送icmp包,并将其结果保存到test.log下,对于后斯的分析,是采取手工的方式(格式化数据,结合excel),这样操作下来很浪费时间,今天我将把昨天写的程序拿出来,来解决手工处理数据的方法,以自动画展示给大家。谢谢!~
[过程]
IDC状态报表生成的流程(历史)
ping(借助perl脚本+crond)---->test.log(生成数据)---->格式化test.log---->excel(借助模板生成趋势图)---->交任务
IDC状态报表生成的流程(现在)
ping(借助perl脚本+crond)---->test.log(生成数据)---->程序(今天写的程序)---->交任务
分析test.log
hzm,220.166.63.15,2009/6/5 22:30:0,20, 17.184,17.293,17.379, 0
hzm,220.166.63.15,2009/6/5 22:31:40,2000, 18.776,18.878,18.966, 0
hzm,220.166.63.15,2009/6/6 3:30:0,20, 17.155,17.240,17.350, 0
hzm,220.166.63.15,2009/6/6 3:31:40,2000, 18.717,18.854,18.961, 0
hzm,220.166.63.15,2009/6/6 9:0:1,20, 17.158,17.242,17.354, 0
hzm,220.166.63.15,2009/6/6 9:1:41,2000, 18.760,18.861,18.966, 0
hzm,220.166.63.15,2009/6/6 11:30:1,20, 17.199,17.277,17.481, 0
hzm,220.166.63.15,2009/6/6 11:31:41,2000, 18.678,18.874,18.970, 0
hzm,220.166.63.15,2009/6/6 15:0:0,20, 17.193,17.279,17.383, 0
hzm,220.166.63.15,2009/6/6 15:1:40,2000, 18.774,18.883,19.001, 0
hzm,220.166.63.15,2009/6/6 17:30:1,20, 17.189,17.278,17.383, 0
hzm,220.166.63.15,2009/6/6 17:31:41,2000, 18.759,18.880,19.001, 0
hzm,220.166.63.15,2009/6/6 20:30:0,20, 17.194,17.283,17.377, 0
hzm,220.166.63.15,2009/6/6 20:31:40,2000, 18.777,18.885,18.997, 0
hzm,220.166.63.15,2009/6/6 22:30:0,20, 17.205,17.289,17.378, 0
hzm,220.166.63.15,2009/6/6 22:31:40,2000, 17.718,18.886,19.004, 0
hzm,220.166.63.15,2009/6/7 3:30:0,20, 17.146,17.240,17.346, 0
hzm,220.166.63.15,2009/6/7 3:31:40,2000, 18.017,18.835,18.948, 0
.....
这是一个向220.166.63.15定点发送20,2000包大小的ICMP数据包。

来看一接口图

根据IP,包大小,来生成不同种类型的图。
看下结果
spacer.gif

接下来,就是程序部分了,请看
index.php

<html>
<head>
<title>IDC状态图</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<mce:style type="text/css"><!--
.style1 {
        font-size: 16px;
        font-weight: bold;
}
--></mce:style><style type="text/css" mce_bogus="1">.style1 {
        font-size: 16px;
        font-weight: bold;
}</style>
</head>

<body>
<?php
$i=0;
global $file_path;
$file_path ="test.log";
$fp = fopen ($file_path, "r");
while(!feof($fp)){
    $bruce=fgets($fp);
    $pieces = explode(",", $bruce);
    if(!is_null($pieces[1])){
       $ip_result[$i] = $pieces[1];
    }
    if(!is_null($pieces[3])){
       $size_result[$i]=$pieces[3];
    }
    $i++;
}
fclose($fp);
$tmp_size_result=array_keys(array_flip($size_result));
$tmp_ip_result=array_keys(array_flip($ip_result));
?>
<form name="form1" method="get" action="result.php">
  <p align="center" class="style1"> IDC状态生成图</p>
  <table width="300" border="1" align="center" cellpadding="3" cellspacing="3">
    <tr>
      <td width="85"><strong>IP:</strong></td>
<td width="188"><select name="ip" id="ip">
<?php
while (list(,$value)= each($tmp_ip_result)){
?>       
<option value=<?php echo $value ?>><?php echo $value ?></option>
<?php } ?>
      </select></td>
    </tr>
    <tr>
      <td><strong>包大小:</strong></td>
      <td>
<select name="size" id="size">
<?php while(list(,$value)=each($tmp_size_result)){ ?>
        <option value=<?php echo $value ?> ><?php echo $value ?></option>
<?php } ?>
      </select></td>
    </tr>
    <tr>
      <td><strong>图宽度:</strong></td>
      <td>
<INPUT TYPE="text" NAME="img_width">
</td>
    </tr>
<tr>
      <td><strong>文件名:</strong></td>
      <td>
<INPUT TYPE="text" NAME="file_name" value="<?php echo $file_path ?>" readonly>
</td>
    </tr>
  </table>
  <p align="center">
    <input type="submit" value="生 成">
    <input type="reset" name="Submit2" value="重 置">
  </p>
</form>
</body>
</html>

result.php

<?php
include ("../jpgraph.php");
include ("../jpgraph_line.php");

$src_ip = $_GET["ip"];
$pack_size = $_GET["size"];
$image_width = $_GET["img_width"];
$file_name =$_GET["file_name"];

$i=0;
$fp = fopen ("$file_name", "r");
while (!feof($fp))
{
    $bruce=fgets($fp);
    $pieces = explode(",", $bruce);
 if($src_ip == $pieces[1]){
    if($pieces[3]==$pack_size){
       $result_min[$i]=$pieces[4];
       $result_avg[$i]=$pieces[5];
       $result_max[$i]=$pieces[6];
       $tmp_time=explode(" ",$pieces[2]);
       $tmp1_time=explode(":",$tmp_time[1]);
       $result_time[$i]=$tmp1_time[0].":".$tmp1_time[1];
       $i++;
    }
  }
}
fclose($fp);

$graph = new Graph($image_width,300,auto);                                                                      //创建新的Graph对象
$graph->SetScale("textlin");
$graph->SetShadow();                                                                                    //设置图像的阴影样式

$graph->img->SetMargin(60,30,30,70);                                                            //设置图像边距
$graph->title->Set("IDC状态(Size=$pack_size)");                                                //设置图像标题
$graph->title->SetMargin(10);

$lineplot1=new LinePlot($result_avg);                                                                        //创建设置两条曲线对象
$lineplot2=new LinePlot($result_min);
$lineplot3=new LinePlot($result_max);

$graph->Add($lineplot1);                                                                                        //将曲线放置到图像上
$graph->Add($lineplot2);
$graph->Add($lineplot3);

$graph->xaxis->title->Set("时间段");                                                                      //设置坐标轴名称
$graph->yaxis->title->Set("Ping值");
$graph->xaxis->title->SetMargin(10);
$graph->yaxis->title->SetMargin(15);

$graph->title->SetFont(FF_SIMSUN,FS_BOLD);                                                      //设置字体
$graph->yaxis->title->SetFont(FF_SIMSUN,FS_BOLD);
$graph->xaxis->title->SetFont(FF_SIMSUN,FS_BOLD);


$graph->xaxis->SetTickLabels($result_time);

$lineplot1->SetColor("red");                                                                            //设置颜色
$lineplot2->SetColor("blue");
$lineplot3->SetColor("green");

$lineplot1->SetLegend("Avg");                                                           //设置图例名称
$lineplot2->SetLegend("Min");
$lineplot3->SetLegend("Max");

$graph->legend->SetLayout(LEGEND_HOR);                                                  //设置图例样式和位置
$graph->legend->Pos(0.5,0.96,"center","bottom");

$graph->Stroke();                                                                                               //输出图像
?>

怎么样,看得还满意吗?嗯,赶快交差喽...


如果想了解更多,请关注我们的公众号
公众号ID:opdevos
扫码关注

gongzhouhao.jpg


版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/5/56981.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息