5 Replies Latest reply on Aug 30, 2012 12:59 PM by nko321

    Monitor Disk Space On Hyper-V CSV Volumes - Cluster Shared Volumes

      Has anyone found a way to monitor disk space on CSV volumes on Hyper-V hosts?  I am able to check disk space using a PowerShell script, but have not found a way to do it in NPM or APM.

        • Re: Monitor Disk Space On Hyper-V CSV Volumes - Cluster Shared Volumes
          satishgsk

          Hi nbissette, same here i am also looking for same info. i found a link where a user has got that implemented and i hope it will be useful for us.

           

          http://thwack.solarwinds.com/message/160055#160055

          • Re: Monitor Disk Space On Hyper-V CSV Volumes - Cluster Shared Volumes
            nko321

            I just finished implementing this in our environment.There are two steps involved:

             

            1) Configure a node in the cluster to handle remote Powershell scripts. This portion is covered well enough in other places, and I didn't configure it myself, so I'll leave well enough alone :-)

            2) Execute your Powershell script. The big trick here is to ensure that the output adheres to APM / SAM's expectations. This is poorly outlined in the documentation. Alluded to, really. Not documented per-se.

             

            Below is the script we are using. Note that I'm NOT a Powershell guy; I have kludged the text output to cause SAM to be happy, but I've also committed several deadly sins of scripting in the meantime. The result ALMOST works; it has one obvious problem. If you can help me fix it, I'd be grateful!

             

            Rundown of what it does:

            1. Gets the free space of CSV #1. Saves it to $a.
            2. This is the primary kludge. Yanks the actual numerical, two digit free space quantity from $a and saves it in $b. BIG PROBLEM: If free space is 100%, it'll return "10" (percent). If it's below 10% (a single digit), we are out of luck again; this time, the script will return the first two decimal places of the free space instead of the actual free space. So if we have 1.95122% free space, it'll return "95". My script suddenly think we're at 95% free space when really, we're below 2%.
            3. Important part: Echo some output that SAM understands. It has to be "Statistic.whateveryounameit:Value".
            4. Do all of this over again, this time for our second CSV. We only have two.
            5. A bunch of "if" statements to make proper exit codes. SAM takes exit code 0 to mean the Application Component is "Up," 1 to mean it's "Down," 2 to mean it's in "Warning" and 3 to mean "Critical." Anything else makes SAM say the Application Component is in an "Unknown" state.

             

            Anyone think they can help clean this up?

             

            Import-Module FailoverClusters

             

            $a = Get-ClusterSharedVolume "Cluster Disk 1" | select -Expand SharedVolumeInfo | select -Expand Partition | select PercentFree | out-string

            $b = [regex]::match($a,'\d\d').Groups[0].Value

             

            Echo "Statistic.CSV1PercentFree:$b"

            Echo "Message.CSV1PercentFree:None"

             

            $c = Get-ClusterSharedVolume "Cluster Disk 2" | select -Expand SharedVolumeInfo | select -Expand Partition | select PercentFree | out-string

            $d = [regex]::match($c,'\d\d').Groups[0].Value

             

            Echo "Statistic.CSV2PercentFree:$d"

            Echo "Message.CSV2PercentFree:None"

             

            if ([int]$b -le 10) {exit 2}

            if ([int]$b -le 5) {exit 3}

            if ([int]$d -le 10) {exit 2}

            if ([int]$d -le 5) {exit 3}

            exit 0

              • Re: Monitor Disk Space On Hyper-V CSV Volumes - Cluster Shared Volumes
                nko321

                Further kludge, but cleaner: If you change this line:

                 

                $b = [regex]::match($a,'\d\d').Groups[0].Value


                To read like so:


                $b = [regex]::match($a,'\d*\d').Groups[0].Value


                It will return everything to the left of the decimal point. That should make this script behave the way we want it to, though it's still a messy way to do things. Anyone know how to just tell Powershell to return a better formatted result in the first place?

                  • Re: Monitor Disk Space On Hyper-V CSV Volumes - Cluster Shared Volumes
                    lweniger

                    "{0:N0}" -f will round to the nearest whole number.

                     

                    You can do something like:

                    $b = "{0:N0}" -f (Get-ClusterSharedVolume "Cluster Disk 1" | select -Expand SharedVolumeInfo | select -Expand Partition | Select PercentFree).PercentFree

                    $d = "{0:N0}" -f (Get-ClusterSharedVolume "Cluster Disk 2" | select -Expand SharedVolumeInfo | select -Expand Partition | Select PercentFree).PercentFree

                     

                    You can also make it a bit more portable by doing:

                    Get-ClusterSharedVolume | Foreach {

                        $name = $_.Name

                        $PercentFree = "{0:N0}" -f (Get-ClusterSharedVolume | Select -Expand SharedVolumeInfo | Select -Expand Partition | Select PercentFree).PercentFree

                        Echo "Statistic.$name`PercentFree:$PercentFree"

                        If ([int]$PercentFree -le 10) { exit 2 }

                        If ([int]$PercentFree -le 5) { exit 3 }

                    }

                     

                    Or if you know you have spaces in your CSV names something like:

                    $i = 1

                    Get-ClusterSharedVolume | Foreach {

                        $name = "CSV$i"

                        $PercentFree = "{0:N0}" -f (Get-ClusterSharedVolume | Select -Expand SharedVolumeInfo | Select -Expand Partition | Select PercentFree).PercentFree

                        Echo "Statistic.$name`PercentFree:$PercentFree"

                        If ([int]$PercentFree -le 10) { exit 2 }

                        If ([int]$PercentFree -le 5) { exit 3 }

                        $i++

                    }

                      • Re: Monitor Disk Space On Hyper-V CSV Volumes - Cluster Shared Volumes
                        nko321

                        That first example worked perfectly. I'm using it to replace my current script. Thanks!!

                         

                        The other two gave me the following error:

                         

                        Get-ClusterSharedVolume : The pipeline has been stopped.

                        At line:1 char:24

                        + Get-ClusterSharedVolume <<<<  | Foreach {

                            + CategoryInfo          : NotSpecified: (:) [Get-ClusterSharedVolume], ClusterCmdletException

                            + FullyQualifiedErrorId : Get-ClusterSharedVolume,Microsoft.FailoverClusters.PowerShell.GetClusterSharedVolumeComm

                           and

                         

                        But I'm very satisfied with the first one. It tells me a lot about how things work. Thanks!!