快捷搜索:

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

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 #/etc/mrtg.cfg

(留意)假如仅仅监视一个IP地址采纳如下敕令:

cfgmaker public@192.168.0.1 >> /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]: CPU us;

LegendI[cpu]: CPU sy;

Title[cpu]: CPU Loading

PageTop[cpu]: CPU Loading

从新天生索引页面:

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

Title[ram]:Memory

ShortLegend[ram]: &

kmg[ram]:kB,MB

kilo[ram]:1024

YLegend[ram]: Memory Usage :

Legend1[ram]: Total Memory :

Legend2[ram]: Used Memory :

LegendI[ram]: Total Memory :

LegendO[ram]: Used Memory :

Options[ram]: growright,gauge,nopercent

PageTop[ram]:Memory

从新天生索引页面:

indexmaker /etc/mrtg.cfg > /var/www/mrtg/index.html

造访:

http://localhost/mrtg/

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

切换到超级用户:

sudo -sH

建立FTP脚本:

mkdir /opt/mrtg

vim /opt/mrtg/mrtg.ftp

#!/bin/bash

all=`netstat -a | grep ftp|awk '{print $5}'|sort | wc -l|awk '{print$1 - 1}'`

user=`netstat -a | grep ftp|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.ftp

改动 /etc/mrtg.cfg 在文件着末加入ftp项目

Target[ftp]: `/opt/mrtg/mrtg.ftp`

sudo -sH

建立硬盘读写脚本:

mkdir /opt/mrtg

vim /opt/mrtg/mrtg.disk

#!/bin/bash

hd=sda

disk=/dev/$hd

UPtime=`/usr/bin/uptime |awk '{print $3""$4""$5}'`

KBread_sec=`iostat -x $disk|grep $hd |awk '{print 8$}'`

KBwrite_sec=`iostat -x $disk|grep $hd |awk '{print 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]: Disk I/O Utilization Report

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]: Megabytes

ShortLegend[disk]: &

Options[disk]: growright,gauge,nopercent

从新天生索引页面:

indexmaker /etc/mrtg.cfg > /var/www/mrtg/index.html

造访:

http://localhost/mrtg/

八:磁盘应用

切换到超级用户:

sudo -sH

建立磁盘应用脚本:

mkdir /opt/mrtg

vim /opt/mrtg/mrtg.df

#!/usr/bin/perl

foreach $filesystem (`df -kl | grep -v "Filesystem"`)

您可能还会对下面的文章感兴趣: