-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathborderline.sh
executable file
·73 lines (66 loc) · 2.24 KB
/
borderline.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
#!/usr/bin/env bash
help() {
echo "Report borderline usage of resources"
echo ""
echo "Usage: ./borderline.sh [options]"
echo "Options:"
echo "-h, --help show this message"
echo "-m, --min-percentage define the minimum percentage of available resources (default: 15%)"
echo ""
}
: "${min_percentage:="15"}"
: "${failed:="0"}"
project_id=$(openstack token issue -f value -c project_id)
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
help
exit 0
;;
-m|--min-percentage)
min_percentage=$2
shift 2
;;
*)
echo "Invalid option $1"
help
exit 0
;;
esac
done
check_quotas() {
service=$1
echo "Checking quotas for ${service}:"
while IFS= read -r line;do
metric_name=$(echo "$line" | awk '{ print $1 }')
metric_inuse=$(echo "$line" | awk '{ print $2 }')
metric_reserved=$(echo "$line" | awk '{ print $3 }')
metric_limit=$(echo "$line" | awk '{ print $4 }')
if [[ "$metric_limit" -eq 0 ]]; then
echo " No quotas set for ${metric_name}"
continue
fi
if [[ "$metric_limit" -eq -1 ]]; then
echo " Unlimited quotas for ${metric_name}"
continue
fi
((metric_available=metric_limit-metric_reserved-metric_inuse))
((percentage_value=metric_available*100/metric_limit))
if [[ "$percentage_value" -eq 0 ]]; then
echo " CRITICAL: No more resource available for ${metric_name}"
failed=1
elif [[ "$percentage_value" -lt "$min_percentage" ]]; then
echo " WARNING: Only $percentage_value% of $metric_name are available"
failed=1
else
echo " Available resources for ${metric_name}: ${percentage_value}%"
fi
done < <(openstack quota list --detail --"$service" --project "${project_id}" -f value)
}
check_quotas compute
check_quotas network
if [[ "$failed" -eq 1 ]]; then
echo "Some resources have less than ${min_percentage}% available, actions should be taken!"
exit 11
fi
echo "No issue found, all resources have at least ${min_percentage}% of the total available"