用MRTG监测Linux系统-内存监控

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

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

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

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

  2)、获得内存的使用率和总量

  为了获得内存的使用量和总量我使用free -m 这个命令:

  1.   [root@intel etc]# free -m  
  2.  
  3.   total used free shared buffers cached  
  4.  
  5.   Mem: 501 454 47 0 71 234  
  6.  
  7.   -/+ buffers/cache: 148 353  
  8.  
  9.   Swap: 1019 8 1010  
  10.  

  free 命令执行后生成如上图所示的数据。我们需要的是两个带下划线的数据。其中:

  Memory 的使用情况为:454 M

  Memory 的总量为:501 M

  下面我们通过一个perl 脚本(mem.pl)来获得并输出这两个数据,脚本如下:

  1.   [root@intel bin]# vi mem.pl  
  2.  
  3.   #!/usr/bin/perl  
  4.  
  5.   system ("/usr/bin/free -m | grep Mem >mem_info_file");  
  6.  
  7.   open (MEMINFO,"mem_info_file");  
  8.  
  9.   @meminfo=;  
  10.  
  11.   close (MEMINFO);  
  12.  
  13.   foreach $line(@meminfo) {  
  14.  
  15.   @memstatus=split(/ +/,$line);  
  16.  
  17.   }  
  18.  
  19.   $memused=$memstatus[2];  
  20.  
  21.   $memtotal=$memstatus[1];  
  22.  
  23.   print "$memused\n";  
  24.  
  25.   print "$memtotal\n";  
  26.  
  27.   system ("uptime");  
  28.  
  29.   system ("uname -n");  
  30.  

  ########## By Vitter vitter@safechina.net ##################

  我同样把mem.pl 这个脚本放在/usr/local/mrtg/bin/下,这个脚本由mrtg 来调用,现在我们来完成相应的配置文件(mem.cfg),我把mem.cfg 放在/usr/local/mrtg/etc 目录下,内容如下:

  1.   [root@intel etc]# vi mem.cfg  
  2.  
  3.   WorkDir:/usr/local/apache_1.3.31/htdocs/mrtg/mem/  
  4.  
  5.   Target[localhost]: `/usr/local/mrtg/bin/mem.pl`  
  6.  
  7.   Xsize[localhost]:300  
  8.  
  9.   Ysize[localhost]:100  
  10.  
  11.   Ytics[localhost]:10  
  12.  
  13.   MaxBytes[localhost]: 1006  
  14.  
  15.   Title[localhost]:Memory State of Vitter-test Server  
  16.  
  17.   PageTop[localhost]:Memory State of Vitter-test Server  
  18.  
  19.   ShortLegend[localhost]: B  
  20.  
  21.   kmg[localhost]: M  
  22.  
  23.   YLegend[localhost]: Memory Usage  
  24.  
  25.   Legend1[localhost]: Used  
  26.  
  27.   Legend2[localhost]: Total  
  28.  
  29.   LegendI[localhost]: Used  
  30.  
  31.   LegendO[localhost]: Total  
  32.  
  33.   Options[localhost]: growright,gauge,nopercent  
  34.  

  下面我们可以执行mrtg 了:

  1.   [root@intel etc]# /usr/local/mrtg/bin/mrtg /usr/local/mrtg/etc/mem.cfg  
  2.  

  当第一次执行时会有报警,执行三次,就没有报警了。

【编辑推荐】

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

MRTG监控端的配置

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

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

2011-03-31 11:14:29

MRTG监测

2011-03-31 11:14:30

MRTG监测

2011-03-31 11:14:29

MRTG监测

2011-03-31 11:14:28

2011-04-06 11:36:30

MRTG监控内存

2011-03-30 11:30:31

MRTG

2010-06-02 11:06:15

Linux 内存监控

2011-03-30 11:31:10

MRTG

2011-03-30 11:31:10

MRTG

2011-04-01 09:18:04

mrtg流量

2011-04-02 11:40:11

mrtg监控

2011-03-30 11:34:26

流量MRTG

2011-03-30 13:29:55

MRTG

2011-03-30 13:29:49

MRTG

2011-03-30 11:31:10

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
点赞
收藏

51CTO技术栈公众号