安装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]: out:
LegendI[eth0]: 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
分享到:
相关推荐
网络服务器搭建、配置与管理——Linux(RHEL8CentOS8)(微课版)(第4版)_PPT课件.zip
Linux网络操作系统项目教程(RHEL7.4CentOS7.4)(第3版)-实训指导书.zip
Linux网络操作系统项目教程(RHEL7.4CentOS7.4)(第3版)》-PPT课件.rar
rr268x-rhel_centos-5u2-x86_64
Linux网络操作系统项目教程(RHEL7.4CentOS7.4)(第3版)-电子教案.zip
56796-Linux网络操作系统项目教程(RHEL 8CentOS 8)(微课版)(第4版)-分章节课后习题答案.rar
在RHEL_CentOS 5上配置Oracle 10g
Linux网络操作系统项目教程(RHEL8CentOS8)(微课版)(第4版)-习题及答案.docx
Linux网络操作系统项目教程(RHEL 8CentOS 8)(微课版)(第4版)-分章节课后习题答案.rar
RHEL7 CENTOS 7 下 systemd 服务管理.pdf
RHEL.Centos.Fedora第三方软件库(pbone.EPEL.RPMForge.RPMFusion)使用配置
Linux网络操作系统项目教程(RHEL7.4CentOS7.4)(第3版)-教学大纲.zip
cpuid for RHEL6系列Linux
最新rhel7 centos7 安装向导
RHEL与CentOS系列等等第三方源仓库(大全) 通用,有教程.使用简单
OpenStack Queens for RHEL and CentOS安装指南 根据官方文档整理,日期为20180818-20180819。 我采用CentOS 7.4在虚拟机上演着过此文档,能够成功。 本文档只保留了官方文档中RHEL and CentOS的内容。
RedHat Linux RHEL6配置本地YUM源
此文档为RHEL7的yum源替换为免费CentOS的yum源所需包。
rhel6 centos6 系列双网卡绑定文档并附脚本 linux 6 7 脚本
RHEL6使用CentOS6的yum源 利用yum安装php,mysql,apache