Good news! Mr. Brandon Gordon reached out and informed me of a way to accomplish everything I have outlined below with a simple out-of-the-box feature available in vRealize Operations 7.5 and newer. The VM Property “Summary|Runtime|Power State” can be added to a View and transformed to a ‘relative timestamp’ value to show the number of days a VM has been powered off (see below). At least I learned a lot while doing it the hard way 🙂
One of my colleagues recently had a question from his customer asking if there is a way to determine how long a VM has been powered off. This information would be extremely valuable for virtual administrators to help determine if a VM can be deleted or not based on when it was last powered on. A VM decommissioning process could even be built around this value. I quickly jumped into vRealize Operations and checked for an out-of-the-box metric or property that would fulfill this customer request. vRealize Operations easily tracks the amount of time a VM has been powered on; however, there is nothing to help measure how long a VM has been powered off. 🙁
Since I always enjoy a good challenge, I began thinking of ways in which I could make this happen. I was able to create a solution; however, there are a few caveats… more about these later.
The Solution – Super Metrics to the rescue!
I decided that creating a Super Metric to track this value was the only way to accomplish the task. Initially, I wanted to store the date/time value of when the VM was powered off and then use some date math to calculate the desired value. However, this proved to be more challenging than expected. I ended up creating a Super Metric that essentially adds 5 minutes to itself each time it is evaluated. I used the 5 minute increment value since that is the default collection interval within vRealize Operations; however, you will want to adjust this if you are not using default collection intervals.
The Calculation Details
The Super Metric calculation itself is quite simple and uses a single Ternary Operator to determine if the VM is powered on or off. See HERE for additional details regarding how to use Ternary Operators. The basic logic is as follows:
- If the VM is powered on then set the value of the Super Metric to 0.
- If the VM is powered off then add 5 (minutes) to the previous value of the Super Metric.
Below is what the Super Metric looks like:
While this solution can add a powerful new metric to your toolkit, it is not perfect. Below are the four caveats that I discovered along the way:
- Initializing the Super Metric – Since the Super Metric formula references itself, you will receive an error if you try to create it with the formula outlined above. This is because vRealize Operations is not aware of the Super Metric yet. You will initially have to set the formula/value to “0” and let at least one collection interval pass. Once vROps is aware of the Super Metric you can then go back and correct the formula.
- Data will only exist going forward – Since the powered off duration is not something we can calculate historically or get from vCenter, vROps will only track the value going forward. Duh. This will result in incorrect values for any VMs that were powered off prior to implementing the Super Metric.
- Potential gaps associated with outages – Since this Super Metric is dependent upon a consistent collection cycle, the metric could reflect a lower value than it should if there are outages with vCenter, the vSphere Management Pack, vROps itself, or anything else that could impact the metrics collection process. Better to have a lower value than a higher value when leadership asks… you can respond that the VM has been powered off AT LEAST this long.
- NULL Values – Any newly created VMs that never get powered on will have NULL values. This is because the Super Metric formula references itself and it will not exist until it is powered on and set to 0. In my opinion, having the ability to identify VMs that have never been powered on is less of a caveat and more of a feature. Yeah, that’s right… I made it this way intentionally, sure.
Making it Look Pretty
After creating the Super Metric, I then created a simple View that lists all the Powered Off VMs (excluding Templates) and their associated powered off duration in Days (see below). Notice the VM ‘test04’ has a NULL value… this is because it was created after the Super Metric was created and it has never been powered on. This View can be added to Dashboards, Reports, or just ran on-demand.
Check out the YouTube video HERE for a step-by-step walk through of how to build everything that was outlined above.
While this Super Metric is not perfect it can still add a tremendous amount of business value to an organization. Be sure to implement this NOW so you will have the data available when leadership or a business group wants to know how long a particular VM has been powered off.