9394952

导航

snmp安装[freebsd+redhat]+采集脚本

===============freebsd服务器====================================================

安装snmp服务
#cd /usr/ports/net-mgmt/net-snmp
#make
#make install
安装成功后
#vi /etc/rc.conf
添加
snmpd_enable="YES"
snmpd_flags="-a -p /var/run/snmpd.pid"
snmptrapd_enable="YES"
snmptrapd_flags="-a -p /var/run/snmptrapd.pid"
#/etc/netstart
修改snmpd.conf
#vi /usr/local/share/snmp/snmpd.conf  需要添加如下语句
rocommunity [ID] [ip]  采集服务器地址
exec .1.3.5.1.4.1.2021.52 game /bin/sh /home/zcy/game.sh
启动服务
#/usr/local/etc/rc.d/snmpd.sh start

#snmpdwalk -v 1  -c [ID] localhost 看是否有返回值

安装bsdsar
安装bsdsar这个程序来显示cpu的使用状态
cd /usr/ports/sysutils/bsdsar/
make install
修改/etc/crontab
# bsdsar execution
*/5 * * * * root /usr/local/bin/bsdsar_gather
0 0 * * * /bin/rm /var/log/bsdsar.dat
%~!*@#&#&注意存档/var/log/bsdsar.dat 不断增加我这里删除了每天凌晨
 
 
添加脚本
#cd /home
#mkdir zcy
#vi game.sh
#############log####################
cpulog=/home/zcy/tmp/bsdcpu.tmp
netlog=/home/zcy/tmp/bsdnet.tmp
memlog=/home/zcy/tmp/bsdmem.tmp

#############cpu####################
cpu_orig=`/usr/local/bin/bsdsar -u > $cpulog`
cpu_str=`/usr/bin/tail -1 $cpulog | awk '{print $6}'`
#############mem####################
mem_orig=`/usr/local/bin/bsdsar -r > $memlog`
mem_str=`/usr/bin/tail -1 $memlog | awk '{print $2}'`

#############net####################
net_orig=`/usr/local/bin/bsdsar -I | grep em0> $netlog`
 
net_in=`/usr/bin/tail -1 $netlog | awk '{print $4}'`
net_out=`/usr/bin/tail -1 $netlog | awk '{print $7}'`

############disk####################
disktmp=/home/zcy/tmp/disk.tmp
df -k > $disktmp
disk1=`cat $disktmp | awk 'NR==2 {print $6}'`
disk2=`cat $disktmp | awk 'NR==3 {print $6}'`
disk3=`cat $disktmp | awk 'NR==4 {print $6}'`
disk4=`cat $disktmp | awk 'NR==5 {print $6}'`
disk5=`cat $disktmp | awk 'NR==6 {print $6}'`
disk6=`cat $disktmp | awk 'NR==7 {print $6}'`
disk1use=`cat $disktmp | awk 'NR==2 {print $5}'`
disk2use=`cat $disktmp | awk 'NR==3 {print $5}'`
disk3use=`cat $disktmp | awk 'NR==4 {print $5}'`
disk4use=`cat $disktmp | awk 'NR==5 {print $5}'`
disk5use=`cat $disktmp | awk 'NR==6 {print $5}'`
disk6use=`cat $disktmp | awk 'NR==7 {print $5}'`

############gse######################
topsys=/home/zcy/tmp/top.tmp
top -d 1  > $topsys
gsecpu=`cat $topsys | grep GSE |awk  '{print $11}'`
gsemem=`cat $topsys | grep GSE |awk  '{print $7}'`
############print####################
echo $cpu_str"%"
 
 

=======================redhat==========================================================
安装snmp服务
ftp://rpmfind.net/linux/sourceforge/n/ne/net-snmp/net-snmp-5.2.2-1.EL4.i386.rpm
安装net-snmp的rpm包 net-snmp-5.2.2-1.EL4.i386.rpm
#rpm -ivh  net-snmp-5.2.2-1.EL4.i386.rpm
安装后启动/usr/sbin/snmpd -c /etc/snmp/snmpd.conf

这里snmpd.conf如下[snmpd.conf]redhat附
 
#snmpdwalk -v 1  -c [ID] localhost 看是否有返回值

添加脚本
#cd /home
#mkdir zcy
#vi game.sh
===========================================cpumemgesdiskinout.shell===================================
 
topsys=/home/zcy/tmp/top.tmp

top -n 1 b > $topsys
cpu=`cat $topsys | awk  '/^(Cpu)/{print $8}'`
memf=`free | awk  '/^(Mem)/{print $4}'`
#memt=`free | awk '/^(Mem)/{print $2}'`
gsecpu=`cat $topsys | awk  'NR==10 {print $9}'`
gsemem=`cat $topsys | awk  'NR==10  {print $10}'`
 

disk1=/
disk2=/data
disk1use=`df -k | awk 'NR==2 {print $5}'`
disk2use=`df -k | awk 'NR==3 {print $5}'`
 
infirst=$(awk '/'eth0'/{print $1 }' /proc/net/dev |sed 's/'eth0'://')
outfirst=$(awk '/'eth0'/{print $9 }' /proc/net/dev |sed 's/'eth0'://')
sumfirst=$(($infirst+$outfirst))
sleep 1
inend=$(awk '/'eth0'/{print $1 }' /proc/net/dev |sed 's/'eth0'://')
outend=$(awk '/'eth0'/{print $9 }' /proc/net/dev |sed 's/'eth0'://')
in=$(($inend-$infirst))
out=$(($outend-$outfirst))
===========================================================================================================
!!!保存后执行看输出结果!!!
92% 843096K GES:23.49%,224M /,36%,/dev,100%,/home,1%,/tmp,0%,/usr,12%,/var,0% 67649,22566
!!!如有问题校对相应位置!!!
结束!!
 

posted on 2007-08-02 09:18  9394952  阅读(181)  评论(0编辑  收藏  举报