Chad's profileChad Miller's BlogBlogListsNetworkMore Tools Help

Blog


    April 03

    Making Disk, Database and Table Graphs with Powershell

    Sometimes seeing data visually rather than in text format makes things easier to understand. For instance, I prefer to use WinDirStat to see a Treemap of disk space usage by file and type rather than a sorted text list of large files. Seeing the files visually I can immediately determine which files are taking up the most space. I also would rather view database file space usage in the TaskPad view of SQL Server 2000 Enterprise Manager instead of running a query. Outside of pre-built tools I'll often use Excel pivot charts to quickly create graphs. In Powershell creating your own graphs is fairly simple thanks to Joel Bennet's (Jaykul), Powerboots and Visifire SiliverLight and WPF charts.
     
    Getting Started
    1. Install Powerboots
    2. Install SQL Server Powershell Extensions (SQLPSX)
    3. Download the open source Visifire components
    *Note: I'm using Powershell V1 and I've placed Powerboots, SQLPSX, and Visifire in my ...Documents\WindowsPowerShell\Libraries directory. In addition since Powerboots and Visifire use WPF, the .NET 3.5 Framework is required.
     
    Once you've completed the install you can use this script to create a test chart:
     
    $libraryDir = Convert-Path (Resolve-Path "$ProfileDir\Libraries")
    [Void][Reflection.Assembly]::LoadFrom( (Convert-Path (Resolve-Path "$libraryDir\WPFVisifire.Charts.dll")) )

    if (!(Get-PSSnapin | ?{$_.name -eq 'PoshWpf'}))
    { Add-PsSnapin PoshWpf }

    New-BootsWindow -Async {
      $chart = New-Object Visifire.Charts.Chart
      $chart.Height    = 300 
      $chart.Width     = 600 
      $chart.watermark = $false 
      
         $ds    = New-Object Visifire.Charts.DataSeries
         $ds.RenderAs = [Visifire.Charts.RenderAs]"Bar"
         $chart.Series.Add($ds)
            for($i=0; $i -lt 5; $i++)
            {
            $dp = new-object Visifire.Charts.DataPoint
            $dp.YValue = (get-random -min 1 -max 20)
            $ds.DataPoints.Add($dp)
            }
      $chart
    } -Title "Test"
     
    Here are a few examples I've posted on Poshcode for disk, database and table space graphs.
     
    WPFDiskSpace -- Uses Powerboots and Visifire to display a WPF graph of disk space including percent used and free
     

    Get-WmiObject Win32_LogicalDisk -filter "DriveType=3" | ./WPFDiskSpace.ps1

     

    WPFDbSpace -- Uses Powerboots, Visifire and SQLPSX to Display a WPF graph of SQL Server database data and log file space:
     
    Get-SqlDatabase 'Z002\Sql2k8' | where {$_.name -like "pubs*"} | ./WPFDbSpace.ps1
     
     
     
     
    WPFTableSpace -- Uses Powerboots, Visifire and SQLPSX to display a WPF graph of SQL Server table data and index space usage:
     
    ./WPFTableSpace.ps1 'Z002\SqlExpress' AdventureWorks
     
     
    The graphs I've created so far have been simple/static graphs, but you can do a lot more with Powerboots. For example Joel has a really cool script showing a real-time graphical ping monitor. And not only can you make charts, you can use WPF to create some very slick looking screens. In short, Powerboots is an impressive toolkit which I will definitely find additional uses for.

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://chadwickmiller.spaces.live.com/blog/cns!EA42395138308430!328.trak
    Weblogs that reference this entry
    • None