Hyper-V Resource Metering Using PoSHStats – Free tool

Yusuf Ozturk has designed an elaborate PowerShell script that allows you to visually meter the resource utilization of your Hyper-V 2012 virtual machines in a web browser. This tool works even if your hosts are running Hyper-V Server, as it relies on PoSHServer instead of IIS.

Metering vs. Monitoring

I’m not entirely certain if there’s a lot of industry standardization around these two terms, but this tool reads the metering counters. It tells you what resources your virtual machines are using. Monitoring is probably more appropriate to a real-time tool that checks things like availability, response, and uptime statistics.

Acquisition and Installation

First, obtain PoSHServer. Extract the .msi file to your Hyper-V host and run it. Accept the defaults.

Next, obtain PoSHStats itself. As with PoSHServer, extract its .msi file to your Hyper-V host and run it, accepting the defaults.

Once both of these packages have been installed, open a PowerShell prompt. In a GUI installation of Windows Server 2012, right-click on the PowerShell icon on the task bar or from the Start screen and click “Run as administrator”. In a core or Hyper-V Server 2012 installation, just type POWERSHELL at a command prompt and hit [Enter]. Once in PowerShell, type:

Start-PoSHStats -Hostname sv-hyperv1 -Port 8080

The documentation indicates using “localhost” for the host name. This will work, but you’ll only be able to view the website using a browser on the local system. That would be a bit tough if you’re using a GUI-less system. Whatever you enter for the name will be the name that the server responds to from remote requests. So, the above will enable the system to respond to http://sv-hyperv1:8080, but it will give a 400 error on http://sv-hyperv1.mydomain.local. If you like, you can enter this command again with alternate host names. The only negative to this that I can see is that for each entry you make, you get another Scheduled Task that runs all the time. Task Manager shows that these sit at 0% CPU, so it’s up to you if that’s a problem or not.

You can choose most anything you like for the port number instead of 8080. 8080 is the common port number for web sites that don’t run on the standard http port of 80. There are a few other parameters you can modify if you like, such as where to place the data files. After the port number, type a hyphen and then use [TAB] to cycle through the other options.

Upon running the command for the first time, you’ll get an informational screen. I advise that you read through it, but all you need to do here is tell it how to handle your virtual machines. You can either have it automatically gather statistics for all current virtual machines by pressing [1] or you can select the VMs you want later by pressing [2].

PoSHStats pulls its data from the same location as the built-in metering tool, so to enable a specific VM to watch and run the built-in cmdlet:

Get-VM -VMName svdc1 | Enable-VMResourceMetering

Of course, if you don’t enter a specific VM name, it will enable monitoring for all on the local host.

If the host is in a cluster, it will automatically look at the other members. If you selected option 2 above, to enable metering of a VM that is not on your current host, run the following cmdlet:

Get-VM -VMName svdc2 -ComputerName sv-hyperv2 | Enable-VMResourceMetering

If you’ve left the firewall active on your Hyper-V host, make a hole for request to PoSHServer to get through:

New-NetFirewallRule -Name "PoSHServer" -DisplayName "PoSHServer" -Direction Inbound -Protocol TCP -LocalPort 8080 -Action Allow -Enabled True

Of course, if you used a different port number, that will be the one you need to open.

Advanced Usage

You can run PoSHStats to monitor Hyper-V from another machine, but it must be in the same domain as the system to meter. Open the following file in Notepad (Notepad is included in Hyper-V Server 2012 and Windows Server 2012 Core; just type “notepad” and press [Enter]): C:\Windows\System32\WindowsPowerShell\v1.0\Modules\PoSHStats\config\hosts.ini. Add the host name(s) of your Hyper-V system(s), one per line. You’ll also need to do this if you’re operating in a cluster and it doesn’t pick up other members.

The documentation mentions that to gather stats from another system, you’ll have to change the account that the scheduled task runs under. I did not need to do this to manage the other host in my cluster, but that’s likely due to the fairly unique security configuration of cluster hosts. The Scheduled Task runs under the local system account (basically, the computer account), and that account usually doesn’t have permissions to do anything on any other system. If you’re running PoSHStats on a GUI installation, open up Task Scheduler and change the properties of the running task so that it is using a domain account with admin-level privileges on the target Hyper-V host(s). To perform this from PowerShell:

Get-ScheduledTask posh* | Set-ScheduledTask -User domain\appadmin -Password P@ssw0rd

Don’t use a regular logon account for these or you’ll have some odd issues. In fact, you might have some odd issues running under a domain account anyway. After a reboot, I had to stop and start the tasks in Task Scheduler before I could get the pages to load at all.

