-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-inodes.sh
37 lines (27 loc) · 988 Bytes
/
check-inodes.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
#!/bin/sh
MOUNTPOINTS="${MOUNTPOINTS:-/var/lib/docker /data/var_lib_docker}"
THRESHOLD="${THRESHOLD:-50}"
FILTER="${FILTER:-unused-for=1h}"
SLEEP="${SLEEP:-600}"
REST_TIME="${REST_TIME:-900}"
IDENTIFIER="${IDENTIFIER:-$(hostname -s)}"
if [ ! -z "${HOST_IP}" ]; then
IDENTIFIER="${IDENTIFIER}:${HOST_IP}"
fi
PATH=$PATH:/usr/local/bin
sleep 60
while true; do
for MP in ${MOUNTPOINTS} ; do
if [ ! -d "${MP}" ]; then continue; fi
PERCENT="$(df --output=ipcent "${MP}" | tail -n 1 | sed 's|[^[:digit:]]*||g')"
if [ "${PERCENT}" -lt "${THRESHOLD}" ]; then
printf '[%s] inode usage %d%% for %s - No action taken\n' "${IDENTIFIER}" "${PERCENT}" "${MP}"
else
printf '[%s] inode usage %d%% for %s - Pruning\n' "${IDENTIFIER}" "${PERCENT}" "${MP}"
docker builder prune --force --filter "${FILTER}" 2>&1 | sed "s|^|[${IDENTIFIER}] |"
printf '[%s] prune finished\n' "${IDENTIFIER}"
sleep "${REST_TIME}"
fi
done
sleep "${SLEEP}"
done