用MRTG监测Linux系统-硬盘监控

运维 系统运维
用MRTG监测Linux系统网络、CPU、内存和硬盘情况?MRTG(Multi Router Traffic Grapher)是一个监控网络链路流量负载的工具软件,通过snmp协议得到设备的流量信息。本文讲述的是:硬盘监控

  用MRTG监测Linux系统网络、CPU、内存和硬盘情况

  本文讲述的是:用MRTG监测Linux系统网络、CPU、内存和硬盘情况:

  原理介绍MRTG安装监控CPU监控内存监控硬盘监控

  3)、获得硬盘空间总量和使用量

  用命令df -kl查看硬盘空间情况

  1.   [root@intel bin]# df -kl  
  2.  
  3.   Filesystem 1k-blocks Used Available Use% Mounted on  
  4.  
  5.   /dev/sda5 2063504 1169204 789480 60% /  
  6.  
  7.   /dev/sda1 101089 8127 87743 9% /boot  
  8.  
  9.   /dev/sda2 8262068 2324004 5518368 30% /data  
  10.  
  11.   /dev/sda7 2063504 1364412 594272 70% /home  
  12.  
  13.   /dev/sda6 2063504 1288716 669968 66% /usr  
  14.  
  15.   /dev/sda3 2063536 350040 1608672 18% /var  
  16.  
  17.   /dev/sdb1 17654736 2964312 13793600 18% /data1  
  18.  

  总量=2063504+ 101089+8262068+2063504+2063504+2063536 +17654736 =34271941

  使用量=1169204+8127+2324004+1364412+1288716+350040+2964312=9469231

  1.   [root@intel bin]# vi df.pl  
  2.  
  3.   #!/usr/bin/perl  
  4.  
  5.   # This script was written on RedHat 9.0, it assumes that the command  
  6.  
  7.   # output(df -kl) looks like this:  
  8.  
  9.   # Filesystem 1k-blocks Used Available Use% Mounted on  
  10.  
  11.   # /dev/sda5 2063504 1169204 789480 60% /  
  12.  
  13.   # /dev/sda1 101089 8127 87743 9% /boot  
  14.  
  15.   # /dev/sda2 8262068 2324004 5518368 30% /data  
  16.  
  17.   # /dev/sda7 2063504 1364412 594272 70% /home  
  18.  
  19.   # /dev/sda6 2063504 1288716 669968 66% /usr  
  20.  
  21.   # /dev/sda3 2063536 350040 1608672 18% /var  
  22.  
  23.   # /dev/sdb1 17654736 2964312 13793600 18% /data1  
  24.  
  25.   #  
  26.  
  27.   # In which case, this script returns :  
  28.  
  29.   #  
  30.  
  31.   # 34271941  
  32.  
  33.   # 9469231  
  34.  
  35.   # when run.  
  36.  
  37.   foreach $filesystem (`df -kl | grep -v "Filesystem"`)  
  38.  
  39.   {  
  40.  
  41.   @df = split(/\s+/,$filesystem);  
  42.  
  43.   $total += $df[1];  
  44.  
  45.   $usage += $df[2];  
  46.  
  47.   }  
  48.  
  49.   print "$total\n";  
  50.  
  51.   print "$usage\n";  
  52.  
  53.   system ("uptime");  
  54.  
  55.   system ("uname -n");  
  56.  

  编辑配置文件(df.cfg)

  1.   [root@intel etc]#vi df.cfg  
  2.  
  3.   WorkDir:/usr/local/apache_1.3.31/htdocs/mrtg/df/  
  4.  
  5.   Target[localhost]: `/usr/local/mrtg/bin/df.pl`  
  6.  
  7.   Xsize[localhost]:300  
  8.  
  9.   Ysize[localhost]:100  
  10.  
  11.   Ytics[localhost]:10  
  12.  
  13.   Title[localhost]: Vfocus.Net SERVER Disk Space (34,271,941 kB / 36GB) Megabytes used  
  14.  
  15.   Unscaled[localhost]: dwym  
  16.  
  17.   MaxBytes[localhost]: 34271941  
  18.  
  19.   PageTop[localhost]: Vfocus.Net SERVER Disk Space(34,271,941 kB / 36GB) Megabytes used  
  20.  
  21.   kmg[localhost]: KB,MB,GB  
  22.  
  23.   LegendI[localhost]: Total Disk Space  
  24.  
  25.   LegendO[localhost]: Used Disk Space  
  26.  
  27.   Legend1[localhost]: Total Disk Space  
  28.  
  29.   Legend2[localhost]: Used Disk Space  
  30.  
  31.   YLegend[localhost]: Megabytes  
  32.  
  33.   ShortLegend[localhost]: &  
  34.  
  35.   Options[localhost]: growright,gauge,nopercent  
  36.  
  37.   [root@intel etc]# /usr/local/mrtg/bin/mrtg /usr/local/mrtg/etc/df.cfg  
  38.  

  执行三次,就没有报警了。

  用indexmaker作index文件

  1.   [root@intel bin]# ./indexmaker --title="硬盘监控" --output=/usr/local/apache_1.3.31/htdocs/mrtg/df/index.html /usr/local/mrtg/etc/df.cfg  
  2.  
  3.   [root@intel bin]# ./indexmaker --title="CPU监控" --output=/usr/local/apache_1.3.31/htdocs/mrtg/cpu/index.html /usr/local/mrtg/etc/cpu.cfg  
  4.  
  5.   [root@intel bin]# ./indexmaker --title="内存监控" --output=/usr/local/apache_1.3.31/htdocs/mrtg/mem/index.html /usr/local/mrtg/etc/mem.cfg  
  6.  

  我们把mrtg 加入到crontab 中,让他定时执行:

  1.   */3 * * * * /usr/local/mrtg/bin/mrtg /usr/local/mrtg/etc/mem.cfg  
  2.  
  3.   */3 * * * * /usr/local/mrtg/bin/mrtg /usr/local/mrtg/etc/cpu.cfg  
  4.  
  5.   */3 * * * * /usr/local/mrtg/bin/mrtg /usr/local/mrtg/etc/net1.cfg  
  6.  
  7.   */3 * * * * /usr/local/mrtg/bin/mrtg /usr/local/mrtg/etc/df.cfg  
  8.  

  用MRTG监测Linux系统网络、CPU、内存和硬盘情况就介绍到这里了。

【编辑推荐】

用MRTG在IIS上完成入侵检测功能

MRTG监控端的配置

MRTG的网络流量监测研究与应用(应用篇)

责任编辑:zhaolei 来源: ccw
相关推荐

2011-03-31 11:14:29

MRTG监测

2011-03-31 11:20:10

MRTG监测

2011-03-31 11:14:29

MRTG监测

2011-03-31 11:14:28

2011-03-30 11:30:31

MRTG

2011-04-01 09:18:04

mrtg流量

2011-04-02 11:40:11

mrtg监控

2011-03-30 11:31:10

MRTG

2011-03-30 11:31:10

MRTG

2011-03-30 13:29:55

MRTG

2011-03-30 11:34:26

流量MRTG

2011-04-06 11:36:30

MRTG监控内存

2011-03-30 11:31:10

MRTG

2011-03-30 13:29:49

MRTG

2011-03-31 09:02:18

MRTG流量

2011-03-31 10:24:15

2011-04-06 13:50:34

LinuxMRTG监控

2010-01-27 10:01:20

2011-04-01 15:05:45

Redhat配置mrtg

2010-05-31 19:56:26

Ubuntu mrtg
点赞
收藏

51CTO技术栈公众号