I would like either a program or more preferably a way to log the disk usage.
In order to explain what I mean, when someone installs Ubuntu there are approximately 4.5 GB of disk used. Then when you install/uninstall programs this usage increases or decreases.
What I want is a way to log automatically the current disk that is used in a txt file when there is a change (something is installed/saved or uninstalled/deleted) with the time and date that this change occurred.
Using the
df
command to keep track of the disk space, and thelsblk
command to keep track of the mounted drives, the script below, run in the background, will log changes in the free space of all mounted drives. It creates a log file:~/disklog
where it writes changes to (ink
).If you run it in the terminal, it will output the result simultaneously.
The content of the log file looks like:
How to use
log_diskusage.py
In the head section of the script, set the time interval the treshold and the max number of lines in the logfile:
interval
to run the disk-space checks, as it is, 20 secondstreshold
: You probably wouldn't want to keep record of all (very) small changes, since the disk has a lot of small changes in free disk space. As it is, it is set to10k
max_lines
, since the logfile will grow quickly, especially if you set the treshold to zeroTest-run the script with the command:
If all works fine, add it to your Startup Applications: Dash > Startup Applications > Add.
The script
You should use vmstat which is already installed on ubuntu, or iostat but you've to install it. iostat, vmstat and mpstat Examples for Linux Performance Monitoring