五、各个SHELL(修改了配置之后要重新生成首页,然后重启)
(1)MEMORY:mem.sh
#!/bin/bash
# This script to monitor the mem usage.
totalmem=`/usr/bin/free |grep Mem |awk '{print $2}'`
usedmem=`/usr/bin/free |grep Mem |awk '{print $3}'`
echo "$totalmem"
echo "$usedmem"
编辑MRTG的配置文件:MaxBytes的值根据实际状况修改
# Mem
Target[memory]: `/_mrtg/sh/mem.sh`
Unscaled[memory]: dwym
MaxBytes[memory]: 2048000
Title[memory]:Memory
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]:<H1>Memory</H1>
(2)SWAP:swap.sh
#!/bin/bash
# This script to monitor the swap usage.
totalswap=`/usr/bin/free |grep Swap |awk '{print $2}'`
usedswap=`/usr/bin/free |grep Swap |awk '{print $3}'`
echo "$totalswap"
echo "$usedswap"
编辑MRTG的配置文件:MaxBytes根据实际状况修改
# Swap
Target[swap]:`/_mrtg/sh/swap.sh`
Unscaled[swap]: dwym
MaxBytes[swap]: 3048000
Title[swap]:SWAP
ShortLegend[swap]: &
kmg[swap]:kB,MB
kilo[swap]:1024
YLegend[swap]: Swap Usage
Legend1[swap]: Total Swap
Legend2[swap]: Used Swap
LegendI[swap]: Total Swap
LegendO[swap]: Used Swap
Options[swap]: growright,gauge,nopercent
PageTop[swap]:<H1>Swap</H1>
(3)CPU:cpu.sh
#!/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
hostname
编辑MRTG的配置文件:MaxBytes根据实际状况修改
# Cpu
Target[cpu]: `/_mrtg/sh/cpu.sh`
MaxBytes[cpu]: 100
Title[cpu]: CPU
Options[cpu]: gauge,nopercent,growright
YLegend[cpu]: CPU loading (%)
ShortLegend[cpu]:%
LegendO[cpu]: & CPU USER
LegendI[cpu]: & CPU SYSTEM
PageTop[cpu]: <H1>CPU</H1>
(4)磁盘佔用:df.pl
#!/usr/bin/perl
# output(df -kl) looks like this:
# Filesystem 1k-blocks Used Available Use% Mounted on
# /dev/md0 95645100 30401312 64272080 33% /
# /dev/hde1 14119 1159 12231 9% /boot
#
# In which case, this script returns :
# 95659219
# 30402503
# when run.
foreach $filesystem (`df -kl | grep -v "Filesystem"`){
@df = split(/\s+/,$filesystem);
$total += $df[1];
$usage += $df[2];
}
print "$total\n";
print "$usage\n";
hostname
编辑MRTG的配置文件:MaxBytes根据实际状况修改
# Disk used
Target[disk]: `/_mrtg/sh/df.pl`
Title[disk]: Disk Space
Unscaled[disk]: dwym
MaxBytes[disk]: 115247550
kmg[disk]: KB,MB,GB
LegendI[disk]: Total Disk Space
LegendO[disk]: Used Disk Space
Legend1[disk]: Total Disk Space
Legend2[disk]: Used Disk Space
YLegend[disk]: Megabytes
ShortLegend[disk]: &
Options[disk]: growright,gauge,nopercent
PageTop[disk]: <H1>Disk Space</H1>
(5)磁盘I/O:io.sh
#!/bin/bash
# This script will monitor the KBread/sec &KBwriten/sec of Disk.
# Creater: CCC IT loren ext:2288 2005/8/3
# As sda ,sdb,sdc,sdd,hda.
# disk=sda
hd=sda
disk=/dev/$hd
KBread_sec=`iostat -x $disk|grep $hd |awk '{print $8}'`
KBwrite_sec=`iostat -x $disk|grep $hd |awk '{print $9}'`
echo "$KBread_sec"
echo "$KBwrite_sec"
hostname
编辑MRTG的配置文件:如果需要检测更多的分区则修改io.sh
# Disk I/O
Target[diskIO]: `/_mrtg/sh/io.sh`
Title[diskIO]: Disk HDA I/O
Unscaled[diskIO]: dwym
MaxBytes[diskIO]: 100
kmg[diskIO]: KB,MB,GB
LegendI[diskIO]: Disk I/O KBread/sec
LegendO[diskIO]: Disk I/O KBwrite/sec
Legend1[diskIO]: Disk I/O KBread/sec
Legend2[diskIO]: Disk I/O KBwrite/sec
YLegend[diskIO]: Megabytes
ShortLegend[diskIO]: &
Options[diskIO]: growright,gauge,nopercent
PageTop[diskIO]: <H1>Disk I/O</H1>