画IDC状态趋势图

简介:
[背景]公司以前对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,包大小,来生成不同种类型的图。
看下结果


接下来,就是程序部分了,请看
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();                                                                                               //输出图像
?>

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



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

相关文章
|
存储 Kubernetes Ubuntu
使用 ezctl 工具部署和管理 Kubernetes 集群
使用 ezctl 工具部署和管理 Kubernetes 集群
1878 0
使用 ezctl 工具部署和管理 Kubernetes 集群
|
算法 定位技术
无线定位中TDOA时延估计算法matlab仿真
无线定位中TDOA时延估计算法matlab仿真
[转]2019年全国新农民新技术双创博览会汇聚创业创新最新成果
2019年全国新农民新技术创业创新博览会将于11月19日至22日在江苏省南京市举办,博览会聚焦农业农村领域最新现代信息技术、生物技术、工程技术和机械技术,集中展示“新农人”容易采用的先进实用技术。
|
云安全 安全 网络安全
|
2天前
|
JavaScript API iOS开发
DeepSeek Harness下载、安装、配置一篇搞定(2026整理,送常用插件)
DeepSeek Harness(DSH)是DeepSeek于2026年开源的MIT协议AI Agent框架,支持插件化组装模型、工具、沙箱与UI,兼容主流大模型。本文提供免Node.js的桌面端安装包(Win/macOS),含详细图文教程及热门插件推荐。
|
16天前
|
JSON 程序员 数据格式
最新版Notepad++下载、安装、配置保姆级教程(附官网安装包)
Notepad++ 是一款免费开源、轻量快速的 Windows 文本编辑器,支持多标签、语法高亮、代码折叠与宏录制,体积小、启动快、资源占用低,兼容 x64/x32/ARM 架构,是程序员和文字工作者的高效利器。
3951 1
|
9天前
|
JavaScript 安全 前端开发
Nodejs Brotli decoder 代码执行漏洞 (CVE-2026-111497)10629
Node.js发布安全更新修复Brotli解码器高危RCE漏洞(CVE-2026-111497),建议受影响版本用户立即升级。
2058 2
|
15天前
|
人工智能 API 开发工具
DeepSeek Harness 神插件:白嫖 13 家大厂模型
`dsh-our-free-model` 是 DeepSeek Harness 神级插件:零配置、零API Key、零账号,聚合13家大厂免费模型(含DeepSeek V4.1 Flash、Kimi K3等),支持本地网关、用量看板与自动降级,真正实现“白嫖即用”。
2606 46

热门文章

最新文章