Linux系統(tǒng)上安裝MRTG來(lái)監(jiān)控網(wǎng)絡(luò)流量

Multi Router Traffic Grapher------MRTG是一個(gè)監(jiān)控網(wǎng)絡(luò)鏈路流量負(fù)載的工具軟件,通過(guò)snmp協(xié)議得到設(shè)備的流量信息,并將流量負(fù)載以包含PNG格式的圖形的HTML 文檔方式顯示給用戶,以非常直觀的形式顯示流量負(fù)載。
SNMP(imple Network Management Protocol,簡(jiǎn)單網(wǎng)絡(luò)管理協(xié)議)的前身是簡(jiǎn)單網(wǎng)關(guān)監(jiān)控協(xié)議(SGMP),用來(lái)對(duì)通信線路進(jìn)行管理。隨后,人們對(duì)SGMP進(jìn)行了很大的修改,特別是加入了符合Internet定義的SMI和MIB:體系結(jié)構(gòu),改進(jìn)后的協(xié)議就是著名的SNMP。SNMP的目標(biāo)是管理互聯(lián)網(wǎng)Internet上眾多廠家生產(chǎn)的軟硬件平臺(tái),因此SNMP受Internet標(biāo)準(zhǔn)網(wǎng)絡(luò)管理框架的影響也很大?,F(xiàn)在SNMP已經(jīng)出到第三個(gè)版本的協(xié)議,其功能較以前已經(jīng)大大地加強(qiáng)和改進(jìn)了。
下面來(lái)看一下其在Linux系統(tǒng)上的安裝方法:
(1)必須安裝snmp
rpm -qa|grep snmp* //查看是否安裝了snmp
yum -y install snmp* //安裝snmp
#vim /etc/snmp/snmpd.conf
rocommunity public //配置snmpv1模式
disk / 13102744 //配置系統(tǒng)的大小
disk /data 41279536 //配置數(shù)據(jù)盤的大小
service snmpd start //配置開(kāi)啟snmp
chkconfig snmpd on //設(shè)置開(kāi)機(jī)啟動(dòng)
(2) 安裝mrtg
yum -y install mrtg*
(3)配置mrtg
//配置就是一個(gè)模板,大家只要把IP修改成自己的 內(nèi)存修改成自己的大小就可以了 我是在本地測(cè)試的
HtmlDir: /data/wwwroot/mrtg //這里是你網(wǎng)站的html地址 默認(rèn)為 /var/www/mrtg
ImageDir: /data/wwwroot/mrtg //這里是存放地址 默認(rèn)為 /var/www/mrtg
LogDir: /var/lib/mrtg
ThreshDir: /var/lib/mrtg
#
#[網(wǎng)絡(luò)流入流出圖]
#
Target[eth0_lan]: /118.244.182.176:public@localhost
Options[eth0_lan]:growright
Language:utf8
Directory[eth0_lan]:eth1
MaxBytes[eth0_lan]: 5000000
Title[eth0_lan]: eht0流入流出圖
Kmg[eth0_lan]:K,M,G
YLegend[eth0_lan]:Bytes per Second
ShortLegend[eth0_lan]:B/s
Legend1[eth0_lan]:每秒流入量
legend2[eth0_lan]:每秒流出量
legendI[eth0_lan]:流入
legendO[eth0_lan]:流出
PageTop[eth0_lan]: <H1>網(wǎng)卡流入流程圖</H1>
PageFoot[eth0_lan]:<a href="www.dbjr.com.cn">jb51 Inc</a>
#
#[CPU的負(fù)載]
#
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
Language:utf8
Directory[cpuload]:cpu
MaxBytes[cpuload]:100
Unscaled[cpuload]:dwym
Ylegend[cpuload]:CPU Utilization
Shortlegend[cpuload]:%
legend1[cpuload]:CPU用戶負(fù)載(%)
legend2[cpuload]:CPU閑置(%)
legendI[cpuload]:用戶
legendO[cpuload]:閑置
Title[cpuload]:CPU負(fù)載
PageTop[cpuload]:<h1>Cpu負(fù)載【用戶+閑置】</h1>
PageFoot[cpuload]:<a href="www.dbjr.com.cn">jb51 Inc</a>
#
#[內(nèi)存使用]
#
Target[memory]:.1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.4.0:public@localhost:
Options[memory]:gauge,growright
Directory[memory]:mem
Language:utf8
MaxBytes1[memory]:514908
MaxBytes2[memory]:2096472
Kmg[memory]:K,M,G
kilo[memory]:1024
Unscaled[memory]:dwym
YLegend[memory]:Memory Btyes
ShortLegend[memory]:B
Legend1[memory]:已用Mem(Bytes)
Legend2[memory]:已用Swap(Bytes)
LegendI[memory]:已用Mem:
LegendO[memory]:已用Swap
Title[memory]:內(nèi)存使用率
PageTop[memory]:<h1>內(nèi)存使用量(Mem+Swap)</h1>
PageFoot[memory]:<a href="www.dbjr.com.cn">jb51 Inc</a>
#
#[硬盤使用率]
#
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
Language:utf8
Directory[disk]:disk
MaxBytes1[disk]:13102744
MaxBytes2[disk]:41279536
Kmg[disk]:K,M,G
Kilo[disk]:1024
Ylegend[disk]:Disk Bytes
Shortlegend[disk]:B
legend1[disk]:系統(tǒng)磁盤已用空間
legend2[disk]:數(shù)據(jù)盤已用空間
legendI[disk]:系統(tǒng)已用
legendO[disk]:數(shù)據(jù)已用
Title[disk]:硬盤空間使用率
PageTop[disk]:<h1>硬盤空間[系統(tǒng)盤+數(shù)據(jù)盤]</h1>
PageFoot[disk]:<a href="www.dbjr.com.cn">jb51 Inc</a>
#================================================================================
#監(jiān)控系統(tǒng)負(fù)載[1分鐘+15分鐘]
#================================================================================
Target[systemload]: .1.3.6.1.4.1.2021.10.1.5.1&.1.3.6.1.4.1.2021.10.1.5.3:public@localhost:
Options[systemload]: gauge,nopercent,growright
Directory[systemload]: load
MaxBytes[systemload]: 3000
YLegend[systemload]: System Load
ShortLegend[systemload]:
Legend1[systemload]: 最近1分鐘系統(tǒng)負(fù)載(x100)
Legend2[systemload]: 最近15分鐘系統(tǒng)負(fù)載(x100)
LegendI[systemload]: 1分鐘負(fù)載:
LegendO[systemload]: 15分鐘負(fù)載:
Title[systemload]: 系統(tǒng)負(fù)載(x100)[1分鐘+15分鐘]
PageTop[systemload]:<h1>系統(tǒng)負(fù)載(x100)[1分鐘+15分鐘]</h1>
#================================================================================
#監(jiān)控打開(kāi)的TCP連接數(shù)[TCP連接數(shù)]
#================================================================================
Target[tcpopen]: .1.3.6.1.2.1.6.9.0&.1.3.6.1.2.1.6.9.0:public@localhost:
Options[tcpopen]: gauge,nopercent,growright
Directory[tcpopen]: tcpopen
MaxBytes[tcpopen]: 1000
YLegend[tcpopen]: Tcp Connections
ShortLegend[tcpopen]: 個(gè)
Legend1[tcpopen]: 打開(kāi)的TCP連接數(shù)(個(gè))
Legend2[tcpopen]:
LegendI[tcpopen]: TCP連接數(shù):
LegendO[tcpopen]:
Title[tcpopen]: TCP連接數(shù)[TCP連接數(shù)]
PageTop[tcpopen]:<h1> TCP連接數(shù)[TCP連接數(shù)]</h1>
(4)設(shè)置啟動(dòng)和corntab
mrtg安裝好后就已經(jīng)在 /etc/cron.d/下有一個(gè)mrtg的文件了 我們只需要修改
*/2 * * * * root 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 //每?jī)煞昼?執(zhí)行一次
第一次執(zhí)行會(huì)有錯(cuò)誤 所以我們必須手動(dòng)執(zhí)行三次 沒(méi)錯(cuò)誤就可以了
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
(5)我們到目錄下生成index文件
/usr/local/mrtg/bin/indexmaker /etc/mrtg/mrtg.cfg --output=/data/wwwroot/mrtg/index.html --title="自己起名"
效果如下

