[linux服务器]使用snmp+mrtg监控CPU、流量、磁盘空间、内存

2012-11-05 14:25:39 8 3333


1、 安装snmp

yum install net-snmp* -y


2、 修改/etc/snmpd.conf(可直接清空内容)

① 增加 rocommunity public

②   找到disk修改(df –k查看)可以有多个,看情况

     disk    /   $size      

disk    /boot   $size1

[disk    /home  $size2…]

3、 启动

/etc/init.d/snmpd restart


4、 安装mrtg

yum install mrtg* -y


5将以下内容写到/etc/mrtg/mrtg.cfg,直接覆盖(红色部分需更改)

############################################################

# Multi Router Traffic Grapher -- Example Configuration File

############################################################

#

#Minimal mrtg.cfg


HtmlDir: /var/www/mrtg

ImageDir: /var/www/mrtg

LogDir: /var/lib/mrtg

ThreshDir: /var/lib/mrtg


#####################################################

#moniting LAN interface

#####################################################

Target[eth1_lan]: /10.0.0.99:public@localhost:             //IP与主机名

Options[eth1_lan]: growright

Directory[eth1_lan]: eth1                                 //网络连接名称

MaxBytes[eth1_lan]: 100000000

Kmg[eth1_lan]: K,M,G

YLegend[eth1_lan]: Bytes per Second

ShortLegend[eth1_lan]: B/s

Legend1[eth1_lan]: 每秒流入量 (单位 Bytes)

Legend2[eth1_lan]: 每秒流出量 (单位 Bytes)

LegendI[eth1_lan]: 流入:

LegendO[eth1_lan]: 流出:

Title[eth1_lan]: eth1网络流量[流入+流出]

PageTop[eth1_lan]: <h1>eth1网络流量[流入+流出]</h1>


###################################################

#Moniting CPU Load[use+free]

###################################################


Target[cpuload]: .1.3.6.1.4.1.2021.11.50.0&.1.3.6.1.4.1.2021.11.53.0:public@localhost:

Options[cpuload]: nopercent,growright

Directory[cpuload]: cpu

MaxBytes[cpuload]: 100

Unscaled[cpuload]: dwym

YLegend[cpuload]: CPU Utilization

ShortLegend[cpuload]: %

Legend1[cpuload]: CPU使用负载(%)

Legend2[cpuload]: CPU闲置(%)

LegendI[cpuload]: 使用:

LegendO[cpuload]: 闲置:

Title[cpuload]: CPU负载[使用+闲置]

PageTop[cpuload]: <h1>CPU负载[使用+闲置]</h1>



###################################################

#Moniting Used memory and Swap [Mem+Swap] free -k

###################################################


Target[memory]: .1.3.6.1.2.1.25.2.3.1.6.1&.1.3.6.1.2.1.25.2.3.1.6.3:public@localhost:

Options[memory]: gauge,growright

Directory[memory]: mem

MaxBytes1[memory]: 327252

MaxBytes2[memory]: 1023992                           //内存

#MaxBytesX[memory]: 1023992可多个,看情况

Kmg[memory]: K,M,G

Kilo[memory]: 1024

Unscaled[memory]: dwym

YLegend[memory]: Mem Bytes

ShortLegend[memory]: B

Legend1[memory]: 已用Mem(Bytes)

Legend2[memory]: 已用Swap(Bytes)

LegendI[memory]: 已用Mem :

LegendO[memory]: 已用Swap:

Title[memory]: 内存使用量[Mem+Swap]

PageTop[memory]: <h1>内存使用量[Mem+Swap]</h1>


###################################################

#Moniting disk size [/+/boot]
df -k

###################################################


Target[disk]: .1.3.6.1.4.1.2021.9.1.8.1&.1.3.6.1.4.1.2021.9.1.8.2:public@localhost:

Options[disk]: gauge,growright

Directory[disk]: disk

MaxBytes1[disk]: 11087104

MaxBytes2[disk]: 495844

Kmg[disk]: K,M,G

Kilo[disk]: 1024

Unscaled[disk]: dwym

YLegend[disk]: Disk Bytes

ShortLegend[disk]: B

Legend1[disk]: 根分区已用空间

Legend2[disk]: boot分区已用空间

LegendI[disk]: 根分区已用 :

LegendO[disk]: boot分区已用:

Title[disk]: 硬盘空间[根分区+boot分区]

PageTop[disk]: <h1>硬盘空间[根分区+boot分区]</h1>



6、
cp /etc/cron.d/mrtg /etc/mrtg/

7、vi /etc/mrtg/mrtg,改为以下内容:


#!/bin/bashLANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok
8、执行3次
/etc/mrtg/mrtg/etc/mrtg/mrtg/etc/mrtg/mrtg

9、执行



Indexmaker --output /var/www/mrtg/index.html –title=”System state Monitor” /etc/mrtg/mrtg.cfg

10、修改apache配置文件httpd.conf


Alias /mrtg "/var/www/mrtg"<Directory "/var/www/mrtg">
Options indexes
AllowOverride None
Order deny,allow
Deny from all
Allow from all</Directory

>

11、重启httpd

12、访问http://localhost/mrtg/

13、如出现乱码,则改变编码



原文:http://my.oschina.net/pero/blog/86883

关于作者

ty4z2008105篇文章2002篇回复湖南理工学院 学生

禁止发言

评论8次

要评论?请先  登录  或  注册
  • 8楼
    2013-1-28 21:00

    nagios报警好,cacti的图形好。

  • 7楼
    2012-12-31 09:17

    nagios真心比cacti好用。。就报警这一块来说。。

  • 6楼
    2012-12-28 21:56

    亲,莫非我孤陋寡闻,我记得有一个叫做nagios的,也是监控的,用着虽然界面不是太好看,不过功能不错。 MRTG监控网络设备不错的,例如出口路由流量,核心交换机当前负载等。。。

  • 5楼
    2012-12-12 17:16

    呃,对Zabbix比较深入一些,以前也用过cacti,但是被动式的监控,当主机数量越来越庞大就不行了,还是得靠Zabbix

  • 4楼
    2012-11-5 22:39

    老觉得有点山寨。。

  • 3楼
    2012-11-5 16:42

    以前本地测试过 还不错,

  • 2楼
    2012-11-5 14:43

    多,确实很多,但是网络监控的好像不多;nginx只有网络流量监控,而且文字很不方便。它主要还是status模块的作用,当然可以再次自己开发 PS: 你速度也太快了,我还在编辑

  • 1楼
    2012-11-5 14:27

    哈哈 这类产品工具很多 nginx cacti zabbix 什么的