############cpu########################################
[root@localhost mrtgsh]# vi /etc/mrtg/mrtg.cfg
....
Target[cpu]: `/usr/local/apache2/htdocs/mrtgsh/mrtg.cpu`
MaxBytes[cpu]: 125000000
Title[cpu]: CPU
Options[cpu]: gauge,nopercent,growright
YLegend[cpu]: CPU loading (%)
ShortLegend[cpu]:%
LegendO[cpu]: & CPU USER;
LegendI[cpu]: & CPU SYSTEM;
PageTop[cpu]:
CPU
;
###################mrtg.cpu################################
[root@localhost mrtgsh]# vi /usr/local/apache2/htdocs/mrtgsh/mrtg.cpu
#!/bin/bash
cpuusr=`/usr/bin/sar -u 1 3 |grep Average |awk '{print $3}'`
cpusys=`/usr/bin/sar -u 1 3 |grep Average |awk '{print $5}'`
UPtime=`/usr/bin/uptime |awk '{print $3""$4""$5}'`
echo $cpuusr
echo $cpusys
echo $UPtime
hostname
chmod 755 /usr/local/apache2/htdocs/mrtgsh/mrtg.cpu
####################端口脚本##############################
建立8030脚本:
vi /usr/local/apache2/htdocs/mrtgsh/mrtg.8030
#!/bin/bash
all=`netstat -a | grep 8030|awk '{print $5}'|sort | wc -l|awk '{print$1 - 1}'`
user=`netstat -a | grep 8030|awk '{print $5}'|cut -d":" -f1|sort| uniq |wc -l | awk '{print $1 - 1}'`
if [ "$all" = "-1" ]; then
echo 0
else
echo $all
fi
if [ "$user" = "-1" ]; then
echo 0
else
echo $user
fi
UPtime=`/usr/bin/uptime | awk '{print $3 " " $4 " " $5}'`
echo $UPtime
hostname
使脚本可以执行:
chmod 755 /usr/local/apache2/htdocs/mrtgsh/mrtg.8030
修改 /etc/mrtg/mrtg.cfg 在文件最后加入8030项目
Target[8030]: `/usr/local/apache2/htdocs/mrtgsh/mrtg.8030`
MaxBytes[8030]: 500
Title[8030]: 8030 Connect
Options[8030]: nopercent, growright, gauge
YLegend[8030]: Online Users
ShortLegend[8030]: &
LegendI[8030]: Connect :
LegendO[8030]: Online :
PageTop[8030]:
8030 Connect
;
######################内存监视######################
vi /usr/local/apache/htdocs/mrtgsh/mrtg.memory
添加如下脚本:
#!/bin/bash
# run this script to check the mem usage.
totalmem=`/usr/bin/free |grep Mem |awk '{print $2}'`
usedmem=`/usr/bin/free |grep Mem |awk '{print $3}'`
UPtime=`/usr/bin/uptime | awk '{print $3""$4""$5}'`
echo $totalmem
echo $usedmem
echo $UPtime
让其具有运行权限
chmod 755 /usr/local/apache2/htdocs/mrtgsh/mrtg.memory
3.编辑/etc/mrtg/mrtg.cfg
添加如下内容
Target[memory]: `/usr/local/apache2/htdocs/mrtgsh/mrtg.memory`
MaxBytes[memory]: 4096000
Title[memory]:Memory Usages
ShortLegend[memory]: &
kmg[memory]:kB,MB
kilo[memory]:1024
YLegend[memory]: Memory Usage :
Legend1[memory]: Total Memory :
Legend2[memory]: Used Memory :
LegendI[memory]: Total Memory :
LegendO[memory]: Used Memory :
Options[memory]: growright,gauge,nopercent
PageTop[memory]:
Memory Usages
############重新生成主页面文件#############################
/usr/local/mrtg/bin/indexmaker /etc/mrtg/mrtg.cfg --output=/usr/local/apache2/htdocs/mrtg/index.html --title="My MRTG"
阅读(691) | 评论(0) | 转发(0) |