Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1151133
  • 博文数量: 188
  • 博客积分: 2267
  • 博客等级: 大尉
  • 技术积分: 1907
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-01 11:17
文章分类

全部博文(188)

文章存档

2016年(16)

2015年(16)

2014年(12)

2013年(32)

2012年(45)

2011年(67)

分类: LINUX

2013-01-23 17:01:08

安装snmp

yum install net-snmp net-snmp-utils -y

配置snmp

vim /etc/snmp/snmpd.conf

替换

com2sec notConfigUser  default       public

com2sec local     localhost           public

com2sec mynetwork 192.168.1.0/24      public

 

替换

group   notConfigGroup v1           notConfigUser

group   notConfigGroup v2c           notConfigUser

group MyRWGroup v1         local

group MyRWGroup v2c        local

group MyRWGroup usm        local

group MyROGroup v1         mynetwork

group MyROGroup v2c        mynetwork

group MyROGroup usm        mynetwork

 

 

替换

view    systemview     included      system

view all    included  .1                               80

 

 

替换

access  notConfigGroup ""      any       noauth    exact  systemview none none

access MyROGroup ""      any       noauth    exact  all    none   none

access MyRWGroup ""      any       noauth    exact  all    all    none

 

替换

syslocation Unknown (edit /etc/snmp/snmpd.conf)

syscontact Root  (configure /etc/snmp/snmp.local.conf)

syslocation RHEL6, Home Linux Router.

syscontact Vivek G Gite <10887272@QQ.COM>

 

 

/etc/init.d/snmpd start

chkconfig snmpd on

 snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex

#IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1

#IP-MIB::ipAdEntIfIndex.192.168.1.5 = INTEGER: 2

安装MRTG

mkdir /opt/nginx/mrtg /

ln -s /opt/nginx/mrtg /opt/nginx/static/mrtg

yum -y install mrtg

 

cp -a /var/www/mrtg/* /opt/nginx/mrtg/

cfgmaker --global 'WorkDir: /opt/nginx/static/mrtg' --output /etc/mrtg/mymrtg.cfg public@localhost

indexmaker --output=/opt/nginx/static/mrtg/index.html /etc/mrtg/mymrtg.cfg

 

执行三次

env LANG=C /usr/bin/mrtg /etc/mrtg/mymrtg.cfg

然后就可以通过web方式访问mrtg的界面了

crontab -e

*/5 * * * * /usr/bin/mrtg /etc/mrtg/mymrtg.cfg --logging /var/log/mrtg.log

 

配置MRTG

添加以下内容到/etc/mrtg/mymrtg.cfg

################CPU######################

Target[cpu]: `/opt/mrtg/cpu.sh`

MaxBytes[cpu]: 100

Title[cpu]:  CPU --hongpan

Options[cpu]: gauge,nopercent,growright

YLegend[cpu]: CPU loading (%)

ShortLegend[cpu]:%

LegendO[cpu]: & CPU USER;

LegendI[cpu]: & CPU SYSTEM;

PageTop[cpu]:

CPU负载

 

############### MEM   8G   #################

Target[managemem]:`/opt/mrtg/mem.sh`

Unscaled[managemem]: dwym

MaxBytes[managemem]: 8192000

Title[managemem]:Memory

ShortLegend[managemem]: &

kmg[managemem]:kB,MB

kilo[managemem]:1024

YLegend[managemem]: Memory Usage

Legend1[managemem]: Total Memory

Legend2[managemem]: Used Memory

LegendI[managemem]: Total Memory

LegendO[managemem]: Used Memory

Options[managemem]: growright,gauge,nopercent

PageTop[managemem]:

内存使用

 

################## Disk I/O 100K/sec   /DEV/SDA   ##########

# If you want monitor more disk, please copy below create

# now monitor job, and copy & modify the diskperf.sh to setting disk.

Target[diskIO]: `/opt/mrtg/diskperf.sh`

Title[diskIO]: Disk HDA I/O Utilization Report

Unscaled[diskIO]: dwym

MaxBytes[diskIO]: 10000

PageTop[diskIO]:

磁盘I/O

kmg[diskIO]: KB,MB,GB

