天天看点

在FreeBSD平台下使用mrtg来监控cpu、内存、交换分区、TCP连接以及本机网卡流量

介绍在FreeBSD平台下如何安装和使用mrtg来监控cpu、内存、交换分区、TCP连接以及本机网卡流量

1.安装

#安装apache2

cd /usr/ports/www/apache2

make install clean

#安装p5-SNMP

cd  /usr/ports/net-mgmt/p5-SNMP

make install clean

#安装mrtg

cd /usr/ports/net-mgmt/mrtg

make install clean

2.编写配置文件

LoadMIBs: /usr/local/share/snmp/mibs/UCD-SNMP-MIB.txt

WorkDir: /usr/local/www/data/mrtg

Language: chinese

#monitoring User vs Idle CPU usage

Target[kontor.cpu]:ssCpuRawUser.0&ssCpuRawIdle.0:[email protected]

RouterUptime[kontor.cpu]: [email protected]

MaxBytes[kontor.cpu]: 100

Title[kontor.cpu]: CPU LOAD

PageTop[kontor.cpu]: <H1>User CPU Load %</H1>

Unscaled[kontor.cpu]: ymwd

ShortLegend[kontor.cpu]: %

YLegend[kontor.cpu]: CPU Utilization

Legend1[kontor.cpu]: User CPU in % (Load)

Legend2[kontor.cpu]: Idle CPU in % (Load)

LegendI[kontor.cpu]:  User

LegendO[kontor.cpu]:  Idle

Options[kontor.cpu]: growright,nopercent

#monitoring User vs System CPU usage

Target[kontor.usrsys]:ssCpuRawUser.0&ssCpuRawSystem.0:[email protected]

RouterUptime[kontor.usrsys]: [email protected]

MaxBytes[kontor.usrsys]: 100

Title[kontor.usrsys]: CPU LOAD

PageTop[kontor.usrsys]: <H1>CPU (user and system) Load %</H1>

Unscaled[kontor.usrsys]: ymwd

ShortLegend[kontor.usrsys]: %

YLegend[kontor.usrsys]: CPU Utilization

Legend1[kontor.usrsys]: User CPU in % (Load)

Legend2[kontor.usrsys]: System CPU in % (Load)

LegendI[kontor.usrsys]:  User

LegendO[kontor.usrsys]:  System

Options[kontor.usrsys]: growright,nopercent

#monitoring Active CPU usage

Target[kontor.cpusum]:ssCpuRawUser.0&ssCpuRawUser.0:[email protected] + ssCpuRawSystem.0&ssCpuRawSystem.0:[email protected] + ssCpuRawNice.0&ssCpuRawNice.0:[email protected]

RouterUptime[kontor.cpusum]: [email protected]

MaxBytes[kontor.cpusum]: 100

Title[kontor.cpusum]: CPU LOAD

PageTop[kontor.cpusum]: <H1>Active CPU Load %</H1>

Unscaled[kontor.cpusum]: ymwd

ShortLegend[kontor.cpusum]: %

YLegend[kontor.cpusum]: CPU Utilization

Legend1[kontor.cpusum]: Active CPU in % (Load)

LegendI[kontor.cpusum]:  Active

Options[kontor.cpusum]: growright,nopercent

#Monitoring TCP connections

Target[tcpopen]: .1.3.6.1.2.1.6.9.0&.1.3.6.1.2.1.6.9.0:[email protected]

Options[tcpopen]: nopercent,growright,gauge,noinfo

Title[tcpopen]: Open TCP connections

PageTop[tcpopen]: <h1>Open TCP connections</H1>

MaxBytes[tcpopen]: 1000000

YLegend[tcpopen]: # conns

ShortLegend[tcpopen]: connections

LegendI[tcpopen]:  Connections:

Legend1[tcpopen]: Open TCP connections

#Monitoring Free Memory

Target[freemem]: .1.3.6.1.4.1.2021.4.11.0&.1.3.6.1.4.1.2021.4.11.0:[email protected]

Options[freemem]: nopercent,growright,gauge,noinfo

Title[freemem]: Free Memory

PageTop[freemem]: <h1>Free Memory</h1>

MaxBytes[freemem]: 1000000

kMG[freemem]: k,M,G,T,P,X

YLegend[freemem]: bytes

ShortLegend[freemem]: bytes

LegendI[freemem]:  Free Memory:

Legend1[freemem]: Free memory, not including swap, in bytes

#monitoring localhost ethernet traffic

Target[192.168.0.150_1]: 1:[email protected]:

SetEnv[192.168.0.150_1]: MRTG_INT_IP="192.168.0.150" MRTG_INT_DESCR="lnc0"

MaxBytes[192.168.0.150_1]: 100000000

Title[192.168.0.150_1]: Traffic Analysis for 1

PageTop[192.168.0.150_1]: <H1>Traffic Analysis for 1</H1>

Options[192.168.0.150_1]: growright,bits

将上面的代码保存为/usr/local/www/data/mrtg/mrtg.cfg

3.然后执行下面的命令,一共要执行三才,前两次会报错不用管,知道第三次没错就OK了,如果第三次还提示错误情检查配置文件

/usr/local/bin/mrtg /usr/local/www/data/mrtg/mrtg.cfg

4.制作索引页面

/usr/local/bin/indexmaker --output=/usr/local/www/data/mrtg/index.html /usr/local/www/data/mrtg/mrtg.cfg

5.crontab -e 编辑计划任务,添加下面一条任务

*/5  *  *  *  *  /usr/local/bin/mrtg /usr/local/www/data/mrtg/mrtg.cfg

好了,现在就就可以通过浏览器访问 http://192.168.0.150/mrtg 来监控你的计算机了

继续阅读