Last active
April 10, 2019 03:59
-
-
Save JackyYin/f6475cc0bb6c29a0254911fc6d93d4f9 to your computer and use it in GitHub Desktop.
檢查硬碟空間, 並清除prometheus docker volume
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
usage() | |
{ | |
echo "" | |
echo "Usage: $0 [ -d ][ -p ] " | |
echo -e "\t-d desired docker disk path" | |
echo -e "\t-p desired project path" | |
} | |
while getopts "hp:d:?" opt | |
do | |
echo $opt; | |
case $opt in | |
h) | |
usage | |
exit 1 | |
;; | |
d) | |
echo "-d was triggered with $OPTARG" | |
DISK_PATH=$OPTARG; | |
;; | |
p) | |
echo "-p was triggered with $OPTARG" | |
PROJECT_PATH=$OPTARG; | |
;; | |
?) | |
echo "Invalid option: -$OPTARG" | |
exit 1 | |
;; | |
esac | |
done | |
# default flag value | |
if [[ -z $DISK_PATH ]]; then | |
DISK_PATH="/dev/mapper/centos-root"; | |
fi | |
if [[ -z $PROJECT_PATH ]]; then | |
PROJECT_PATH="/opt/prometheus"; | |
fi | |
REMAIN_DISK=`df -h | grep $DISK_PATH | awk '{print 100 - $5 }'`; | |
echo "Remained Disk Space: ${REMAIN_DISK}%"; | |
if [[ $REMAIN_DISK < 70 ]]; then | |
echo "Start Cleaning..."; | |
cd $PROJECT_PATH && docker-compose down && docker volume ls -q | grep -v prometheus_grafana-storage | xargs -n1 -I{} docker volume rm {} && docker-compose up -d; | |
else | |
echo "Nothing to do..."; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment