专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »Linux » mrtg安装:一步一步安装服务器监视软件MRTG »正文

mrtg安装:一步一步安装服务器监视软件MRTG

来源: 发布时间:星期四, 2009年2月12日 浏览:46次 评论:0


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

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

切换到超级用户:
sudo -sH

安装软件Software:
apt-get apache2
apt-get mrtg
apt-get 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/


=postbody>=postbody> 2安装CPU负载监视[默认5分钟采集次]

切换到超级用户:
sudo -sH

安装软件Software:
apt-get sysstat

建立CPU脚本:
mkdir /opt/mrtg
vim /opt/mrtg/mrtg.cpu
#!/bin/bash
cpuusr=`/usr/bin/sar -u 1 3 | grep Average | awk '{pr $3}'`
cpusys=`/usr/bin/sar -u 1 3 | grep Average | awk '{pr $5}'`
UPtime=`/usr/bin/uptime | awk '{pr $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/


=postbody>=postbody>=postbody> 3安装WWW连接数监视[默认5分钟采集次]

切换到超级用户:
sudo -sH

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

echo $all
fi
[ "$user" = "-1" ]; then
echo 0

echo $user
fi
UPtime=`/usr/bin/uptime | awk '{pr $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]: _disibledevent=>=postbody>=postbody>=postbody> 4安装内存使用监视[默认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 '{pr $2}'`
usedmem=`/usr/bin/free |grep Mem |awk '{pr $3}'`
UPtime=`/usr/bin/uptime | awk '{pr $3""$4""$5}'`
echo $totalmem
echo $usedmem
echo $UPtime
hostname

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

修改 /etc/mrtg.cfg 在文件最后加入ram项目
Target[ram]: `/opt/mrtg/mrtg.ram`
#Unscaled[ram]: dwym
MaxBytes[ram]: 2048000
Title[ram]:Memory
ShortLegend[ram]: &
kmg[ram]:kB,MB
kilo[ram]:1024
YLegend[ram]: &nbsp; Memory Usage :
Legend1[ram]: &nbsp; Total Memory :
Legend2[ram]: &nbsp; Used Memory :
LegendI[ram]: &nbsp; Total Memory :
LegendO[ram]: &nbsp; Used Memory :
Options[ram]: growright,gauge,nopercent
PageTop[ram]:<H1>Memory</H1>

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

访问:
http://localhost/mrtg/


=postbody>=postbody>=postbody>=postbody>=postbody>

=postbody>=postbody>=postbody>=postbody>=postbody>





=postbody>=postbody>=postbody>=postbody>=postbody> 5安装FTP连接数监视[默认5分钟采集次]

切换到超级用户:
sudo -sH

建立FTP脚本:
mkdir /opt/mrtg
vim /opt/mrtg/mrtg.ftp
#!/bin/bash
all=`netstat -a | grep ftp|awk '{pr $5}'|sort | wc -l|awk '{pr$1 - 1}'`
user=`netstat -a | grep ftp|awk '{pr $5}'|cut -d":" -f1|sort| uniq |wc -l | awk '{pr $1 - 1}'`
[ "$all" = "-1" ]; then
echo 0

echo $all
fi
[ "$user" = "-1" ]; then
echo 0

echo $user
fi
UPtime=`/usr/bin/uptime | awk '{pr $3 " " $4 " " $5}'`
echo $UPtime
hostname


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

修改 /etc/mrtg.cfg 在文件最后加入ftp项目
Target[ftp]: `/opt/mrtg/mrtg.ftp`
MaxBytes[ftp]: 500
Options[ftp]: nopercent, growright
YLegend[ftp]: _disibledevent=>=postbody>=postbody>=postbody>=postbody>=postbody> 6安装CPU温度监视[默认5分钟采集次]

切换到超级用户:
sudo -sH

安装软件Software:
apt-get mbmon

建立CPU温度脚本:
mkdir /opt/mrtg
vim /opt/mrtg/mrtg.temp
#!/bin/bash
/usr/bin/mbmon -c 1 -i -T 4 -u -n
exit 0


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

