Skip to content

Instantly share code, notes, and snippets.

@Eeems
Last active September 15, 2020 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Eeems/c3757602e2117e39a08694c5fbfce794 to your computer and use it in GitHub Desktop.
Save Eeems/c3757602e2117e39a08694c5fbfce794 to your computer and use it in GitHub Desktop.
Plot Size tool
#!/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;

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

Screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment