Simple tool to plot out changes in used space on a mount point. Useful for watching the changes in space usage in /tmp
# Install gnuplot and inotify-tools
plot_size /tmp
| #!/bin/bash | |
| if [[ "$1" == "" ]];then | |
| echo "Usage: plot_size <mountpoint> [-k]"; | |
| echo " <mountpoint>: Mount point to monitor"; | |
| echo " -k don't remove old data before graphing"; | |
| exit 1; | |
| fi; | |
| if [[ "$(df | grep $1)" == "" ]];then | |
| echo "Unable to find mountpoint $1"; | |
| exit 1; | |
| fi; | |
| function update(){ | |
| while true;do | |
| echo -e "$(tail -n 300 /tmp/plot_size.dat)\n$(df | grep $1 | awk '{print systime()" "$3}')" > /tmp/plot_size.dat; | |
| sleep 1; | |
| done; | |
| } | |
| if [[ "$2" != "-k" ]];then | |
| echo -n > /tmp/plot_size.dat; | |
| fi; | |
| trap 'kill $(jobs -p)' EXIT | |
| update "$1" & | |
| trap "tput cnorm" EXIT | |
| tput civis | |
| while inotifywait --quiet -e close_write /tmp/plot_size.dat > /dev/null;do | |
| cat /tmp/plot_size.dat | gnuplot -e "\ | |
| set xlabel 'Time'; \ | |
| set ylabel 'Size'; \ | |
| set title '/tmp $(df -h | grep $1 | awk '{print $3" "$5}')'; \ | |
| set term dumb $(tput cols) $(tput lines); \ | |
| set xdata time; \ | |
| set timefmt '%s'; \ | |
| set format x '%H:%M:%S'; \ | |
| set ytics format '%.0s%cB'; \ | |
| set yrange [0:*]; \ | |
| plot '-' using 1:(\$2*1000) notitle with lines ls 1;" | grep --color -E '\*|$'; | |
| done; |