監控硬碟空間指令碼
監控硬碟空間指令碼(請指正)
近日,公司要求對磁碟空間進行監控,編寫了以下指令碼。希望大家指正,並且幫助我完善此指令碼。
目標:
監控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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【shell】磁碟監控指令碼指令碼
- PostgreSQL之鎖監控指令碼SQL指令碼
- 監控系統告警指令碼集合指令碼
- Hbase刪除名稱空間指令碼指令碼
- Shell 系統資訊監控指令碼指令碼
- 監控磁碟使用率的shell指令碼指令碼
- 網路卡流量監控指令碼,python實現指令碼Python
- centos 監控web站點是否500 指令碼CentOSWeb指令碼
- shell指令碼:監控MySQL服務是否正常指令碼MySql
- Shell指令碼監控MySQL主從狀態指令碼MySql
- linux系統 物理硬碟監控Linux硬碟
- shell指令碼監控啟動停止weblogic服務指令碼Web
- 關於前端指令碼異常監控的思考前端指令碼
- 查詢表空間使用情況的指令碼指令碼
- Oracle 建立表空間和使用者指令碼Oracle指令碼
- 硬碟空間的管理和分割槽硬碟
- Linux伺服器硬碟空間清理Linux伺服器硬碟
- 雲空間影片監控的可擴充套件性:適應不斷增長的監控需求套件
- 在 Linux 上用 Bash 指令碼監控 messages 日誌Linux指令碼
- 使用Shell指令碼程式監控網站URL是否正常指令碼網站
- 寫了個監控 ElasticSearch 程式異常的指令碼!Elasticsearch指令碼
- 64位win10多大硬碟空間合適_64位win10支援多大硬碟空間Win10硬碟
- 透過shell指令碼監控日誌切換頻率指令碼
- 基於Ping和Telnet/NC的監控指令碼案例分析指令碼
- zabbix-mongodb監控指令碼(高效能、低佔用)MongoDB指令碼
- 雲空間技術在影片監控中的隱私保護策略
- 磁硬碟陣列後如何檢測和監控硬碟健康狀況?硬碟陣列
- MySQL 5.6大查詢和大事務監控指令碼(Python 2)MySql指令碼Python
- 分享實用監控指令碼:使用Shell檢查程式是否存在指令碼
- 利用 Shell 指令碼來監控 Linux 系統的記憶體指令碼Linux記憶體
- 用於自動監控磁碟使用情況的 Shell 指令碼指令碼
- 正常執行時間監控
- 直播間截留監控系統
- sqlserver監控指令碼_發現某個等待就發出郵件SQLServer指令碼
- 用 Bash 指令碼監控 Linux 上的記憶體使用情況指令碼Linux記憶體
- PowerShell 指令碼來監控 CPU、記憶體和磁碟使用情況:指令碼記憶體
- 如何用bash shell 指令碼監控 Linux記憶體、磁碟和 CPU?指令碼Linux記憶體
- mac硬碟空間怎麼清理?這樣也能清理出上10G的磁碟空間Mac硬碟
- 一文帶你瞭解 WGCLOUD 監控硬碟故障 SMARTGCCloud硬碟