`
neilsh
  • 浏览: 9859 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
社区版块
存档分类
最新评论

RHEL6(CENTOS)配置MRTG服务

阅读更多
安装snmpd和mrtg
#yum install mrtg net-snmp net-snmp-utils


配置SNMP,配置完成后重启snmpd (因为网络接口转而采用了脚本采集,所以snmp就不配置了)

com2sec notConfigUser  localhost       public
group   notConfigGroup v1           notConfigUser
group   notConfigGroup v2c           notConfigUser
view    systemview    included   .1.3.6.1.2.1.1
view    systemview    included   .1.3.6.1.2.1.25.1.1
access  notConfigGroup ""      any       noauth    exact  all all none
view all    included  .1                               80
syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)


因为功能需求,我们再编写三个插件脚本,分别监视eth0、cpu和内存。
监视eth接口脚本内容
#!/bin/bash
# (c) 2002 Denis Kolisnichenko
# Usage: /usr/bin/count iface
/bin/grep "$1" /proc/net/dev | /bin/awk -F ":" '{ print $2 }' | /bin/awk '{ print $1 "\n" $9 }'
UPTIME=`/usr/bin/uptime | /bin/awk -F " " '{ print $3 }'`
echo $UPTIME
echo $1

监视CPU脚本内容
#!/usr/bin/perl
system ("/usr/bin/sar -u 1 3|grep Average >cpu_info_file");
open (CPUINFO,"cpu_info_file");
@cpuinfo=<CPUINFO>;
close (CPUINFO);
foreach $line(@cpuinfo) {
        @cpustatus=split(/ +/,$line);
}
$cpuused=$cpustatus[2]+$cpustatus[4];
$cpuidle=$cpustatus[5];
print "$cpuused\n";
print "$cpuidle";
system ("uptime");
system ("uname -n");

监视MEM脚本内容
#!/usr/bin/perl
system ("/usr/bin/free -m | grep Mem >mem_info_file");
open (MEMINFO,"mem_info_file");
@meminfo=<MEMINFO>;
close (MEMINFO);
foreach $line(@meminfo) {
@memstatus=split(/ +/,$line);
}
$memused=$memstatus[2];
$memtotal=$memstatus[1];
print "$memused\n";
print "$memtotal\n";
system ("uptime");
system ("uname -n");


配置/etc/mrtg/mrtg.cfg
EnableIPv6: no
WorkDir: /var/www/mrtg/
# eth0 monitor
Target[eth0]: `/etc/mrtg/bin/count.sh eth0`
Options[eth0]: nopercent,growright,bits
Title[eth0]: Server eth0 Traffic
PageTop[eth0]: <h1>Eth0 - interface</h1>
MaxBytes[eth0]: 99999999
kilo[eth0]: 1024
YLegend[eth0]: bits per second
ShortLegend[eth0]: bit/s
LegendO[eth0]: &nbsp; out:
LegendI[eth0]: &nbsp;   in :
# CPU monitor
Target[localhost_cpu]: `/etc/mrtg/bin/mrtg.cpu`
Ytics[localhost_cpu]: 10
YticsFactor[localhost_cpu]: 10
MaxBytes[localhost_cpu]:100
Title[localhost_cpu]:CPU State
PageTop[localhost_cpu]:<H1>Server CPU </H1>
ShortLegend[localhost_cpu]: %
YLegend[localhost_cpu]: CPU (%)
Legend1[localhost_cpu]: Used
Legend2[localhost_cpu]: Total
LegendI[localhost_cpu]: CPU Used
LegendO[localhost_cpu]: CPU IDEL
Options[localhost_cpu]: growright,gauge,nopercent
# Mem monitor
Target[localhost_mem]: `/etc/mrtg/bin/mrtg.mem`
Ytics[localhost_mem]:5
YticsFactor[localhost_mem]: 1
MaxBytes[localhost_mem]: 1000
Title[localhost_mem]:Memory State of TestServer
PageTop[localhost_mem]:<H1>Server Mem </H1>
ShortLegend[localhost_mem]: B
kmg[localhost_mem]: M
YLegend[localhost_mem]: Memory Usage
Legend1[localhost_mem]: Used
Legend2[localhost_mem]: Total
LegendI[localhost_mem]: Used
LegendO[localhost_mem]: Total
Options[localhost_mem]: growright,gauge,nopercent


生成index.html
#indexmaker --output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg


添加crontab计划
#cat /etc/cron.d/mrtg

*/5 * * * * root LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok


注:可以先运行一遍该命令,立即生成数据
/usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok


修改httpd的配置中mrtg的网址Allow from 部分

访问MRTG
http://youripaddres/mrtg/



引用

参考资料:
http://pm4u.narod.ru/en/mrtg.htm
http://www.php-oa.com/2009/11/01/centos-rhel-mrtg.html
http://oss.oetiker.ch/mrtg/doc/mrtg-reference.en.html
http://hi.baidu.com/wangli19880718/blog/item/b0cd9c514c47dd190cf3e3df.html

1
2
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics