forked from xuyu23681/LinuxShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjiankongzhuji
32 lines (31 loc) · 1.34 KB
/
jiankongzhuji
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
# check_xu.sh
# 0 * * * * /home/check_xu.sh
DAT=”`date %Y%m%d`” #变量格式化时间
HOUR=”`date %H`”
DIR=”/home/oslog/host_${DAT}/${HOUR}” #定义一个目录等于
DELAY=60
COUNT=60 #计时器60
# whether the responsible directory exist
if ! test -d ${DIR} #如果test有这个目录
then
/bin/mkdir -p ${DIR} #否则创建这个目录
fi
# general check 内核检查
export TERM=linux
/usr/bin/top -b -d ${DELAY} -n ${COUNT} > ${DIR}/top_${DAT}.log 2>&1 &
# cpu check cpu检查
/usr/bin/sar -u ${DELAY} ${COUNT} > ${DIR}/cpu_${DAT}.log 2>&1 &
#/usr/bin/mpstat -P 0 ${DELAY} ${COUNT} > ${DIR}/cpu_0_${DAT}.log 2>&1 &
#/usr/bin/mpstat -P 1 ${DELAY} ${COUNT} > ${DIR}/cpu_1_${DAT}.log 2>&1 &
# memory check #内存检测
/usr/bin/vmstat ${DELAY} ${COUNT} > ${DIR}/vmstat_${DAT}.log 2>&1 &
# I/O check #I/O检查
/usr/bin/iostat ${DELAY} ${COUNT} > ${DIR}/iostat_${DAT}.log 2>&1 &
# network check #网络检查
/usr/bin/sar -n DEV ${DELAY} ${COUNT} > ${DIR}/net_${DAT}.log 2>&1 &
#/usr/bin/sar -n EDEV ${DELAY} ${COUNT} > ${DIR}/net_edev_${DAT}.log 2>&1 &
放在crontab里每小时自动执行
0 * * * * /home/check_xu.sh
这样会在/home/oslog/host_yyyymmdd/hh目录下生成各小时cpu、内存、网络,IO的统计数据。
监控硬盘存储空间是否大于90%,大于则发mail报警