virtual-deployment/libvirt/show_diskusage.sh

74 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
#
# SPDX-License-Identifier: Apache-2.0
#
# Copyright (c) 2023 Wind River Systems, Inc.
#
# Show the host's and lab's disk usage per configured disk
# The disk usage for each lab's configured disks
# (i.e., for each VM),
# and for each of the host's disks overall upon which the
# lab's virtual disks are presented.
if [ -z "$CONFIG_FILE" ]; then
echo 'No configuration file selected'
exit 1
fi
if ! [ -f "$CONFIG_FILE" ]; then
echo 'Configuration file does not exist'
exit 1
fi
DISK_DIRS=""
CONTROLLER0_DIR="$( ./config.py "$CONFIG_FILE" controllerlist 0 disk )"
CONTROLLER1_DIR="$( ./config.py "$CONFIG_FILE" controllerlist 1 disk )"
echo
if [ -n "$CONTROLLER0_DIR" ] && [ -d $CONTROLLER0_DIR ]; then
sudo du -sh $CONTROLLER0_DIR
DISK_DIRS="$DISK_DIRS $CONTROLLER0_DIR"
fi
if [ -n "$CONTROLLER1_DIR" ] && [ -d $CONTROLLER1_DIR ]; then
sudo du -sh $CONTROLLER1_DIR
DISK_DIRS="$DISK_DIRS $CONTROLLER1_DIR"
fi
if [ -n "$STORAGE_NODES_NUMBER" ]; then
index=0
while [ "$index" -le "$STORAGE_NODES_NUMBER" ]; do
host_dir="$( ./config.py "$CONFIG_FILE" storagelist "$index" disk )"
if [ -n "$host_dir" ] && [ -d $host_dir ]; then
sudo du -sh $host_dir
DISK_DIRS="$DISK_DIRS $host_dir"
fi
index+=1
done
fi
if [ -n "$WORKER_NODES_NUMBER" ]; then
index=0
while [ "$index" -le "$WORKER_NODES_NUMBER" ]; do
host_dir="$( ./config.py "$CONFIG_FILE" workerlist "$index" disk )"
if [ -n "$host_dir" ] && [ -d $host_dir ]; then
sudo du -sh $host_dir
DISK_DIRS="$DISK_DIRS $host_dir"
fi
index+=1
done
fi
echo
# Print a header
df -h $DISK_DIRS | grep "^Filesystem" | sed "s;Mounted on;Disk Path;"
(
for l in $DISK_DIRS; do
# Works assuming there is no space for directory name
sudo df -h $l | grep -v "^Filesystem" | sed "s;[^ ]\{1,\}$;$l;"
done
) | sort | uniq
echo