修改 /etc/mrtg.cfg 在文件最后加入cpu项目
Target[temp]: `/opt/mrtg/mrtg.temp`
MaxBytes[temp]: 100
Title[temp]: CPU Temperature
PageTop[temp]: <H1>CPU Temperature</H1>
Options[temp]: gauge,absolute,unknaszero,growright
YLegend[temp]: Temperature(C)
ShortLegend[temp]: (C)
Legend1[temp]: CPU Temperature
Legend2[temp]: M/B Temperature
LegendI[temp]: CPU Temp.
LegendO[temp]: M/B Temp.

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

访问:
http://localhost/mrtg/


=postbody>=postbody>=postbody>=postbody>=postbody>=postbody>=postbody> 7硬盘读写监视[默认5分钟采集次]

切换到超级用户:
sudo -sH

建立硬盘读写脚本:
mkdir /opt/mrtg
vim /opt/mrtg/mrtg.disk
#!/bin/bash
hd=sda
disk=/dev/$hd
UPtime=`/usr/bin/uptime |awk '{pr $3""$4""$5}'`
KBread_sec=`iostat -x $disk|grep $hd |awk '{pr 8$}'`
KBwrite_sec=`iostat -x $disk|grep $hd |awk '{pr 9$}'`
echo $KBread_sec
echo $KBwrite_sec
echo $UPtime
hostname


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

修改 /etc/mrtg.cfg 在文件最后加入硬盘读写
Target[disk]: `/opt/mrtg/mrtg.disk`
Title[disk]: Disk HDA I/O Utilization Report
#Unscaled[disk]: dwym
MaxBytes[disk]: 10240000
PageTop[disk]: <H1>Disk I/O Utilization Report</H1>
kmg[disk]: KB,MB,GB
LegendI[disk]: Disk I/O KBread/sec
LegendO[disk]: Disk I/O KBwrite/sec
Legend1[disk]: Disk I/O KBread/sec
Legend2[disk]: Disk I/O KBwrite/sec
YLegend[disk]: Megas
ShortLegend[disk]: &
Options[disk]: growright,gauge,nopercent

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

访问:
http://localhost/mrtg/


=postbody>=postbody>=postbody>=postbody>=postbody>=postbody>=postbody>=postbody> 8:磁盘使用

切换到超级用户:
sudo -sH

建立磁盘使用脚本:
mkdir /opt/mrtg
vim /opt/mrtg/mrtg.df
#!/usr/bin/perl
foreach $filesystem (`df -kl | grep -v "Filesystem"`)
{
@df = split(/\s+/,$filesystem);
$total $df[1];
$usage $df[2];
}
pr "$total\n";
pr "$usage\n";
hostname


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

修改 /etc/mrtg.cfg 在文件最后加入
Target[disk]: `/opt/mrtg/mrtg.df`
Title[disk]: Disk Space
Unscaled[disk]: dwym
MaxBytes[disk]: 465247550
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]: Megas
ShortLegend[disk]: &
Options[disk]: growright,nopercent
PageTop[disk]: <H1>Disk Space</H1>

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


=postbody>=postbody>=postbody>=postbody>=postbody>=postbody>=postbody>=postbody>=postbody> 9:分区

切换到超级用户:
sudo -sH

建立分区脚本:
mkdir /opt/mrtg
vim /opt/mrtg/mrtg.swap
#!/bin/bash
# This script to monitor the swap usage.
totalswap=`/usr/bin/free |grep Swap |awk '{pr $2}'`
usedswap=`/usr/bin/free |grep Swap |awk '{pr $3}'`
echo "$totalswap"
echo "$usedswap"


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

修改 /etc/mrtg.cfg 在文件最后加入
Target[swap]: `/opt/mrtg/mrtg.swap`
MaxBytes[swap]: 2048000
Title[swap]:Memory State of Server
ShortLegend[swap]: &
kmg[swap]:kB,MB
kilo[swap]:1024
YLegend[swap]: Swap Usage
Legend1[swap]: Total Swap
Legend2[swap]: Used Swap
LegendI[swap]: Total Swap
LegendO[swap]: Used Swap
Options[swap]: growright,gauge,nopercent
PageTop[swap]:<H1>Swap</H1>


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

访问:
http://localhost/mrtg/


=postbody>=postbody>=postbody>=postbody>=postbody>=postbody>=postbody>=postbody>=postbody>

原文链接:http://forum.ubuntu.org.cn/about8891.html



0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: