分类: 系统运维
2005-03-15 10:40:41
Mrtg监测CPU
1.安装 sysstat-4.0.7-3.i386.rpm
rpm -ivh sysstat-4.0.7-3.i386.rpm
2.编写外挂脚本 vi mrtg.cpu
#!/bin/bash
# 这个是用来测试cpu的脚本
# 1.开始使用sar来监测cpu的user及system的负载率
cpuusr=`/usr/bin/sar -u 1 3 | grep Average | awk '{print }'`
cpusys=`/usr/bin/sar -u 1 3 | grep Average | awk '{print }'`
UPtime=`/usr/bin/uptime | awk '{print " " " " }'`
# 2.列出四个数据(前两个为数字)
echo $cpuusr
echo $cpusys
echo $UPtime
echo 192.168.8.160
3.设定为可执行 chmod 755 mrtg.cpu
测试一下 ./mrtg.cpu
0.67
1.67
12:48, 1 user,
192.168.8.160
4.设置mrtg参数文件 vi mrtg.cfg.cpu
### Global Config Options
### To get bits instead of bytes and graphs growing to the right
WorkDir: /var/www/html/mrtg/cpu/
Language: GB2312
Target[localhost]: '/var/www/html/mrtg/cpu/mrtg.cpu'
MaxBytes[localhost]: 100
Options[localhost]: gauge, nopercent, growright
YLegend[localhost]: CPU loading (%)
ShortLegend[localhost]: %
LegendO[localhost]: CPU 使用者负载;
LegendI[localhost]: CPU 纯系统负载;
Title[localhost]: CPU 负载
PageTop[localhost]: 192.168.8.160 CPU 负载率
System: RedHat 9 in Linux Kernel 2.4.19
5.执行 (也三次以上)
mrtg /var/www/html/mrtg/cpu/mrtg.cfg.cpu
6.让它自动执行 crontab -e
*/2 * * * * mrtg /var/www/html/mrtg/cpu/mrtg.cfg.cpu >/dev/null 2>&1
7.打开浏览器即可观测