//mrtg流量图大致流程 snmp调试->安装mrtg->配置mrtg->根据配置文件生成图片和部分网页文件->生成index.html->crontab轮询生成监控图片文件
//安装mrtg软件包
yum -y install mrtg*
//修改mrtg配置文件
vim /etc/mrtg/mrtg.cfg
#路径
HtmlDir: /home/wwwroot/test1/public/mrtg
ImageDir: /home/wwwroot/test1/public/mrtg
LogDir: /var/mrtg
ThreshDir: /var/mrtg
#流量
Target[eth1_lan]: /192.168.22.191: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]:网络流量[流入+流出]
PageTop[eth1_lan]:<h1>eth1网络流量[流入+流出]</h1>
#系统负载
Target[systemload]:.1.3.6.1.4.1.2021.10.1.3.1&.1.3.6.1.4.1.2021.10.1.3.3:public@localhost:
Options[systemload]:gauge,nopercent,growright
Directory[systemload]:load
MaxBytes[systemload]:3000
YLegend[systemload]:System Load
ShortLegend[systemload]:
Legend1[systemload]:最近1分钟系统负载(x100)
Legend2[systemload]:最近15分钟系统负载(x100)
LegendI[systemload]:1分钟负载:
LegendO[systemload]:15分钟负载:
Title[systemload]:系统负载(x100)[1分钟+15分钟]
PageTop[systemload]:<h1>系统负载(x100)[1分钟+15分钟]</h1>
#cpu
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>
#内存 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]:380028
MaxBytes2[memory]:4161528
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>
#硬盘 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]:16037808
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]:数据盘已用空间
LegendI[disk]:系统已用:
LegendO[disk]:数据已用:
Title[disk]:硬盘空间[系统盘+数据盘]
PageTop[disk]:<h1>硬盘空间[系统盘+数据盘]</h1>
//配置防火墙允许访问161端口
/sbin/iptables -I INPUT -p udp --dport 161 -j ACCEPT
service iptables save
service iptables restart
//设置开机自动启动
chkconfig iptables on
//配置完成后连续执行3次如下命令 vim/etc/cron.d/mrtg可查看轮询脚本(默认5分钟执行一次)
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
//生成首页
indexmaker --output //home/wwwroot/test1/public/mrtg/index.html --title="mrtg监控首页" /etc/mrtg/mrtg.cfg