LegendI[diskIO]: Disk I/O KBread/sec

LegendO[diskIO]: Disk I/O KBwrite/sec

Legend1[diskIO]: Disk I/O KBread/sec

Legend2[diskIO]: Disk I/O KBwrite/sec

YLegend[diskIO]:   Megabytes

ShortLegend[diskIO]: &

Options[diskIO]: growright,gauge,nopercent

 

 

###虹盘在线人数##############

Target[tsai.adsldns.org_person]: `/opt/mrtg/person.sh`

MaxBytes[tsai.adsldns.org_person]: 5000

Options[tsai.adsldns.org_person]: gauge, nopercent, growright

YLegend[tsai.adsldns.org_person]: Online Users

ShortLegend[tsai.adsldns.org_person]: %

LegendI[tsai.adsldns.org_person]:  

LegendO[tsai.adsldns.org_person]:  

Title[tsai.adsldns.org_person]: WWW 上線人數統計表

PageTop[tsai.adsldns.org_person]:

虹盘在线人数

#

  

#  

#

System:Aerosol Lab. in Redhat 6.1 Kernel 2.2.18
Maintainer: VBird

################### Swap   16G #######################

Target[swap]:`/opt/mrtg/swap.sh`

Unscaled[swap]: dwym

MaxBytes[swap]: 16384000

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

交换分区

 

 

 

脚本文件

# cat /opt/mrtg/cpu.sh

#!/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

 

 

# cat /opt/mrtg/diskperf.sh

#!/bin/bash

# This script will monitor the KBread/sec &KBwriten/sec of Disk, and sent out the Blk_read/s and Blk_wrtn/s to MRTG, to make the performance image.

# Creater: CCC IT loren   ext:2288 2005/8/3

# Set the who need monitor device. As sda ,sdb,sdc,sdd,hda.

# disk=sda

hd=hda

disk=/dev/$hd

#UPtime=`/usr/bin/uptime |awk '{print """"}'`

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

KBwrite_sec=`iostat -x $disk|grep $hd |awk '{print $7 }'`

echo "$KBread_sec"

echo "$KBwrite_sec"

 

# cat /opt/mrtg/mem.sh

#!/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}'`

echo "$totalmem"

echo "$usedmem"

 

 

# cat /opt/mrtg/person.sh

#!/bin/bash

# 1. 計算連線的數目

echo `netstat -a | grep http|awk '{print $5}'|sort | wc -l|awk '{print$1 - 1}'`

# 底下在說明整個咚咚的列出(檢查用) 

# netstat -a | grep www|awk '{print $5}'|sort| uniq

 

# 2. 計算連線人數:

echo `netstat -a | grep http|awk '{print $5}'|cut -d":" -f1|sort| uniq |wc -l | awk '{print $1 - 1}'`

# netstat -a | grep www|awk '{print $5}'|cut -d":" -f1|sort| uniq

 

# 3. 輸出時間咚咚

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

 

# cat /opt/mrtg/swap.sh

#!/bin/bash

# run this script to check the swap usage.

totalswap=`/usr/bin/free |grep Swap |awk '{print }'`

usedswap=`/usr/bin/free |grep Swap |awk '{print }'`

echo "$totalswap"

echo "$usedswap"

 

 

 

常见问题

修改了配置文件/etc/mrtg/mymrtg.cfg ,网页没有生效

indexmaker  -output=/opt/nginx/static/mrtg/index.html  -title=ceshi.hongpan /etc/mrtg/mymrtg.cfg

 

mrtg.cfg 里面几个参数的意思.

Target:是要执行的脚本

Xsize:生成图表的横向宽度(最大600

Ysize:生成图表的纵向高度(最大200

Title:标题

kMG: Change the default multiplier prefixes

Ytics:纵向划分为几个块(格子)

MaxBytes:图表纵向数值的最大上限

PageTop:页面上面的提示

kilo:一般是写1024,如果需要的话,是1000在计算机里的单位

LegendI:从SHELL返回的数据中的第一个

LegendO:从SHELL返回的数据中的第二个

Options growright,表示图表向右延展

阅读(1243) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~