Results

Wait! Don’t get impatient! It took about an hour for my guests to start showing up. This is expected for VM metering.

I may have done something wrong while I was fiddling, but my primary host shows up twice in the report. I managed to break my installation in a few ways, mostly through repeated uninstallations and deletions of the containing folders. For instance, one of my hostnames no longer works (http://sv-hyperv1). I always get a blank screen. Other hostnames I use work fine (localhost and sv-hyperv1.siron.local). I don’t even know if the problem is in PoSHStats or PoSHServer. For the 99% of you who will install and walk away from it, you’re going to be just fine. If you’re a fiddler like me, your mileage may vary.

Another thing to note, if you connect using IE 10, it will prompt you to install Adobe Flash each time. It’s built in to IE 10 so you can’t actually update it. Just ignore the prompt or use a different browser.

PoSHStats

PoSHStats in Action

 

 

Altaro Hyper-V Backup
Share this post

Not a DOJO Member yet?

Join thousands of other IT pros and receive a weekly roundup email with the latest content & updates!

11 thoughts on "Hyper-V Resource Metering Using PoSHStats – Free tool"

  • Ken Olson says:

    Good news! On my two installations, the clients appeared instantly…or as quick as I could type in the url anyway. I did run from the host desktop instead of remotely. Also, in both cases, I did run IE10 (Server 2012 don’t ya’ know) and there was no flash error.

  • Yngve Spång says:

    Running Windows 2008R2 core Hyper-V server. Manage to install PoSHServer on one of my blades with above mention OS. When trying to install PoSHStats, which I downloaded following the link on top of this article, I get the message “PoSHStats cannot be installed on the following versions: …” indicating all Windows x64 OS. How to install it?

  • JBX says:

    When I execute the first command I got an error. What do I Wrong?

    Start-PoSHStats : The ‘Start-PoSHStats’ command was found in the module ‘PoSHStats’, but the module could not be loaded
    . For more information, run ‘Import-Module PoSHStats’.
    At line:1 char:1
    Start-PoSHStats -Hostname Ghzshyperv002 -Port 8080
    ~~~~~~~~~~~~~~~
    CategoryInfo : ObjectNotFound: (Start-PoSHStats:String) [], CommandNotFoundException
    FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

    • Eric Siron says:

      Hi,
      I’ve been leaving your post unanswered because I don’t know the answer and I was hoping someone else would jump in.
      All I can suggest is trying the ‘Import-Module PoSHStats’ line that it recommends. If that doesn’t help, I’ll unfortunately need to refer you back to the script’s creator. I just don’t have the necessary internal knowledge of this script to give you an authoritative answer.
      Sorry!

  • Babu says:

    Hi,
    I installed and started PosHStats in a Windows Server 2012 (HyperV enabled) successfully and working as expected. But I did a mistake that I have configured it with HostName set as LOCALHOST, so I was not able to browse to “https://:8080” from remote machine.
    So I tried the below,
    – Stopped the Job in Task Scheduler
    – Uninstalled PoshServer and PoshStats
    – Deleted all contents from PoshServer and PoshStats and removed the folder as well

    Then I reinstalled PoshServer and PoshStats on the same Server and ran the below command,

    “Start-PoshStats -HostName server01 -port 8080”
    And I got the acknowledgement as You can browse to the URL “http:server01:8080”. But when I try to browse that URL, I’m getting white Page with footer set to “@Copyright 2012. All rights Reserved. Virtual Machine REsource Usage Report by PoSHStats”

    Even I tried creating another job with port no 82 as well, but the same issue.

    • Eric Siron says:

      Unfortunately, none of us here have the inside knowledge to provide support for this product. I have encountered a similar problem and never found a fix. You may be able to contact the author through his site for assistance.

  • Paul Gagne says:

    The link to PoSHStats takes you to , which does not appear as free source for the tool needed. I downloaded the VirtualMetric software, thinking it was included in the package. I could not complete the install because it needs SQLExpress. Am I missing something? How can I get a copy of PoSHSTats?

    • Eric Siron says:

      You’re not missing anything. PoSHStats was discontinued in favor of this new product. Someone I spoke with a while back was able to uncover an old version on an independent download site somewhere, but I don’t have any further information.

Leave a comment or ask a question

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

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

Notify me of follow-up replies via email

Yes, I would like to receive new blog posts by email

What is the color of grass?

Please note: If you’re not already a member on the Dojo Forums you will create a new account and receive an activation email.