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/

Leave a Reply

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