-
Notifications
You must be signed in to change notification settings - Fork 44
/
ovn-pods-memory-usage
executable file
·46 lines (39 loc) · 1.28 KB
/
ovn-pods-memory-usage
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
#!/usr/bin/env bash
# description: Checks if the memory usage of the OVN pods is under the LIMIT threshold
[ -z ${UTILSFILE} ] && source $(echo "$(dirname ${0})/../utils")
error=false
if oc auth can-i adm top -A >/dev/null 2>&1; then
LIMIT="${OVN_MEMORY_LIMIT:=5000}"
FLAG=0
pods_memory_usage=$(oc adm top pod -n openshift-ovn-kubernetes -l app=ovnkube-node --no-headers | awk '{ print $1 " " $3 }' | awk '{$2 = substr($2,0,length($2)-2)} 1')
MESSAGE=""
OLDIFS=${IFS}
IFS=$'\n'
for pod_line in ${pods_memory_usage}; do
pod_name=$(echo $pod_line | awk '{ print $1 }')
pod_size=$(echo $pod_line | awk '{ print $2 }')
if [[ ${pod_size} -ge ${LIMIT} ]]; then
MESSAGE="${MESSAGE}The OVN pod memory usage for ${pod_name} is extremely high: ${RED}${pod_size}${NOCOLOR}Mi\n"
FLAG=1
fi
done
IFS=${OLDIFS}
if [[ ${FLAG} -ne 0 ]]; then
MESSAGE="${MESSAGE}For more information you can check the KCS https://access.redhat.com/solutions/6493321\n"
msg "${MESSAGE}"
errors=$(("${errors}" + 1))
error=true
fi
if [ ! -z "${ERRORFILE}" ]; then
echo $errors >${ERRORFILE}
fi
if [[ $error == true ]]; then
exit ${OCERROR}
else
exit ${OCOK}
fi
else
msg "Couldn't adm top pods, check permissions"
exit ${OCSKIP}
fi
exit ${OCUNKNOWNN}