Skip to content

Commit

Permalink
capture in GB. Add monthly/gnuplot info
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeWalters committed May 17, 2017
1 parent 8eb5217 commit 89faf9f
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 17 deletions.
4 changes: 2 additions & 2 deletions DUOT.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# The mountpoint to be checked. In the form of a directory, not device
DISK=/partition/to/check
# This is where disk usage will be stored over time.
LOG=/var/log/usageovertimeV2.csv

LOG=/var/log/usageovertime.csv
MONTHLYLOG=/var/log/usageovertime.monthly.dat
62 changes: 48 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,63 @@
# Disk Usage Over Time - DUOT

This is a two part script.

1. diskusage.sh checks the disk usage of a particular mount point and outputs it to a specified csv file as YYMMDD,diskusage (ie: 20161214,21452214). If run every day, this can be useful for tracking your usage in excel or libreCalc in a pretty graph. This script should be run as frequently as possible. Preferably, diskusage.sh would be run daily in a cron. The more times this script is run, the more accurate it should become due to the fluctuations in disk usage.
1. `diskusage.sh` checks the disk usage of a particular mount point and outputs it to a specified csv file as YYMMDD,diskusage (ie: 20161214,21452214). If run every day, this can be useful for tracking your usage in excel or libreCalc in a pretty graph. The more times this script is run, the more accurate it should become due to the fluctuations in disk usage. `diskusage.sh` must be run daily to accurately calculate the growth average over time when paired with `estimatefull.sh`.

2. estimatefull.sh approximates when your disk will be full based on your growth average (Which is generated using the csv file).
2. `estimatefull.sh` approximates when your disk will be full based on your growth average (Which is generated using the csv file). `diskusage.sh` must be run daily to accurately calculate the growth average over time.

3. `monthlyusage.sh` should be run monthly and is best used in association with gnuplot (demonstration below).

## Usage

### usageovertime.sh / estimatefull.sh
```
root@localhost:/# tail /var/log/usageovertimeV2.csv
20170205,15400044896
20170206,15383424560
20170207,15350913480
20170208,15380265120
20170209,15419715720
20170210,15435301616
20170211,15464570480
20170212,15474348352
20170213,15485409192
20170214,15459207288
20170508,16512
20170509,16457
20170510,16479
20170511,16539
20170512,16598
20170513,16618
20170514,16673
20170515,16710
20170516,16727
20170517,16775
root@localhost:/tmp# ./estimatefull.sh
Estimated date disk will be full: September 08 2018
```
It is recommended that the estimatefull.sh script is run daily to better calculate the growth average over time. You can put this in a cron job or run it manually.

### monthlyusage.sh

Install gnuplot and run the following command to get an SVG file that demonstrates past usage.
```
gnuplot -p -e '
set title "Disk Usage Over Time in GB";
set object 1 rectangle from screen 0,0 to screen 1,1 fillcolor rgb "white" behind;
set ylabel "Disk Usage in GB";
set yrange[0:AAAAA];
set ytics font ", 10";
set key off;
set xdata time;
set xtics font ", 8";
set xtics rotate by 45 offset -2.5,-1.5;
set format x "%m/%Y";
set tics nomirror;
set timefmt "%Y-%m-%d";
set bmargin 2.5;
set style line 11 lc rgb "#808080" lt 1;
set border 3 back ls 11;
set style line 12 lc rgb "#808080" lt 0 lw 1;
set grid back ls 12;
set term svg enhanced size 640,480;
set encoding iso_8859_1;
set output "out.svg";
plot "/var/log/usageovertime.month.dat" using 1:2 w lp pt 1 ps 1 lt 1 lc rgb "#f05F40" lw 2'
```
Substitute AAAAA for a max value on the Y Axis
Substitute /var/log/usageovertime.month.dat for your results file from `monthlyusage.sh`.

![Screenshot](https://raw.githubusercontent.com/JoeWalters/IMG/master/out.svg)


## Setting up the application
Change the LOG and DISK variable accordingly in DUOT.conf
Expand Down
2 changes: 1 addition & 1 deletion diskusage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ source $MYDIR/DUOT.conf


if grep -qs $DISK /proc/mounts; then
echo "$(date +%Y%m%d),$(df $DISK | grep $DISK | awk '{print $3}')" >> $LOG
echo "$(date +%Y%m%d),$(df -BG $DISK | grep $DISK | awk '{print $3}')" | sed -e 's/G//g' >> $LOG
fi
24 changes: 24 additions & 0 deletions monthlyusage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

####################
# plotdiskusageGB.sh
####################
#
# Written by: Joseph Walters
# https://github.com/JoeWalters/DUOT
#
####################
#
# Output disk usage to a file (to be used monthly)
#
####################

MYSELF="$(realpath "$0")"
MYDIR="${MYSELF%/*}"

source $MYDIR/DUOT.conf

#Output current disk usage to file
echo "$(date +%Y-%m) $(df -BG | grep common | awk '{print $3}' | sed -e 's/G//g')" >> $MONTHLYLOG

exit 0

0 comments on commit 89faf9f

Please sign in to comment.