MRTG能做什么?——6项数据监测配置文档
发表于:2007-07-04来源:作者:点击数:
标签:
[color=red:8cf569541e]作者:白金网名:platinum(china unix )超超白金(白金论坛) 欢迎转载,转载请保留上述信息 ===========================================================================[/color:8cf569541e] http://mrtg.platinum.3322.org 以
[color=red:8cf569541e]作者:白金 网名:platinum(china
unix) 超超白金(白金
论坛)
欢迎转载,转载请保留上述信息
=========================================================================== [/color:8cf569541e]
http://mrtg.platinum.3322.org以下是我的配置文档,根据个人不同再进行细节更改
mrtg.conf
[code:1:8cf569541e]
### Global Defaults
# to get bits instead of bytes and graphs growing to the right
Options[_]: growright
######################################################################
# System: platinum.3322.org
# Description:
Linux platinum.3322.org
# Contact: Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
# Location: Unknown (edit /etc/snmp/snmpd.conf)
######################################################################
### Interface 3 >> Descr: 'eth1' | Name: '' | Ip: '0.0.0.0' | Eth: '4c-00-10-b5-
2e-1b' ###
Target[platinum.3322.org_3]: 3:holdata@holdata.3322.org
SetEnv[platinum.3322.org_3]: MRTG_INT_IP="0.0.0.0" MRTG_INT_DESCR="eth1"
MaxBytes[platinum.3322.org_3]: 80000
Xsize[platinum.3322.org_3]: 600
Ysize[platinum.3322.org_3]: 200
Ytics[platinum.3322.org_3]: 9
Title[platinum.3322.org_3]: Traffic Analysis for ADSL -- platinum.3322.org
PageTop[platinum.3322.org_3]: <H1>Traffic Analysis for ADSL -- platinum.3322.org</
H1>
### Interface 2 >> Descr: 'eth0' | Name: '' | Ip: '192.168.0.1' | Eth: '4c-00-10
-b4-e1-2c' ###
Target[platinum.3322.org_2]: 2:holdata@holdata.3322.org
SetEnv[platinum.3322.org_2]: MRTG_INT_IP="192.168.0.1" MRTG_INT_DESCR="eth0"
MaxBytes[platinum.3322.org_2]: 10000000
Xsize[platinum.3322.org_2]: 600
Ysize[platinum.3322.org_2]: 200
Ytics[platinum.3322.org_2]: 9
Title[platinum.3322.org_2]: Traffic Analysis for LAN -- server.platinum.3322.org
PageTop[platinum.3322.org_2]: <H1>Traffic Analysis for LAN -- platinum.3322
.org</H1>
Target[managemem]:`/usr/local/sbin/mem.pl`
#Target[managemem]: memTotalReal.0&memAvailReal.0:holdata@holdata.3322.org
Xsize[managemem]: 600
Ysize[managemem]: 200
Ytics[managemem]: 9
Unscaled[managemem]: dwym
MaxBytes[managemem]: 262144
Title[managemem]:Memory State of HOLDATA Server
PageTop[managemem]:<H1>Memory State of HOLDATA Server</H1>
ShortLegend[managemem]: &
kmg[managemem]:kB,MB
kilo[managemem]:1024
YLegend[managemem]: Memory Usage
Legend1[managemem]: &Total Memory&
Legend2[managemem]: &Available Memory&
LegendI[managemem]: &Total Memory&
LegendO[managemem]: &Available Memory&
Options[managemem]: growright,gauge,nopercent
Target[disk]: `/usr/local/sbin/df.pl`
Xsize[disk]: 600
Ysize[disk]: 200
Ytics[disk]: 10
Title[disk]: HOLDATA SERVER Disk Space (76,524,755 kB / 80GB) Megabytes used
Unscaled[disk]: dwym
MaxBytes[disk]: 76524755
PageTop[disk]: <H1>PLATINUM SERVER Disk Space(76,524,755 kB / 80GB) Megabytes use
d</H1>
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
Target[cpu]:`/usr/local/sbin/cpu.pl`
Xsize[cpu]:600
Ysize[cpu]:200
Ytics[cpu]:10
MaxBytes[cpu]:100
Title[cpu]: CPU State of HOLDATA Server
PageTop[cpu]:<H1>CPU State of HOLDATA Server</H1>
ShortLegend[cpu]:%
YLegend[cpu]:CPU Loading(%)
Legend1[cpu]: Load over 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&
Options[cpu]:growright,gauge,nopercent
Target[load]: `/usr/local/sbin/load.sh`
Xsize[load]: 600
Ysize[load]: 200
Ytics[load]: 10
MaxBytes[load]: 3000
PageTop[load]: <H1> HOLDATA SERVER Load Average </H1>
Options[load]: growright, gauge, nopercent
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]: 15 minute stagger&&
Title[load]: System load
[/code:1:8cf569541e]
以下是要调用的SHELL的具体代码
df.pl
[code:1:8cf569541e]
#!/usr/bin/perl
# This script
was written on Debian 3.0, it assumes that the command
# 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";
[/code:1:8cf569541e]
cpu.pl
[code:1:8cf569541e]
# !/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 holdata.3322.org
[/code:1:8cf569541e]
load.sh
[code:1:8cf569541e]
#!/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
[/code:1:8cf569541e]
mem.pl,直接抓取memTotalReal.0&memAvailReal.0包也可以,但好像UCD-SNMP不可以
LINUX系统安装,默认是UCD-SNMP,我现在换成了最新版本的NET-SNMP[code:1:8cf569541e]
#!/usr/bin/perl
# setup local vars
my($machine, $os);
#=======================================================
# == Enter your default machine name and os here ==
$machine = "holdata.3322.org"; # 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: cpuinfo.pl {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;
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";
}
[/code:1:8cf569541e]
然后再/etc/crontab里加上每2分钟运行一次mrtg 指定路径的mrtg.conf就可以了
照上面看来,MRTG可以监测任何东西,只要有数据,MRTG就能根据数据绘制出图形,自己可以编写小程序来获取你想要绘制的图形的数据
[color=red:8cf569541e]
根据不同的需要,可以再进一步改进
我这个MRTG系统已经根据自己的实际情况改进了好几次了,实际就是改写SHELL
效果见
http://mrtg.platinum.3322.org[/color:8cf569541e]
linuxpotato 回复于:2003-12-29 23:56:54 |
哇!mrtg有着末多功能,我根据菜鸟哥的文档只配出流量和cpu占用率,功能很少,楼主是怎末做到的,可否将配置与大家分享一下呢?我觉得这其中还可再加上在线人数统计功能,期待。 :em02:
|
platinum 回复于:2003-12-30 09:02:52 |
我发现MRTG可以用的很活,不一定非要抓SNMP包进行处理 完全可以编写SHELL,获取系统的数据然后输出给MRTG做图表分析 我这里除了第一第二个必须用SNMP抓包,第三个可用可不用以外,其余3个必须编写SHELL了
|
imtj 回复于:2003-12-30 09:42:28 |
你可以把你的上面统计的那些是怎么实现的写出来看看!!!
|
manju 回复于:2003-12-30 09:51:28 |
能否把详细的配置写出来。谢谢了!
|
platinum 回复于:2003-12-30 11:44:02 |
资料整理中……请稍等…………
|
platinum 回复于:2003-12-30 11:57:22 |
(此贴内容已移至顶部)
|
platinum 回复于:2003-12-31 13:07:23 |
费了这么半天劲,版主帮我加精吧! ^O^
|
好好先生 回复于:2003-12-31 13:38:53 |
鼓励一下这种精神.
|
大熊宝宝 回复于:2004-01-01 13:06:34 |
:lol: :lol: :lol: 好
|
eagerlinuxer 回复于:2004-01-02 03:01:31 |
太好了,太好了,我正需要这个呢。有没有有关mrtg.conf配置文档说明,帖出来或给个链接吧,还有你俱体的配置过程的说明:)
|
platinum 回复于:2004-01-02 08:55:31 |
小弟不才:) 那几个pl和sh文件是我从很多地方包括国外的BBS上搜索然后一点一点攒下来的,具体怎么编我就不太清楚了,但知道几个参数是干什么用的,我在这里说一下吧
Target:是要执行的脚本 Xsize:生成图表的横向宽度(最大600) Ysize:生成图表的纵向高度(最大200) Title:标题 Ytics:纵向划分为几个块(格子) MaxBytes:图表纵向数值的最大上限 PageTop:页面上面的提示 kilo:一般是写1024,如果需要的话,是1000在计算机里的单位 LegendI:从SHELL返回的数据中的第一个 LegendO:从SHELL返回的数据中的第二个 Options:一般后面跟growright,表示图表向右延展
我就知道这么多了……^_^
总之一句话,LegendI和LegendO是最有用的,它可以根据Target后面所执行的脚本所返回的数据绘制图表,你想知道什么,只要编写SHELL能获得并输出,MRTG就能给你画出来
另外一种就是用SNMP的抓包,这个我就不太清楚了……
|
fire9 回复于:2004-01-02 10:43:02 |
够厉害的!
|
npudream 回复于:2004-01-07 16:35:24 |
可以在服务器上安装net-snmp,配置并启动snmpd服务,然后按照http://net-snmp.sourceforge.net/tutorial/mrtg/index.html里的介绍就可以远程抓取各类参数并生成mrtg图形,这样就可以集中网管所有的服务器。
|
wangfeixue 回复于:2004-01-07 16:51:00 |
请问什么是MRTG哪里有下载的??
|
zor 回复于:2004-02-27 14:21:49 |
由于redhat 7的snmp包有BUG所以会很不稳定,而且无法查到硬盘的数据,虽然有很多文档都有写可以查到。必须升级默认安装的rpm才能达到输出硬盘资料和其它数值效果。 :em11:
|
platinum 回复于:2004-03-06 10:41:41 |
可以自己写脚本实现,不通过SNMP进行抓包!
|
startkill 回复于:2004-12-31 15:30:56 |
platinum兄问个问题``我的mrtg默认只能显示10MB的流量需要修改那里才能显示更大的流量
|
startkill 回复于:2004-12-31 15:57:07 |
呵呵```偶找到了``
|
woshiwho 回复于:2004-12-31 16:33:58 |
这种帖子,赶紧收了,回去慢慢品味
|
原文转自:http://www.ltesting.net