分类:
2008-11-03 23:16:13
环境说明:服务器包括有:solaris,HPunix,linux,windows 共几十台
每天需要巡检系统两次,工作量比较大,希望通过现有资源实现巡检自动化。
实施办法:
统一巡检内容:CPU,内存,磁盘使用情况,数据库表空间使用情况,硬件状态是否正常,重要进程状态,系统log有无报错等 :采用统一log格式
cpu: %[0-9][0-9]
memory: %[0-9][0-9]
......................
实时办法:系统脚本功能,定时任务功能 ,部署一台ftp服务器
脚本功能说明:获取系统所需要信息,并处理成所要求格式文件
定时任务:定时执行脚本,产生log文件,再写一自动上传脚本,自动上传产生log文件
FTP服务器功能:除了ftp服务功能外,部署多mysql数据库,将格式化数据定时导入数据库
用户可方便通过数据库接口调用各系统状态信息
2009-4-8有一段时间没有上这博客了
solaris系统设计代码如下(具备良好扩展性)
包括:autocheck.sh (脚本说明:自动上传结果)
per_check.sh (执行检查的核心脚本,主要功能,调用各检查模块,并将检查结果格式化)
crontab定时:
#write by gyhong #(2008/11/04)
15 7,15 * * * /export/home/gyhong/autocheck.sh >> /export/home/gyhong/sys_check.log 2>&1
#end
代码如下 autocheck.sh
#!/bin/bash
#wirte by szwg_gyh9711
#date:20081103
PWD=/export/home/gyhong
export PWD
function autoftp()
{
local filename=$1
ftp -n <<- EOF
open 192.168.1.1
user szftp 123456
bin
prompt
put $filename
bye
EOF
}
cd /export/home/gyhong
datetime=`date +%Y%m%d_%T`
sys_name=`hostname`
ipaddress=`ifconfig -a | grep inet | awk 'NR==2 {print $2}'`
okfilename="${sys_name}_${ipaddress}_ok_${datetime}.log"
nofilename="${sys_name}_${ipaddress}_no_${datetime}.log"
#start per_check.sh
echo "=====[`date +%Y%m%d_%T`]---> per_check.sh======="
#执行检查
/export/home/gyhong/per_check.sh > /export/home/gyhong/$okfilename
#上传检查结果文件
autoftp $okfilename
if [ $? -eq 0 ]; then
echo "[`date +%Y%m%d_%T`] ftp $okfilename----OK"
rm /export/home/szwg/$okfilename
fi
per_check代码如下:(只放上检查CPU,内存,磁盘脚本,其它略)
#static parameter
system="TD"
datetime=`date "+%Y-%m-%d %T"`
ipaddress=`ifconfig -a | grep inet | awk 'NR==2 {print $2}'`
hostname="`hostname`"
hardmemory=32768
#get cpu mem performance
message=`vmstat 2 2 | awk 'NR==4'`
cpu=`echo ${message} | awk '{printf("%4.2f",$20+$21)}'`
memory=`echo ${message} | cut -d" " -f5`
memory=`echo "${memory} ${hardmemory}" | awk '{ printf("%4.2f",($2-$1/1024)/$2*100)}'`
#output cpu message
echo "${system}#${ipaddress}#${hostname}#2.1.1#CPU#${cpu}#${datetime}#null"
#output memory message
echo "${system}#${ipaddress#}#${hostname}#2.1.2#MEMORY#${memory}#${datetime}#null"
#system storage use message
datetime=`date "+%Y-%m-%d %T"`
df -h | awk 'NR>1'> /export/home/gyhong/df.log
while read one two there four five six
do
echo "${system}#${ipaddress#}#${hostname}#2.1.3#${six}#`echo ${five} | cut -d% -f1`#${datetime}#$two"
done < /export/home/gyhong/df.log
rm /export/home/gyhong/df.log
#get database message
datetime=`date "+%Y-%m-%d %T"`
/export/home/gyhong/data_oracle.sh | awk '(NR > 9){printf("%s\t%4.2f\t%sM\n",$1,$4,$2)}' | egrep -v "Disconn|With|JServer"> /export/home/gyhong/oracle.log
while read one two there
do
echo "${system}#${ipaddress#}#${hostname}#3.2.1#${one}#${two}#${datetime}#${there}"
done < /export/home/gyhong/oracle.log
rm /export/home/gyhong/oracle.log
windows系统检查
提示:可直接通过wmic实现
另外FTP上传功能同unix