Disk Space Usage Trend Analysis – Part 3

green

Picking up from Part 1 and Part 2 in the series, it’s now time to take our collected data and calculated linear trend line and plot them graphically.

Before going any further, download and install the Microsoft Chart Controls on the computer you’re going to run this script from.

There is a lot going on here.  Remembering that this is to be inserted into the previous script (in the middle of a loop through each computers hard disks). The summary of the script is:

  • Get the capacity of the current drive
  • Get the data from the saved .txt file for the last X days for the current drive
  • Limit the chart y-axis to a range of numbers specific to the data (you don’t want graphs starting from 0GB when the data is in the terabytes)
  • Based on the above range, set appropriate interval/tick values
  • Calculate the number of days the disk has left if the trend continues and only create a graph if within X days of exhausting available space
  • Create the chart object and chart area
  • Plot a horizontal line for the capacity of the disk
  • Plot a line for the historical usage of the disk
  • Plot the linear trend line, and extend it to show where it hits the disk capacity
  • Save the chart to an image file in c:\scripts\diskgraphs

 

Here’s the script:

After all of that, you should have .png files in c:\scripts\diskgraphs that are in the format of <computername>_<driveletter>_<todays_date>.png

diskgraphfolder

And when you open each image, you should see something like this:

BK02_C_150514

You can now embed these images in HTML or an email to be delivered periodically.

 

FAQ

Q: Why don’t I get graphs for all my drives?

A: The script is designed to only produce graphs when disk usage is trending upwards AND if that trend suggests the disk will run out of space in less than 100 days.  You can change these settings easily to produce graphs for all drives regardless of the slope or predicted days remaining.

 

Q: What if I wanted a pie/bar/whatever style of chart?

A: Check out the link in the References for more information about other chart types and more theory on how the chart controls really work.

 

References

https://www.microsoft.com/en-us/download/details.aspx?id=14422

https://bytecookie.wordpress.com/2012/04/13/tutorial-powershell-and-microsoft-chart-controls-or-how-to-spice-up-your-reports/

2 Comments Disk Space Usage Trend Analysis – Part 3

  1. corey

    this works good if your data goes up linearly–But what is the solution when the recordings are sinusoidal in nature, e.g. large creation of files over a week and then deletion on the weekend. For something like this, an identifier to determine a sinusoidal growth is necessary and then multi regression is required. or alternatively perform a linear regression on the peaks of your disk space use for each period.

    Reply
    1. Kamal

      You’re right – the script does not cater for sinusoidal peaks and troughs. The script was primarily designed for “growth over time” scenarios which (at the time of writing) was found to be a major ongoing headache.
      I don’t think it would be too difficult to modify the script to look for various patterns of change. IE: tracking large shifts (in % or GB) form the previous day/week, even though the trend suggests no growth.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *