I have several 2TB disks dedicated to running storj nodes, with 1.8TB allocated. However, with all the test data received over the past month or so, I found that most of them were showing 95% or higher disk usage with df
in linux. So, I wrote the script below to analyze the used disk space. I’m sharing here with the hope that it might be useful for others. I’ve only tested it on Ubuntu 22.04 with ext4 filesystems.
Example usage:
./storj-diskspace-check.sh /mnt/storj24/storj24/config
Example output:
Filesystem 1B-blocks Used Available Use% Mounted on
/dev/sdm1 1967814619136 1806314487808 61465141248 97% /mnt/storj24
Total bytes: 1967814619136 (1.97T)
Used bytes: 1806314487808 (1.81T, 91%)
Avail bytes: 61465141248 (61.47G, 3%)
Reserved bytes: 100034990080 (100.03G, 5%)
Scanning blobs directory...
Used bytes on disk: 1786510647296 (1.79T)
File size total: 1762082276004 (1.76T)
Difference: 24428371292 (24.43G)
Scanning trash directory...
Used bytes on disk: 19417468928 (19.42G)
File size total: 19322173207 (19.32G)
Difference: 95295721 (95.30M)
Scanning temp directory...
Used bytes on disk: 4096 (4.10K)
File size total: 4096 (4.10K)
Difference: 0 (0.00)
This is the content of storj-diskspace-check.sh:
#!/bin/bash
set -e
print_number () {
# si, iec, iec-i
# See man numfmt for full list
fmt_units=si
fmt_format="%.02f"
fmt_round=nearest
numfmt --to=$fmt_units --format=$fmt_format --round=$fmt_round $1
}
# make sure dir exists before changing to it
stat $1/storage > /dev/null
cd $1/storage
df --block-size=1 .
total_bytes=`df --block-size=1 . --output=size | grep -v "1B-blocks"`
used_bytes=`df --block-size=1 . --output=used | grep -v Used`
avail_bytes=`df --block-size=1 . --output=avail | grep -v Avail`
reserve_bytes=$((total_bytes - ($avail_bytes + $used_bytes)))
echo ""
echo "Total bytes: $total_bytes (`print_number $total_bytes`)"
echo "Used bytes: $used_bytes (`print_number $used_bytes`, $((used_bytes * 100 / total_bytes))%)"
echo "Avail bytes: $avail_bytes (`print_number $avail_bytes`, $((avail_bytes * 100 / total_bytes))%)"
echo "Reserved bytes: $reserve_bytes (`print_number $reserve_bytes`, $((reserve_bytes * 100 / total_bytes))%)"
echo ""
echo "Scanning blobs directory..."
blobs_actual=`du --block-size=1 --max-depth=0 blobs | cut -f 1`
blobs_apparent=`du --block-size=1 --apparent-size --max-depth=0 blobs | cut -f 1`
blobs_diff=$((blobs_actual - blobs_apparent))
echo "Used bytes on disk: $blobs_actual (`print_number $blobs_actual`)"
echo "File size total: $blobs_apparent (`print_number $blobs_apparent`)"
echo "Difference: $blobs_diff (`print_number $blobs_diff`)"
echo ""
echo "Scanning trash directory..."
trash_actual=`du --block-size=1 --max-depth=0 trash | cut -f 1`
trash_apparent=`du --block-size=1 --apparent-size --max-depth=0 trash | cut -f 1`
trash_diff=$((trash_actual - trash_apparent))
echo "Used bytes on disk: $trash_actual (`print_number $trash_actual`)"
echo "File size total: $trash_apparent (`print_number $trash_apparent`)"
echo "Difference: $trash_diff (`print_number $trash_diff`)"
echo ""
echo "Scanning temp directory..."
temp_actual=`du --block-size=1 --max-depth=0 temp | cut -f 1`
temp_apparent=`du --block-size=1 --apparent-size --max-depth=0 temp | cut -f 1`
temp_diff=$((temp_actual - temp_apparent))
echo "Used bytes on disk: $temp_actual (`print_number $temp_actual`)"
echo "File size total: $temp_apparent (`print_number $temp_apparent`)"
echo "Difference: $temp_diff (`print_number $temp_diff`)"
echo ""