-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhdfscheck.sh
45 lines (40 loc) · 1.01 KB
/
hdfscheck.sh
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
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env bash
OVERUSE=75
CHECK_INTVL=180
function WARN() {
echo "`date "+%Y-%m-%d %H:%M:%S"` [WARN] ""$@"
}
function usage() {
cat << endl
Usage: $(basename "$0")
[-over OVERUSE] #warn after hdfs usage goes beyond OVERUSE, in percent
[-intvl CHECK_INTVL] #check interval, in seconds
[-help]
endl
}
while [ $# -gt 0 ]; do
case "$1" in
-help)
usage; exit 0;;
-over)
shift;OVERUSE=$1;;
-intvl)
shift;CHECK_INTVL=$1;;
*)
echo "Uknown option $1"
usage; exit -1;;
esac
shift
done
while [[ true ]]; do
SUM=0
if [ "${OVERUSE}" != "" ]; then
for us in `hadoop dfsadmin -report | egrep "^DFS Used%: " | sed 's/DFS Used%: //' | egrep -o '^[0-9]+'`; do
[ $us -ge $OVERUSE ] && SUM=$(( $SUM + 1))
done
fi
DEADNODE=`hadoop dfsadmin -report | egrep "^Datanodes available: " | egrep -o "[0-9]+ dead" | awk '{print $1}'`
[ "${SUM}" != "0" ] && WARN "${SUM} nodes are hdfs over-used by ${OVERUSE}"
[ "${DEADNODE}" != "0" ] && WARN "${DEADNODE} nodes is dead"
sleep ${CHECK_INTVL}
done