免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 4541 | 回复: 17
打印 上一主题 下一主题

MRTG为交换机各端口当前流量排序scripts [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-01-31 13:47 |只看该作者 |倒序浏览
MRTG当前流量排序scripts

V1.00  Created by Thomas(2004-12-30)



前言:
  脚本在FreeBsd4.10上测试完成。于原文上的相关脚本(用于LINUX)做了相应修改。

参考:
  http://www.net130.com/2004/6-22/224959.html
          ――使用MRTG监控网络信息流量


排序脚本(加到/etc/crontab中)

  1. #!/bin/sh
  2. #  MRTGSORT
  3. #Create by Thomas 2004-12-30
  4. #Just add to the end of MRTG sentence in /etc/crontab, example:
  5. #*/5     *       *       *       *       root    /usr/local/bin/mrtg /usr/local/etc/mrtg/mrtg.cfg;/usr/local/etc/mrtg/mrtgsort.sh
  6. #
  7. #START....
  8. #
  9. >;/tmp/tmp1
  10. >;/tmp/tmp2
  11. >;/tmp/tmp3
  12. mrtgdir=/usr/local/www/data/mrtg
  13. ls $mrtgdir/1/192*html>;/tmp/tmp1
  14. ls $mrtgdir/2/192*html>;>;/tmp/tmp1
  15. for i in `cat /tmp/tmp1`
  16. do
  17.    more $i|grep TITLE>;>;/tmp/tmp2
  18.    more $i|grep % \
  19.       |cut -f4 -f5 -d" "\
  20.       |awk 'NR==3{print}NR==6{print}'\
  21.       |cut -f3 -d">;" >;>;/tmp/tmp2
  22. done
  23. more /tmp/tmp2 | awk 'NR%3==1{printf("<tr>;<td>; %s </td>;",$0)}\
  24.    NR%3==2{printf("<td>; %s </td>;",$0)}\
  25.    NR%3==0{printf("<td>; %s </td>;</tr>;\n",$0)}'\
  26.    |sed -e 's/<TITLE>;//g' -e 's:</TITLE>;::g' >;/tmp/tmp3

  27. echo -n '<HTML>;
  28. <HEAD>;
  29. <META content="TEXT/html; charset=gb2312" http-equiv=Content-Type>;
  30. </HEAD>;
  31. <BODY>;
  32. <p align=center>;<b>;Sorted by current Input. (Unit KB) </b>;</p>;
  33. <table cellSpacing=0 cellPadding=1 width=600 align=center border=1>;
  34. <tr height=30 bgcolor=#FF9900>;
  35.   <td >;
  36.   <p>;SwitchName&Port</p>;
  37.   </td>;
  38.   <td >;
  39.   <p>;InputSize</p>;
  40.   </td>;
  41.   <td >;
  42.   <p>;OutputSize</p>;
  43.   </td>;
  44. </tr>;
  45. ' >;/usr/local/www/data/mrtg/1.html

  46. echo -n '<HTML>;
  47. <HEAD>;
  48. <META content="TEXT/html; charset=gb2312" http-equiv=Content-Type>;
  49. </HEAD>;
  50. <BODY>;
  51. <p align=center>;<b>;Sorted by current Output. (Unit KB) </b>;</p>;
  52. <table cellSpacing=0 cellPadding=1 width=600 align=center border=1>;
  53. <tr height=30 bgcolor=#00FFFF>;
  54.   <td >;
  55.   <p>;SwitchName&Port</p>;
  56.   </td>;
  57.   <td >;
  58.   <p>;InputSize</p>;
  59.   </td>;
  60.   <td >;
  61.   <p>;OutputSize</p>;
  62.   </td>;
  63. </tr>;
  64. ' >;/usr/local/www/data/mrtg/2.html

  65. more /tmp/tmp3 | awk '{if ($7~/kb.*/) print}'|sort -t " " -rn +5 >;>;/usr/local/ww
  66. w/data/mrtg/1.html

  67. more /tmp/tmp3 | awk '{if ($7!~/kb.*/) print}'|sort -t " " -rn +5 >;>;/usr/local/w
  68. ww/data/mrtg/1.html

  69. more /tmp/tmp3 | awk '{if ($10~/kb.*/) print}'|sort -t " " -rn +8 >;>;/usr/local/w
  70. ww/data/mrtg/2.html

  71. more /tmp/tmp3 | awk '{if ($10!~/kb.*/) print}'|sort -t " " -rn +8 >;>;/usr/local/
  72. www/data/mrtg/2.html

  73. echo -n " </table>; \
  74. </BODY>;   \
  75. </HTML>;  \
  76. ">;>;/usr/local/www/data/mrtg/1.html
  77. echo -n " </table>; \
  78. </BODY>;   \
  79. </HTML>;  \
  80. ">;>;/usr/local/www/data/mrtg/2.html

  81. ####The End of the scripts#####

复制代码


注:
1.由“参考”中脚本生成的mrtg html放于mrtg/1、mrtg/2目录中,目的是将这些html中的当前流入流出的流量取出,再排序,加一些格式。
2./tmp/tmp1、/tmp/tmp2、/tmp/tmp3是三个临时文件,mrtg/1.html、mrtg/2.html分别放置按流入排序和流出排序。

论坛徽章:
0
2 [报告]
发表于 2005-01-31 13:49 |只看该作者

MRTG为交换机各端口当前流量排序scripts

觉得好,就帮忙顶一下啊!
顶。

论坛徽章:
0
3 [报告]
发表于 2005-01-31 16:37 |只看该作者

MRTG为交换机各端口当前流量排序scripts

555,又是一篇没人认可的:-(
一个回复也没有,555

论坛徽章:
0
4 [报告]
发表于 2005-02-01 10:27 |只看该作者

MRTG为交换机各端口当前流量排序scripts

楼主,俺小伟哥来帮你顶!!!
请问普通的TP-LING D-LING能行吗?

论坛徽章:
0
5 [报告]
发表于 2005-02-01 10:34 |只看该作者

MRTG为交换机各端口当前流量排序scripts

哦。。。。
恐怕不行。
没有管理功能,没法起snmp.

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
6 [报告]
发表于 2005-02-01 11:21 |只看该作者

MRTG为交换机各端口当前流量排序scripts

不错:)

论坛徽章:
0
7 [报告]
发表于 2005-02-01 11:40 |只看该作者

MRTG为交换机各端口当前流量排序scripts

HoHo,感谢版主鼓励~^_^~

论坛徽章:
0
8 [报告]
发表于 2005-02-01 19:38 |只看该作者

MRTG为交换机各端口当前流量排序scripts

应该将执行代码和显示或输出内容分开,这样脚本会更清晰易读

论坛徽章:
0
9 [报告]
发表于 2005-02-02 17:57 |只看该作者

MRTG为交换机各端口当前流量排序scripts

[quote]原帖由 "maozd"]应该将执行代码和显示或输出内容分开,这样脚本会更清晰易读[/quote 发表:


除非分成几个文件。。。
不过一共不够一页纸,岂不多此一举了?

论坛徽章:
0
10 [报告]
发表于 2005-02-03 09:56 |只看该作者

MRTG为交换机各端口当前流量排序scripts

可以顶,但个人认为如果在语句之间多点备注说明会使看脚本的人更明了.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP