I want to track the disk usage on my personal WebDAV account and plot it along time.
Sample Screenshot (click to see the website):
First, create a cronjob which logs the disk usage. The tricky part is to log the date and the output of the
du command at the same time. Here is the commented bash script:
# create a temporary filename TFILE="/tmp/dutmp.$$.tmp"; # dump the current date in the file date -R > $TFILE; # get the current disk usage to the path of your webdav du -sm /your/server/path/to/webdav >> $TFILE ; # get the contents of the tempfile, replace the newline character with # a semicolon, skip the path from du's output and write it to my logfile sed ':a;N;$!ba;s/\n/; /g' $TFILE | sed 's/\(.*;\s*[0-9]*\).*/\1/' >> /your/wwwroot/du/du-log.txt; # delete the tempfile rm $TFILE
I put the above commands on one line in my crontab (executing every 15 mins):
*/15 * * * * TFILE="/tmp/dutmp.$$.tmp"; date -R > $TFILE; du -sm /your/server/path/to/webdav >> $TFILE ; sed ':a;N;$!ba;s/\n/; /g' $TFILE | sed 's/\(.*;\s*[0-9]*\).*/\1/' >> /your/wwwroot/du/du-log.txt; rm $TFILE
du-log.txt looks like this
Date; MByte Fri Apr 1 2011 15:00:01 +0200; 4639 Fri Apr 1 2011 15:15:01 +0200; 4695 Fri Apr 1 2011 15:30:01 +0200; 4751 [...]
Remember that initially the logfile should just consist of one line
Here is the full HTML code, (click for rendered view):
Note that you need a workaround to get this rendered in IE.