2015-02-06 23:06:37 +01:00
|
|
|
#! /usr/bin/env sh
|
|
|
|
|
|
|
|
#############################################################################
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
#
|
|
|
|
#############################################################################
|
|
|
|
|
|
|
|
#### Colors definition
|
|
|
|
BLACK='\033[30;40m'
|
|
|
|
RED='\033[0;31m'
|
|
|
|
REDB='\033[1;31m'
|
|
|
|
GREEN='\033[1;32m'
|
|
|
|
YELLOW='\033[1;33m'
|
|
|
|
BLUE='\033[34;40m'
|
|
|
|
MAGENTA='\033[0;35m'
|
|
|
|
CYAN='\033[36;40m'
|
|
|
|
WHITE='\033[0;37m'
|
|
|
|
WHITEB='\033[1;37m'
|
|
|
|
RESET='\033[0m'
|
|
|
|
|
|
|
|
|
2015-08-29 09:22:59 +02:00
|
|
|
printf '%b' "${MAGENTA}++++++++++++++++++++: ${WHITE}Disk Usage${RESET} ${MAGENTA}:+++++++++++++++++++++${RESET}"
|
2015-02-06 23:06:37 +01:00
|
|
|
# Root partition
|
|
|
|
# Replace by rootfs in few kernel version
|
|
|
|
DISK_USAGE=$(df | grep -m1 "/$" | awk '{print $5}')
|
|
|
|
printf '%b' "\n${MAGENTA}+ ${WHITEB}/${RESET}\t[ ${DISK_USAGE} ] "
|
|
|
|
|
|
|
|
# Other partition
|
|
|
|
for PART in /boot /home /opt /tmp /usr /var /var/lib/vz; do
|
|
|
|
# "/...$" : $ to grep only the mount point and not sub-directories (/var: OK; /mnt/temp: nOK)
|
|
|
|
if (df | grep "${PART}$" > /dev/null); then
|
|
|
|
DISK_USAGE=$(df | grep "${PART}$" | awk '{print $5}')
|
|
|
|
printf '%b' "\n${MAGENTA}+ ${WHITEB}${PART}${RESET}\t[ ${DISK_USAGE} ] "
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
### IF ZFS
|
|
|
|
if [ $(which zpool) ]; then
|
2015-08-29 09:22:59 +02:00
|
|
|
printf '%b' "\n${MAGENTA}+++++++++++++++++++ ${WHITEB}ZFS${RESET} ${WHITE}Partitions${RESET} ${MAGENTA}:++++++++++++++++++${RESET}"
|
2015-02-06 23:06:37 +01:00
|
|
|
NUMBER_PART=$(df -T | grep zfs | wc -l)
|
|
|
|
LINE=1
|
|
|
|
|
|
|
|
while [ "${LINE}" -le "${NUMBER_PART}" ]; do
|
|
|
|
PART_NAME=$(df -T | grep zfs | sed -n "${LINE},${LINE}p" | awk '{print $1}')
|
|
|
|
DISK_USAGE=$(df -T | grep zfs | sed -n "${LINE},${LINE}p" | awk '{print $6}')
|
|
|
|
printf '%b' "\n${MAGENTA}+ ${WHITEB}${PART_NAME}${RESET} [ ${DISK_USAGE} ] "
|
2015-03-26 10:00:58 +01:00
|
|
|
LINE=$((LINE+1))
|
2015-08-29 09:22:59 +02:00
|
|
|
# Bash ONLY: (( LINE++ ))
|
2015-02-06 23:06:37 +01:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
### FI ZFS
|
|
|
|
|
2015-08-29 09:22:59 +02:00
|
|
|
### IF CEPH
|
|
|
|
# First, test if a keyring file exists
|
|
|
|
if [ -f /etc/ceph/*.keyring ]; then
|
|
|
|
printf '%b' "\n${MAGENTA}++++++++++++++++++++++++ ${WHITEB}Ceph${RESET} ${MAGENTA}:++++++++++++++++++++++++${RESET}"
|
|
|
|
for keyring in "$(find /etc/ceph -type f -name *.keyring)"; do
|
|
|
|
CEPH_USERNAME=$(grep client ${keyring} | sed 's/^\[client.\(.*\)\]/\1/')
|
|
|
|
CEPH_HEALTH=$(ceph health --id ${CEPH_USERNAME})
|
|
|
|
CEPH_HEALTH_OK=$(ceph health --id ${CEPH_USERNAME} | grep -i -- 'ok')
|
|
|
|
|
|
|
|
# Test health to determine the color to use
|
|
|
|
if [ ${CEPH_HEALTH_OK} ]; then
|
|
|
|
CEPH_COLOR=${GREEN}
|
|
|
|
else
|
|
|
|
CEPH_COLOR=${RED}
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Print
|
|
|
|
printf '%b' "\n${MAGENTA}+ ${WHITEB}${keyring}: ${CEPH_COLOR}${CEPH_HEALTH}"
|
|
|
|
done
|
|
|
|
|
|
|
|
# Else use default
|
|
|
|
elif [ -f /etc/ceph/ceph.conf ]; then
|
|
|
|
printf '%b' "\n${MAGENTA}++++++++++++++++++++++++ ${WHITEB}Ceph${RESET} ${MAGENTA}:++++++++++++++++++++++++${RESET}"
|
|
|
|
CEPH_HEALTH=$(ceph health)
|
|
|
|
CEPH_HEALTH_OK=$(ceph health | grep -i -- 'health_ok')
|
|
|
|
|
|
|
|
# Test health to determine the color to use
|
|
|
|
if [ ${CEPH_HEALTH_OK} ]; then
|
|
|
|
CEPH_COLOR=${GREEN}
|
|
|
|
else
|
|
|
|
CEPH_COLOR=${RED}
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Print
|
|
|
|
printf '%b' "\n${MAGENTA}+ ${CEPH_COLOR}${CEPH_HEALTH}"
|
|
|
|
fi
|
|
|
|
### FI CEPH
|
|
|
|
|
2015-02-06 23:06:37 +01:00
|
|
|
|
|
|
|
printf '%b' "${RESET}\n"
|
|
|
|
|
|
|
|
|