使用snmp+mrtg监控Linux 系统 CPU、流量、磁盘空间、内存

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:

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]:

eth1网络流量[流入+流出]

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

#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]:

CPU负载[使用+闲置]

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

#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]:

内存使用量[Mem+Swap]

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

#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]:

硬盘空间[根分区+boot分区]

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

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

#!/bin/bash

LANG=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"

Options indexes

AllowOverride None

Order deny,allow

Deny from all

Allow from all

11、重启httpd

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

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

e46f8b20fca3268e2dde6a80f1367414.gif0b1331709591d260c1c78e86d0c51c18.png

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