監控硬碟空間指令碼
監控硬碟空間指令碼(請指正)
近日,公司要求對磁碟空間進行監控,編寫了以下指令碼。希望大家指正,並且幫助我完善此指令碼。
目標:
監控20臺Linux伺服器的硬碟空間,如果超過一定限度,發報警信給系統管理員.
思路:
指令碼分為兩大部分
1. client
功能:
收集資料: chkfs-client.sh (將每臺機器的資料定時蒐集到指定路徑)
上傳資料: autoftp.sh (定時上傳到monitor server)
2.server
功能:
分析資料:chkfs-server.sh (分析各臺主機傳送來的資料)
傳送報警信:send_msg (超過threshold時,自動發信)
chkfs-client.sh
#!/bin/bash
host=`uname -n`
m=`date +%m`
d=`date +%d`
log=/tmp/monitor/$host.df.${m}${d}.txt
rm -f /tmp/monitor/*.df.*.txt
df -k |grep -i -v "Use" |awk {'print $5$6'} > $log
autoftp.sh
#!/bin/bash
#Purpose: upload files to the monitor server
#Author: Kevin Zhang (kevincszhang at gmail dot com)
#Licence: GPL
#History:
#/11/10/2007: 1st edition
user=upload
passwd=upload
ftp -n << !
open ip_address_of_monitor_server
user $user $passwd
binary
prompt off
lcd /tmp/monitor
cd /tmp/monitor/chkdu
put *.du.*
cd /tmp/monitor/chkfs
put *.df.*
close
bye
!
chkfs-server.sh
#!/bin/bash
#Purpose: Periodically check the file system of server #
#Author: Kevin Zhang ( kevincszhang at gmail dot com) #
#Licence: GPL #
#History: #
#/11/10/2007: 1st edition #
#########################################################################
bin=/root/sysadmin/server/chkfs
log=/tmp/monitor/chkfs
file=${log}/grcntj0
usedfs=${log}/usedfs.txt
date=`date +%m-%d-%H`
#### checking whether old file exists. if so, remove it.
(
if [ -f ${log}/chkfs.alarm.${date}.txt ]; then
rm -f ${log}/chkfs.alarm.${date}.txt
fi
#### starting to check file systems
cc=1
while [ $cc -le 10 ]
do
if [ -f ${file}${cc}.df.${date}.txt ]; then
cat ${file}${cc}.df.${date}.txt > ${usedfs}
l=`cat ${bin}/filesystem.txt |wc -l`
c=1
while [ $c -le $l ]
do
fs=`awk 'NR == i {print $1}' i=$c ${bin}/filesystem.txt`
b_limit=`awk 'NR == i {print $2}' i=$c ${bin}/filesystem.txt`
b_used=`cat ${usedfs} |grep "${fs}$" |awk 'BEGIN {FS = "%"} {print $1}'`
host=`echo "${file}${cc}" | cut -c 20-`
if [ ${b_used} -ge ${b_limit} ]; then
echo -e "\n\nWARNING - block usage of filesystem $fs on host $host is now ${b_used}%. It has exceeded the ${b_limit}% threshold. \n\nATTENTION IT team:\nPls check it immediately.\nThank You.\n\n\n" >> ${log}/chkfs.alarm.${date}.txt
fi
c=` expr $c + 1 `
done
fi
cc=` expr $cc + 1`
done
rm -f ${log}/*.df.*
rm -f ${usedfs}
#### sending alarm message to the corresponding sysadmin
TO="123@163.com, [email]234@163.com[/email]"
SUBJECT="Filesystem Alarm - IT team, pls take action!"
MESSAGE="${log}/chkfs.alarm.${date}.txt"
CC="567@163.com"
BCC=""
if [ -s ${log}/chkfs.alarm.${date}.txt ]; then
echo "send alarm information to system administrator."
${bin}/send_msg "$TO" "$SUBJECT" "$MESSAGE" "$CC" "$BCC"
fi
) > ${log}/chk_filesystem.${date}.log 2>&1
send_msg
#SENDMAIL="/usr/lib/sendmail -oi -t"
#SENDMAIL="/usr/bin/mailx"
#hostname="$6"
#FROM="$hostname"
SUBJECT="$2"
TO="$1"
MESSAGE="$3"
CC="$4"
BCC="$5"
#
/bin/cat ${MESSAGE} | /usr/bin/mailx "$TO" -s "$SUBJECT" -c "$CC" -b "$BCC"
filesystem.txt 設定threshold
/ 80
/home 80
/usr 80
/var 80
近日,公司要求對磁碟空間進行監控,編寫了以下指令碼。希望大家指正,並且幫助我完善此指令碼。
目標:
監控20臺Linux伺服器的硬碟空間,如果超過一定限度,發報警信給系統管理員.
思路:
指令碼分為兩大部分
1. client
功能:
收集資料: chkfs-client.sh (將每臺機器的資料定時蒐集到指定路徑)
上傳資料: autoftp.sh (定時上傳到monitor server)
2.server
功能:
分析資料:chkfs-server.sh (分析各臺主機傳送來的資料)
傳送報警信:send_msg (超過threshold時,自動發信)
chkfs-client.sh
#!/bin/bash
host=`uname -n`
m=`date +%m`
d=`date +%d`
log=/tmp/monitor/$host.df.${m}${d}.txt
rm -f /tmp/monitor/*.df.*.txt
df -k |grep -i -v "Use" |awk {'print $5$6'} > $log
autoftp.sh
#!/bin/bash
#Purpose: upload files to the monitor server
#Author: Kevin Zhang (kevincszhang at gmail dot com)
#Licence: GPL
#History:
#/11/10/2007: 1st edition
user=upload
passwd=upload
ftp -n << !
open ip_address_of_monitor_server
user $user $passwd
binary
prompt off
lcd /tmp/monitor
cd /tmp/monitor/chkdu
put *.du.*
cd /tmp/monitor/chkfs
put *.df.*
close
bye
!
chkfs-server.sh
#!/bin/bash
#Purpose: Periodically check the file system of server #
#Author: Kevin Zhang ( kevincszhang at gmail dot com) #
#Licence: GPL #
#History: #
#/11/10/2007: 1st edition #
#########################################################################
bin=/root/sysadmin/server/chkfs
log=/tmp/monitor/chkfs
file=${log}/grcntj0
usedfs=${log}/usedfs.txt
date=`date +%m-%d-%H`
#### checking whether old file exists. if so, remove it.
(
if [ -f ${log}/chkfs.alarm.${date}.txt ]; then
rm -f ${log}/chkfs.alarm.${date}.txt
fi
#### starting to check file systems
cc=1
while [ $cc -le 10 ]
do
if [ -f ${file}${cc}.df.${date}.txt ]; then
cat ${file}${cc}.df.${date}.txt > ${usedfs}
l=`cat ${bin}/filesystem.txt |wc -l`
c=1
while [ $c -le $l ]
do
fs=`awk 'NR == i {print $1}' i=$c ${bin}/filesystem.txt`
b_limit=`awk 'NR == i {print $2}' i=$c ${bin}/filesystem.txt`
b_used=`cat ${usedfs} |grep "${fs}$" |awk 'BEGIN {FS = "%"} {print $1}'`
host=`echo "${file}${cc}" | cut -c 20-`
if [ ${b_used} -ge ${b_limit} ]; then
echo -e "\n\nWARNING - block usage of filesystem $fs on host $host is now ${b_used}%. It has exceeded the ${b_limit}% threshold. \n\nATTENTION IT team:\nPls check it immediately.\nThank You.\n\n\n" >> ${log}/chkfs.alarm.${date}.txt
fi
c=` expr $c + 1 `
done
fi
cc=` expr $cc + 1`
done
rm -f ${log}/*.df.*
rm -f ${usedfs}
#### sending alarm message to the corresponding sysadmin
TO="123@163.com, [email]234@163.com[/email]"
SUBJECT="Filesystem Alarm - IT team, pls take action!"
MESSAGE="${log}/chkfs.alarm.${date}.txt"
CC="567@163.com"
BCC=""
if [ -s ${log}/chkfs.alarm.${date}.txt ]; then
echo "send alarm information to system administrator."
${bin}/send_msg "$TO" "$SUBJECT" "$MESSAGE" "$CC" "$BCC"
fi
) > ${log}/chk_filesystem.${date}.log 2>&1
send_msg
#SENDMAIL="/usr/lib/sendmail -oi -t"
#SENDMAIL="/usr/bin/mailx"
#hostname="$6"
#FROM="$hostname"
SUBJECT="$2"
TO="$1"
MESSAGE="$3"
CC="$4"
BCC="$5"
#
/bin/cat ${MESSAGE} | /usr/bin/mailx "$TO" -s "$SUBJECT" -c "$CC" -b "$BCC"
filesystem.txt 設定threshold
/ 80
/home 80
/usr 80
/var 80
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23757700/viewspace-696540/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 監控oracle表空間指令碼Oracle指令碼
- oracle空間使用監控指令碼Oracle指令碼
- Sybase空間監控指令碼 btmbfe_sybase_space_use.sh指令碼
- 自動監控Oracle 表空間資訊併傳送郵件指令碼Oracle指令碼
- 監控指令碼指令碼
- mysql監控指令碼MySql指令碼
- DBA監控指令碼指令碼
- session指令碼監控Session指令碼
- 埠監控指令碼指令碼
- oracle 監控指令碼Oracle指令碼
- oracle表空間增加監控Oracle
- listener監聽監控指令碼指令碼
- 【SQL監控】SQL完全監控的指令碼SQL指令碼
- 單個指令碼監控主機上所有例項的表空間利用率指令碼
- 表空間監控(三)tablespace detailAI
- linux 下監控磁碟空間Linux
- ogg監控指令碼指令碼
- stap監控IO指令碼指令碼
- 【shell】磁碟監控指令碼指令碼
- mysql 的一個監控指令碼,監控heartbeatMySql指令碼
- window 硬碟監控硬碟
- mysql mon 的一個監控指令碼,監控heartbeatMySql指令碼
- 表空間監控(二)datafile size detailAI
- AIX分頁(交換)空間的監控AI
- PostgreSQL之鎖監控指令碼SQL指令碼
- Oracle DBA常用監控指令碼Oracle指令碼
- memcached程式埠監控指令碼指令碼
- Nagios 監控ESXI指令碼iOS指令碼
- 監控cpu與memory指令碼指令碼
- 資料庫監控指令碼資料庫指令碼
- (Datagurad)監控指令碼指令碼
- 監控session數量指令碼Session指令碼
- 監控sqlldr執行指令碼SQL指令碼
- 監控資料庫指令碼資料庫指令碼
- cacti自定義監控指令碼指令碼
- Linux發郵件磁碟空間監控Linux
- oracle監控表空間,JOB,rman備份Oracle
- 監控系統告警指令碼集合指令碼