-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_hadoop-dfs.sh
executable file
·120 lines (106 loc) · 2.82 KB
/
check_hadoop-dfs.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/sh
PROGNAME=`basename $0`
VERSION="Version 2.0,"
AUTHOR="2009, Mike Adolphs (http://www.matejunkie.com/)"
AUTHOR="2013, Florian Baumann (http://noqqe.de)"
ST_OK=0
ST_WR=1
ST_CR=2
ST_UK=3
print_version() {
echo "$VERSION $AUTHOR"
}
print_help() {
print_version $PROGNAME $VERSION
echo ""
echo "$PROGNAME is a Icinga plugin to check the status of HDFS, Hadoop's"
echo "underlying, redundant, distributed file system."
echo ""
echo "$PROGNAME -w 10 -c 5"
echo ""
echo "Options:"
echo " -w|--warning)"
echo " Defines the warning level for used space in percent"
echo " -c|--critical)"
echo " Defines the critical level for used space in percent"
exit $ST_UK
}
while test -n "$1"; do
case "$1" in
--help|-h)
print_help
exit $ST_UK
;;
--version|-v)
print_version $PROGNAME $VERSION
exit $ST_UK
;;
--warning|-w)
warning=$2
shift
;;
--critical|-c)
critical=$2
shift
;;
*)
echo "Unknown argument: $1"
print_help
exit $ST_UK
;;
esac
shift
done
check_sanity() {
if [ -n "$warning" -a -n "$critical" ]; then
if [ ${warning} -gt ${critical} ]; then
echo "ERR: Confusing warning and critical values"
exit $ST_UK
fi
if [ ${warning} -gt 100 ] && [ ${critical} -gt 100 ]; then
echo "ERR: Value above 100%? Rly?"
exit $ST_UK
fi
else
echo "ERR: Missing value, see --help"
exit $ST_UK
fi
if [ ! -x "$(which hdfs)" ]; then
echo "ERR: hdfs not installed"
exit $ST_UK
fi
}
get_vals() {
tmp_vals=`hdfs dfsadmin -report 2>/dev/null`
dfs_used=`echo -e "$tmp_vals" | grep -m1 "DFS Used:" | awk '{printf "%.2f\n", $3/1024/1024/1024/1024}'`
dfs_used_p=`echo -e "$tmp_vals" | grep -m1 "DFS Used%:" | awk '{print $3}'`
dfs_total=`echo -e "$tmp_vals" | grep -m1 "Present Capacity:" | awk '{printf "%.2f\n", $3/1024/1024/1024/1024}'`
perc=`echo $dfs_used_p |awk -F. '{print $1}'`
}
do_output() {
output="DFS total: ${dfs_total} TB, DFS used: ${dfs_used} TB (${dfs_used_p})"
}
do_perfdata() {
perfdata="'dfs_total'=${dfs_total} 'dfs_used'=${dfs_used}"
}
# Runtime
check_sanity
get_vals
do_output
do_perfdata
# Icinga plugin data
if [ -n "$warning" -a -n "$critical" ] ; then
if [ "$perc" -ge "$warning" -a "$perc" -lt "$critical" ] ; then
echo "WARNING - ${output} | ${perfdata}"
exit $ST_WR
elif [ "$perc" -ge "$critical" ]; then
echo "CRITICAL - ${output} | ${perfdata}"
exit $ST_CR
else
echo "OK - ${output} | ${perfdata} "
exit $ST_OK
fi
else
echo "OK - ${output} | ${perfdata}"
exit $ST_OK
fi