我的MRTG配置文件
时间:2006-03-14 来源:zhu_mx
我的MRTG配置文件
mrtg.cfg
# Created by
# ./cfgmaker --output=/var/www/html/mrtg/net/mrtg.cfg [email protected]
### Global Config Options
# for UNIX
WorkDir: /var/www/html/mrtg
# or for NT
# WorkDir: c:\mrtgdata
### Global Defaults
# to get bits instead of bytes and graphs growing to the right
Options[_]: growright, bits
Language:GB2312
######################################################################
# System: linuxwht
# Description: Linux linuxwht 2.4.20-8 #1 Thu Mar 13 17:54:28 EST 2003 i686
# Contact: [email protected]
# Location: 172.16.86.230
######################################################################
### Interface 1 >> Descr: 'lo' | Name: '' | Ip: '127.0.0.1' | Eth: '' ###
### The following interface is commented out because:
### * it is a Software Loopback interface
#
# Target[172.16.86.230_1]: 1:[email protected]:
# SetEnv[172.16.86.230_1]: MRTG_INT_IP="127.0.0.1" MRTG_INT_DESCR="lo"
# MaxBytes[172.16.86.230_1]: 1250000
# Title[172.16.86.230_1]: Traffic Analysis for 1 -- linuxwht
# PageTop[172.16.86.230_1]: <H1>Traffic Analysis for 1 -- linuxwht</H1>
# <TABLE>
# <TR><TD>System:</TD> <TD>linuxwht in 172.16.86.230</TD></TR>
# <TR><TD>Maintainer:</TD> <TD>[email protected]</TD></TR>
# <TR><TD>Description:</TD><TD>lo </TD></TR>
# <TR><TD>ifType:</TD> <TD>softwareLoopback (24)</TD></TR>
# <TR><TD>ifName:</TD> <TD></TD></TR>
# <TR><TD>Max Speed:</TD> <TD>1250.0 kBytes/s</TD></TR>
# <TR><TD>Ip:</TD> <TD>127.0.0.1 (localhost)</TD></TR>
# </TABLE>
### Interface 2 >> Descr: 'eth0' | Name: '' | Ip: '172.16.3.1' | Eth: '00-0c-29-37-66-3e' ###
Target[net_2]: 2:[email protected]:
SetEnv[net_2]: MRTG_INT_IP="172.16.3.1" MRTG_INT_DESCR="eth0"
Xsize[net_2]:400
Ysize[net_2]:150
Ytics[net_2]:10
MaxBytes[net_2]: 1250000
Title[net_2]: Traffic Analysis for 2 -- linuxwht
PageTop[net_2]: <H1>Traffic Analysis for 2 -- linuxwht</H1>
<TABLE>
<TR><TD>System:</TD> <TD>linuxwht in 172.16.86.230</TD></TR>
<TR><TD>Maintainer:</TD> <TD>[email protected]</TD></TR>
<TR><TD>Description:</TD><TD>eth0 </TD></TR>
<TR><TD>ifType:</TD> <TD>ethernetCsmacd (6)</TD></TR>
<TR><TD>ifName:</TD> <TD></TD></TR>
<TR><TD>Max Speed:</TD> <TD>1250.0 kBytes/s</TD></TR>
<TR><TD>Ip:</TD> <TD>172.16.3.1 (mail)</TD></TR>
</TABLE>
Target[cpu]:`/var/www/html/mrtg/cpu.mrtg`
Xsize[cpu]:400
Ysize[cpu]:150
Ytics[cpu]:10
MaxBytes[cpu]: 100
Options[cpu]:gauge,nopercent,growright
YLegend[cpu]:CPU loading (%)
ShortLegend[cpu]:%
Legend1[cpu]:Load over last 5 minutes&
Legend2[cpu]:Load over last 15 minutes&
Legend3[cpu]:Average over last 5 minutes
Legend4[cpu]:Average over last 15 minutes
Legendo[cpu]:CPU SYS &
Legendi[cpu]:CPU USER&
Title[cpu]:CPU State of Linuxwht Server
PageTop[cpu]:<H1>CPU State of Linuxwht Server</H1>
Target[managemem]:`/var/www/html/mrtg/mem.mrtg`
Xsize[managemem]:400
Ysize[managemem]:150
Ytics[managemem]:9
MaxBytes[managemem]: 125992
Options[managemem]:gauge,nopercent,growright
YLegend[managemem]: Memory Usage
ShortLegend[managemem]: &
kmg[managemem]:KB,MB
kilo[managemem]:1024
Legend1[managemem]:Total Memory&
Legend2[managemem]:Available Memory&
Legendo[managemem]:Available Memory&
Legendi[managemem]:Total Memory&
Title[managemem]:Memory State of Linuxwht Server
PageTop[managemem]:<H1>Memory State of Linuxwht Server</H1>
Target[load]:`/var/www/html/mrtg/load.mrtg`
Xsize[load]:400
Ysize[load]:150
Ytics[load]:10
MaxBytes[load]:100
Options[load]:gauge,nopercent,growright
YLegend[load]: Load average (10E-2)
ShortLegend[load]: (10E-2)&
Legend1[load]:Load over 5 minutes&
Legend2[load]:Load over last 15 minutes&
Legend3[load]:Average over last 5 minutes
Legend4[load]:Average over last 15 minutes
Legendo[load]:015 minute stagger
Legendi[load]:Total load stagger
Title[load]:System load of Linuxwht Server
PageTop[load]:<H1>Linuxwht Server Load Average</H1>
Target[disk]:`/var/www/html/mrtg/df.mrtg`
Xsize[disk]:400
Ysize[disk]:200
Ytics[disk]:10
MaxBytes[disk]: 10000000000
Options[disk]:gauge,nopercent,growright
YLegend[disk]: Megabytes
ShortLegend[disk]: &
Legend1[disk]:Total Disk Space
Legend2[disk]:Used Disk Space
Legendi[disk]:Total Disk Space
Legendo[disk]:Used Disk Space
Title[disk]:Linuxwht Server Disk Space (8,062,493 kb / 8.0GB)
PageTop[disk]:<H1>Linuxwht Server Disk Space (8,062,493 kb / 8.0GB)</H1>
cpu.mrtg
#!/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
echo linuxwht.linuxwht.com
df.mrtg
#!/usr/bin/perl
foreach $filesystem (`df --block-size=1 | grep -v "Filesystem"`)
/* 原来我用`df -kl`时发现显示的硬盘空间是错误的,因为SNMP是以字节为单位进行运算的,所以输出也要以字节为基准 */
{
@df = split(/\s+/,$filesystem);
$total += $df[1];
$usage += $df[2];
}
print "$total\n";
print "$usage\n";
$UPTIME=`uptime`;
$HOSTN=`uname -n`;
print "$UPTIME";
print "$HOSTN";
load.mrtg
#!/bin/sh
# first the load 5 and 15 min avg
# multiply * 100 to avoid floats
# it helps if mrtg "period" is a multiple of 5 mins
uptime | sed -e 's/^.*average.*: \(.*\)$/\1/' -e 's/ //g' |
awk -F, '{ printf("%.0f\n",$2*100); printf("%.0f\n",$3*100) }'
# the uptime
uptime | sed 's:^.* up \(.*\), [0-9][0-9]* users.*$:\1:'
# my name
uname -n
mem.mrtg
#!/usr/bin/perl
# setup local vars
my($machine, $os);
#=======================================================
# == Enter your default machine name and os here ==
$machine = "linuxwht.linuxwht.com"; # Enter machine to monitor here
$os = "linux"; # Currently there is only linux and sun
# == You shouldn't need to edit anything below this line ==
#========================================================
# This allows command args to override defaults listed above
if (scalar(@ARGV) > 2)
{
print("USAGE: cpu.mrtg {machine} {os}\n");
exit(-1);
}
if ($ARGV[0] ne '' && $ARGV[0] ne '#')
{
$machine = $ARGV[0];
}
if ($ARGV[1] ne '' && $ARGV[1] ne '#')
{
$os = $ARGV[1];
}
# Validate the os
SWITCH:
{
if ($os =~ /^sun$/){last SWITCH;}
if ($os =~ /^linux$/){last SWITCH;}
# DEFAULT: Die if we can't figure out what the os is
die "Can't figure out which OS the machine is.\n";
}
# Execute the appropriate subroutine based on the os
&$os;
print "$getuptime";
print "$machine\n";
exit(0);
#=======================================================
# Subroutines: names of subroutines are supported OSs.
#========================================================
sub sun
{
# Run commands
# $getcpu = `rsh $machine "sar -u 1 10" | grep Average`;
# $getuptime = `rsh $machine "uptime"`;
# Parse though getcpu and get data
# $getcpu =~ /^Average\s+(\d+)\s+(\d+)\s+/;
# $outputusr = $1;
# $outputsys = $2;
# Print getcpu data for mrtg
# print $outputusr."\n";
# print $outputsys."\n";
#foreach $_ (` | grep -v "Filesystem"`)
#{
# ($device, $size, $used, $free, $percent, $mount) = split(/\s+/);
# chop($percent);
# print "$percent\n";
#}
# Parse though getuptime and get data
$getuptime =~ /^\s+(\d{1,2}:\d{2}..)\s+up\s+(\d+)\s+(......),/;
# Print getuptime data for mrtg
print $2." ".$3."\n";
# Print machine name for mrtg
print $machine."\n";
}
sub linux
{
# Run commands
# $getcpu = ` /usr/local/bin/sar -u 1 10 | grep "Average:"`;
$getuptime = `/usr/bin/uptime`;
# Parse though getcpu and get data
# $getcpu =~ /^Average:\s+(\d+).(\d+)%\s+(\d+).(\d+)%\s+(\d+).(\d+)%\s+(\d+).(\d+)%/;
# $getcpuusr = $1;
# $getcpusys = $5;
foreach $_ (`/usr/bin/sar -r 1 2 | grep "Average"`)
{
($average, $kbmemfree, $kbmemused, $memused, $kbmemshrd, $kbbuffers, $kbcached, $kbswpfree, $kbswpused, $swpused) = split(/\s+/);
chop($user);
chop($nice);
print "$kbmemused\n";
print "$kbmemfree\n";
}
# Print getcpu data for mrtg
# print $getcpuusr."\n";
# print $getcpusys."\n";
}
一点说明:
sar命令是要sysstat-4.0.7-3.rpm(redhat 9.0是这个,其它版本作相应改变)
Target:是要执行的脚本
Xsize:生成图表的横向宽度(最大600)
Ysize:生成图表的纵向高度(最大200)
Title:标题
Ytics:纵向划分为几个块(格子)
MaxBytes:图表纵向数值的最大上限,如果此值小于LegendI,则输出的LegendI等于Legendo,Legendo则等于零!
PageTop:页面上面的提示
kilo:一般是写1024,如果需要的话,是1000在计算机里的单位
LegendI:从SHELL返回的数据中的第一个
LegendO:从SHELL返回的数据中的第二个
Options:一般后面跟growright,表示图表向右延展