How to monitor Hyper-V Server Checkpoints

As IT Admins we want to have full control of our virtualization environment. By using PRTG we can get notified if there is x amount of checkpoints in the Hyper-V Server.
How-to-monitor-Hyper-V-Server-Checkpoints

Microsoft used to call it snapshots, but back in Windows Server 2012 R2, the name was changed to checkpoints. However we call it, it is important to treat them properly and have full control of our virtualization environment. For the folks who are not familiar with snapshots (VMware, XenServer) or checkpoints (Hyper-V), they are used to capture the current state of the virtual machine. This can be very helpful if we are deploying some system changes or app updates. In case of failure, we can easily revert to the previous state. Once we don’t need a checkpoint anymore, we should delete it. The issue is that we sometimes keep checkpoints for a long time which unnecessarily consumes disk space, or we´re relying on snapshots as the replacement for the backup which is a big mistake.

WRONG: Hyper-V Checkpoints

As an IT Admin, I want to be notified if there are x amount of checkpoints in a production environment. Thanks to PRTG and PowerShell script we can easily achieve our goal. PRTG has a native sensor called “EXE/Script Sensor” which can execute the script below.

Before we start, the quote of the day:

“Hyper-V checkpoints are NOT alternative for a backup!”

HOW-TO

Create a PowerShell script with the code below or if you prefer you can download it from this LINK. Please modify the script:

‘Hostname’ – please add Hyper-V Server FQDN. In my case, it is ‘hyper-v.techwithjasmin.com’

-VMName * – it will query the total amount of the checkpoints on your Hyper-V Server. If you would like to monitor a certain VM, please define that in the script (e.g. -VMName win-srv-2019). winsrv2019 is the name of the virtual machine.

Define amount of the snapshots. In my case it is 5.

$x= 0
$i= Invoke-Command –ComputerName 'hyper-v.techwithjasmin.com' –ScriptBlock{Get-VMSnapshot -VMName * | measure}
$i=$i.Count


if ($i  -eq 0) {
  $x=[string]$i+":OK"
  write-host $x
  exit 0
}
ElseIf ($i -eq 5) {
  $x=[string]$i+": 5 Snapshots"
  write-host $x

  exit 1
}
ElseIf ($i -lt 5) {
  $x=[string]$i+": <5 Snapshots"
  write-host $x

  exit 1
}


ElseIf ($i -gt 5) {
  $x=[string]$i+": >5 Snapshots"
  write-host $x
  exit 1
}

Else 
{
  $x=[string]$i+":Invalid"
  write-host $x
  exit 2
}

Once you have modified the PowerShell script based on your needs, please copy the PowerShell script to C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXE.

Here is an example from my environment. The -VMName * parameter includes the total amount of the checkpoints, which is in my case 14.

Total amount of snapshots on Hyper-V Server

If I want to be more specific and show the amount of the snapshots on a certain VM, e.g. win-srv-2019, I’ll use the parameter -VMName win-srv-2019. There are 4 snapshots on my VM.

Total amount of snapshots on single VM

Once we are done with the sensors, we should configure notification trigger. You can add state trigger notification which will inform you in case your sensors is in Warning state (e.g. if it has x amount of checkpoints).

State Trigger Notification

Thank you for reading this article. In case of any questions, feel free to comment or contact me.

Comments (3):

  1. Tony Fantaci

    March 8, 2023 at 15:29

    Hi,
    The script seems to work when there are no snapshots, but when there is at least 1 snapshot, it fails with message ‘Response not well-formed: “( )” (code: PE132)’.

    Tony

    Reply
  2. Tony Fantaci

    March 9, 2023 at 15:23

    I found the issue. Apparently PRTG does not like the “” symbols in the message. I removed them and it worked.

    Reply
    • Jasmin Kahriman

      March 11, 2023 at 09:06

      Hi Tony – Gald to hear it works now. Thank you for sharing a fix with us.

      Reply

Leave a Reply

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

Share via
Copy link