当前位置: 首页 > 图文教程 > 操作系统 > Unix/Linux > 一步一步安装服务器监视软件MRTG

Unix/Linux
Solaris系统性能问题
定时任务
SA299考前简要总结
2005.8.22 310-015考试在TK中出现的原题或类似的题
My sumarization after passing the exam of 310-015
博客序言
SM240 课程内容及学习目标
SA399课程介绍及学习目标
Solaris9的jumpstart服务器配置中文详解(转载自CU)
SA399第一章读书笔记
SA399第二章读书笔记
精灵王的提醒
步长法-解决判断循环链表
SA399第三章读书笔记
真令人惊讶
Solaris介绍(转载)
VxVM中的底层建卷
转: Solaris 10 安装及SVC管理及X及Vmware及其它可能遇到的一些问题
Solaris学习笔记(2)
小型机内存与pc机内存区别

Unix/Linux 中的 一步一步安装服务器监视软件MRTG


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-01   浏览: 63 ::
收藏到网摘: n/a

     MRTG(MultiRouter Traffic Grapher, MRTG)是基于SNMP的典型网络流量统计分析工具。它耗用的系统资源很小,因此有很多外挂的程序也依附在MRTG下。它通过SNMP协议从设备得到其流量信息,并将流量负载以包含JPEG格式图形的HTML文档的方式显示给用户,以非常直观的形式显示流量负载。

一:安装网络流量监视[默认5分钟采集一次]

切换到超级用户:
sudo -sH

安装软件:
apt-get install apache2
apt-get install mrtg
apt-get install snmpd

编辑snmpd:
vim /etc/snmp/snmpd.conf

查找到类似的行,修改为如下所示:(仅仅修改屏蔽或放开)
# sec.name source community
# com2sec paranoid default public # kommentieren
com2sec readonly default public # <- auskommentieren
#com2sec readwrite default private

重启snmpd服务:
/etc/init.d/snmpd restart

重新生成mrtg的配置文件:
cfgmaker public@localhost > /etc/mrtg.cfg

(注意)如果仅仅监视一个IP地址采用如下命令:
cfgmaker [email protected] >> /etc/mrtg.cfg

生成mrtg的主页:
indexmaker /etc/mrtg.cfg > /var/www/mrtg/index.html

访问:
http://localhost/mrtg/

二安装CPU负载监视[默认5分钟采集一次]

切换到超级用户:
sudo -sH

安装软件:
apt-get install sysstat

建立CPU脚本:
mkdir /opt/mrtg
vim /opt/mrtg/mrtg.cpu
#!/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
hostname

使脚本可以执行:
chmod +755 /opt/mrtg/mrtg.cpu

修改 /etc/mrtg.cfg 在文件最后加入cpu项目
Target[cpu]: `/opt/mrtg/mrtg.cpu`
MaxBytes[cpu]: 100
Options[cpu]: gauge, nopercent, growright
YLegend[cpu]: CPU loading (%)
ShortLegend[cpu]: %
LegendO[cpu]: &nbsp; CPU us;
LegendI[cpu]: &nbsp; CPU sy;
Title[cpu]: CPU Loading
PageTop[cpu]: <H1>CPU Loading</H1>

重新生成索引页面:
indexmaker /etc/mrtg.cfg > /var/www/mrtg/index.html

访问:
http://localhost/mrtg/

三安装WWW连接数监视[默认5分钟采集一次]

切换到超级用户:
sudo -sH

建立WWW脚本:
mkdir /opt/mrtg
vim /opt/mrtg/mrtg.www
#!/bin/bash
all=`netstat -a | grep www|awk '{print $5}'|sort | wc -l|awk '{print$1 - 1}'`
user=`netstat -a | grep www|awk '{print $5}'|cut -d":" -f1|sort| uniq |wc -l | awk '{print $1 - 1}'`
if [ "$all" = "-1" ]; then
echo 0
else
echo $all
fi
if [ "$user" = "-1" ]; then
echo 0
else
echo $user
fi
UPtime=`/usr/bin/uptime | awk '{print $3 " " $4 " " $5}'`
echo $UPtime
hostname


使脚本可以执行:
chmod +755 /opt/mrtg/mrtg.www

修改 /etc/mrtg.cfg 在文件最后加入www项目
Target[www]: `/opt/mrtg/mrtg.www`
MaxBytes[www]: 500
Options[www]: nopercent, growright
YLegend[www]: Online Users
ShortLegend[www]: %
LegendI[www]: &nbsp; Connect :
LegendO[www]: &nbsp; Online :
Title[www]: WWW Connect
PageTop[www]: <H1> WWW Connect </H1>


重新生成索引页面:
indexmaker /etc/mrtg.cfg > /var/www/mrtg/index.html

访问:
http://localhost/mrtg/

四安装内存使用监视[默认5分钟采集一次]

切换到超级用户:
sudo -sH

建立RAM脚本:
mkdir /opt/mrtg
vim /opt/mrtg/mrtg.ram
#!/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