相關(guān)文章
在Linux系統(tǒng)中使用iptraf進(jìn)行網(wǎng)絡(luò)監(jiān)控
這篇文章主要介紹了在Linux系統(tǒng)中使用iptraf進(jìn)行網(wǎng)絡(luò)監(jiān)控,iptraf是一個(gè)擁有簡(jiǎn)單圖形化界面的TCP/UDP管理工具,需要的朋友可以參考下2015-07-24簡(jiǎn)介L(zhǎng)inux下的TCP/UDP監(jiān)控工具iptraf
這篇文章主要介紹了簡(jiǎn)介L(zhǎng)inux下的TCP/UDP監(jiān)控工具iptraf,程序基于簡(jiǎn)單的圖形化界面,需要的朋友可以參考下2015-06-03shell awk實(shí)現(xiàn)實(shí)時(shí)監(jiān)控網(wǎng)卡流量腳本(常見(jiàn)應(yīng)用二)
通過(guò)第3方工具獲得網(wǎng)卡流量,這個(gè)大家一定很清楚。其實(shí)通過(guò)腳本一樣可以實(shí)現(xiàn)效果。下面是我個(gè)人工作中整理的數(shù)據(jù)。以下是shell腳本統(tǒng)計(jì)網(wǎng)卡流量2013-11-19Linux流量監(jiān)控工具 iftop (最全面的iftop教程)
在類Unix系統(tǒng)中可以使用top查看系統(tǒng)資源、進(jìn)程、內(nèi)存占用等信息。查看網(wǎng)絡(luò)狀態(tài)可以使用netstat、nmap等工具。若要查看實(shí)時(shí)的網(wǎng)絡(luò)流量,監(jiān)控TCP/IP連接等,則可以使用iftop2010-12-20Linux中iptraf命令詳解(IP局域網(wǎng)監(jiān)控工具)
iptraf命令可以實(shí)時(shí)地監(jiān)視網(wǎng)卡流量,可以生成網(wǎng)絡(luò)協(xié)議數(shù)據(jù)包信息、以太網(wǎng)信息、網(wǎng)絡(luò)節(jié)點(diǎn)狀態(tài)和ip校驗(yàn)和錯(cuò)誤等信息2017-12-27