Disk Usage Monitoring
Introduction to Disk Usage Monitoring
Welcome to this lesson on Disk Usage Monitoring. Keeping track of disk usage is essential for maintaining system health and ensuring that there is adequate storage space for applications and data. Monitoring disk usage helps system administrators detect potential issues early, avoid system crashes, and maintain optimal system performance.
Let's dive in!
Disk Usage of Filesystems with df
The df command provides an overview of the disk space usage of filesystems. It shows information like total space, used space, available space, and the percentage of space used. You can use the -h option to make the output easier to read
Using the df command without a file path displays the disk space usage of all mounted filesystems on the system. You can use a path to a filesystem to get the statistics for only that filesystem. Let's take a look:
df $FILESYSTEMdisplays the disk usage of the filesystem containing the directory specified by$FILESYSTEM.df -h $FILESYSTEMuses the-hflag, which stands for "human-readable". It converts the sizes into more comprehensible units like KB, MB, or GB.
The output of this code is:
Let's break down each column:
Filesystem: The name of the filesystem or disk partition. In this case, it is/dev/vda1, which indicates a specific disk or partition.Size: The total size of the filesystem, which is 621 GB in this example.Used: The amount of disk space that is currently used, which is 52 GB.Avail: The amount of disk space that is still available for use, which is 569 GB.Use%: The percentage of the total disk space that is currently used, which is 9%.Mounted on: The directory where the filesystem is mounted. In this case, it is/usercode/FILESYSTEM.
Disk Usage of Files and Directories with du
The df command provides statistics about certain filesystems. If you want to estimate the disk usage of files and directories we can use the du command. The -h option is used to provide a human-readable report of the disk usage for all files and directories within the specified directory. It lists each item along with its size in human-readable format.
The -sh option provides a summary of the total disk usage for the specified directory in human-readable format. It does not list individual items. Instead, it gives you the total disk usage of the entire directory at the top level.
Let's take a look at the disk usage of our $FILESYSTEM directory.
The output is:
Let's look at the output of du -h $FILESYSTEM
12K /usercode/FILESYSTEM/.codesignal: This indicates that the.codesignaldirectory inside /usercode/FILESYSTEMis using 12 KB of disk space.20K /usercode/FILESYSTEM: This indicates that the total disk usage of the/usercode/FILESYSTEMdirectory is 20 KB, which includes the space used by its contents (like the.codesignaldirectory).
The output of the du -sh $FILESYSTEM command is: 20K /usercode/FILESYSTEM.
This is a summarized report indicating that the total disk usage of the entire /usercode/FILESYSTEM directory is 20 KB. It does not provide a breakdown of individual files or subdirectories.
