Determining VM doing I/O on a Hyper-V host

265

Solution 1

Open Performance Monitor (run as Admin) on your local workstation. Add counter, select counters from the hyper-v machine, Hyper-V Virtual IDE Controller or Hyper-V Virtual Storage Device, select counters and instances (VMs) as seems appropriate. You might have to fish around a bit to find the counter that makes the most sense to you.

There are some good hints as to which Counters to look for in Monitoring Hyper-V Performance

Solution 2

Syneticon-dj, I wrote something for you this afternoon. I thought this problem was interesting, so this simple script will give you the read and write IO stats on each running VM on the Hyper-V host. As an added bonus it associates each VM to its vmwp.exe's Process ID.

You can run this on your Hyper-V server, because it doesn't need a GUI.

The downside is that while I was working on this, I noticed that the performance counters were working great for a while, and then for no discernible reason they decided to all stay on zero. Well maybe it's not a bug, like Chris S says... but these counters might unfortunately not be very useful after all. Regardless, it would be very easy to modify the script to use the Virt. Storage Device counters instead.

The output looks like this:

PID     VMName               ReadBytesPerSec             WriteBytesPerSec
---     ------               ---------------             ----------------
5108    DC02                          483.90                            0
2796    DC01                               0                            0
3348    ECA01                     4782668.27                            0

#Requires -Version 3
function Get-VMPidAndIO
{
<#
.SYNOPSIS
    Gets the Process ID and I/O statistics of each virtual machine running on the Hyper-V host.
.DESCRIPTION
    Gets the Process ID and I/O statistics of each virtual machine running on the Hyper-V host.
    Currently only works for VMs using virtual IDE controllers.
    Requires Powershell 3 at a minimum.
.LINK
    http://myotherpcisacloud.com
.NOTES
    Written by Ryan Ries, June 2013.
    [email protected]
#>
    BEGIN
    {
        Try
        {
            $VMProcesses = Get-CimInstance -Query "Select ProcessId,CommandLine From Win32_Process Where Name ='vmwp.exe'" -ErrorAction Stop
        }
        Catch
        {
            Write-Error $_.Exception.Message
            Return
        }
    }
    PROCESS
    {

    }
    END
    {
        Foreach($_ In $VMProcesses) 
        {
            $VMName = $((Get-VM | Where Id -EQ $_.CommandLine.Split(' ')[-1]).Name)            
            [PSCustomObject]@{PID=$_.ProcessId;
                              VMName=$VMName; 
                              ReadBytesPerSec=[Math]::Round($(Get-Counter "\Hyper-V Virtual IDE Controller (Emulated)($VMName`:Ide Controller)\Read Bytes/sec").CounterSamples.CookedValue, 2);
                              WriteBytesPerSec=[Math]::Round($(Get-Counter "\Hyper-V Virtual IDE Controller (Emulated)($VMName`:Ide Controller)\Write Bytes/sec").CounterSamples.CookedValue, 2); }
        }

    }
}

Solution 3

I wrote a PowerShell GUI tool gathering Guest performance data for all VM's found on selected Hyper-V hosts. Data gathering and matching is done with get-counter and Hyper-V WMI information. Run from any member server, no modules required. I hope this will help in quickly troubleshooting performance problems on Hyper-V hosts and VM's.

Show Hyper-V Virtual Machine Guest Performance Statistics (PowerShell) https://gallery.technet.microsoft.com/Show-Hyper-V-Virtual-652fdd54

Solution 4

Both of the other answers are useful. But I find that I get what you're looking for much more easily (when the VHDs are stored on local or locally shared disks instead of a file server) by opening up "Resource Monitor" and looking at the Disk tab. Look at "Disk Activity" and sort by "Total (B/sec)." You'll see the VHDs listed in order of their activity.

Obviously my strategy is a loose approximation for machines that you're locally logged into, which makes it less useful in a big, headless environment.

Share:
265

Related videos on Youtube

Bobimaru
Author by

Bobimaru

Updated on September 18, 2022

Comments

  • Bobimaru
    Bobimaru almost 2 years

    Usually when I loop through a database table records, I put them in 1 div, however, I have been wondering whether it is possible to create 3 divs and then put one record in each div, then start from the first div again and rinse and repeat.

    Example of how I've done it so far:

    <div class="container">
        @foreach($albumImages as $albumImage)
        <div class="centeredImage stickyContainer" style="background-image: url('/storage/uploads/albums/{{$albumName}}/{{$albumImage->file_name}}')">
            <a class='specialA' href=''></a>
        </div>
        @endforeach
    </div>
    

    As you can see in this case, all the records are in the container div.

    Example of what I've been thinking about:

    <div class="flex-grid">
        <div class="col-l"></div>
        <div class="col-c"></div>
        <div class="col-r"></div>
    </div>
    

    and have the first record go in col-l, the second in col-c, the third in col-r and then start from col-l again.

    • the-wabbit
      the-wabbit about 11 years
      @RyanRies no, I do not see vmwp.exe involved in any of the I/O. As I do not know which disks the load is going to, I can't tell if it is taking the IDE or the SCSI code path, both seems equally possible.
    • Lovepreet Singh
      Lovepreet Singh almost 6 years
      This can be achieved with the help of Javascript.
    • Loek
      Loek almost 6 years
      Yes, it's certainly possible. There's tons of ways to do this though (both in PHP and JavaScript, though I would go the PHP route), so it's kind of hard to answer this question in a way everybody is happy.
    • Bobimaru
      Bobimaru almost 6 years
      Can you tell me what should I be looking for in google in order to find how to do something like that using PHP?
    • Loek
      Loek almost 6 years
      Take a look at this answer, it should get you pointed in the right direction (tip: replace the 4 with 3 and add the classes manually): stackoverflow.com/a/19588744/4074200
    • Bobimaru
      Bobimaru almost 6 years
      I'll check it out, thank you very much!
    • René
      René almost 6 years
      Assuming it's just for styling, you're better off using css nth-child selectors. That would also be more useful if you want to make the site responsive.
  • the-wabbit
    the-wabbit about 11 years
    Mmh, I tried that. It did not yield useful results and I have no idea why this is so. At first, I had trouble locating the Virtual Storage Device counters - it seems like they are not present on my installs. Since most of my disks are IDE, I gave the Virtual IDE Controller a shot but for some unfathomable reasons it is not returning anything but zeros for the instance actually causing the load (which I stumbled upon by accident in the meantime) - whereas other instances seem to produce sane values.
  • Philip
    Philip about 11 years
    If you have the VM Integration stuff installed then you're not using IDE (regardless of what the configuration screen says; don't get me started on MS's poor config screen choices), so you have to use the Virt Stor Dev counters. The latter are per VHD, not per VM, so there's a little bit of dereferencing involved.
  • the-wabbit
    the-wabbit about 11 years
    This clears it up. I finally found the virtual storage device, it seems to return sane values for the virtual disks.
  • Philip
    Philip about 11 years
    That's not a bug, see comments in my answer.
  • Ryan Ries
    Ryan Ries about 11 years
    Then I wonder why the counters seem to intermittently work? (Windows guests with full integration services.) And why they would choose the significantly less useful level of abstraction of per-VHD counters instead? :(
  • Philip
    Philip about 11 years
    Not sure why it would show anything intermittently. As for why, it's the way storage works in Hyper-V. Essentially there is only one storage controller for all VMs. By using an "IDE Controller" in the configuration you are just enabling IDE Emulation for the storage exposed to that VM (as opposed to the "SCSI Controller" that has nothing to do with SCSI, and just disables any sort of storage controller emulation). VMs that support Integration Services just skip the IDE emulation. The storage controller counters don't exactly care what VM is attached to each VHD, hence the way it works.
  • Ryan Ries
    Ryan Ries about 11 years
    Awesome. Thanks for the info. I'm extremely interested in reading more about this, but I'm having a hard time turning up any good technical documentation. I think it would behoove MS to demystify a lot of this stuff for us. We'd be able to put more confidence in their solutions. I just want a Hyper-V Internals book. Is that too much to ask? :)
  • Koen Zomers
    Koen Zomers over 10 years
    Chris S is right. The exact name of the performance monitor counter he refers to is "Hyper-V Virtual Storage Device". I.e. the "Queue length" in this category gives a nice insight into which of your VHD(X) files is having most latency communicating with your disk.
  • Bobimaru
    Bobimaru almost 6 years
    Doesn't that just create the column divs? My goal is to populate them with my database records as well
  • Davit Zeynalyan
    Davit Zeynalyan almost 6 years
    That case put your code instead of <div class="col-*"></div>
  • Bobimaru
    Bobimaru almost 6 years
    This is what I don't get, I'm obviously not supposed to create the columns using the loop since this will result in more than 3 columns if I have more than 3 records, so how am I exactly supposed to first create only 3 columns and then populate them with every first, every second and every third record?
  • Bobimaru
    Bobimaru almost 6 years
    Wow, works like a charm, is it bad that there are so many ifs and foreach?
  • Davit Zeynalyan
    Davit Zeynalyan almost 6 years
    Latest 3 foreach need for you. I think I can decrease one foreach in my answer. @if (!empty($albumImages1)) this conditions never get error when $albumImages count small then 3
  • Loek
    Loek almost 6 years
    @Bobimaru It's not necessarily. This was what I was getting at with my comment that this question isn't really solvable in a way that makes everybody happy. Really custom functionality like this requires really custom code and that just isn't of use to anyone but you. Good answer though!
  • Bobimaru
    Bobimaru almost 6 years
    I mean in general? I'm actually using this just for styling ( masonry effect for my images ) which I'm sure can be done with JavaScript but have no idea how to do it. This is why I'm wondering if this is not clean/fast code and whether I should keep it or try to figure the JavaScript counterpart.
  • Progrock
    Progrock almost 6 years
    Granted that this needs some translation to your template engine.
  • Bobimaru
    Bobimaru almost 6 years
    In my case, John and George should be in the same div col-a and there should be no more than 3 divs though.
  • Progrock
    Progrock almost 6 years
    @Bobimaru perhaps edit your question, you say: "and have the first record go in col-l, the second in col-c, the third in col-r and then start from col-l again."
  • Bobimaru
    Bobimaru almost 6 years
    Sorry for misrepresenting my question but by "start from col-l again" I meant have my fourth record go inside the first col-l.
  • Davit Zeynalyan
    Davit Zeynalyan almost 6 years
    @Bobimaru see my updated answer last part it is more good solution then previous solutions
  • Progrock
    Progrock almost 6 years
    @Bobimaru added an example.
  • Bobimaru
    Bobimaru almost 6 years
    If I may ask 1 final question. I've been trying to make this work with 4 columns as well using your code, however, I'm not sure what condition to set in the foreach($albumImages as $albumImage) code that separates the images
  • Davit Zeynalyan
    Davit Zeynalyan almost 6 years
    that case @php(list ($albumImages1, $albumImages2, $albumImages3, $albumImages4) = split_sequence_by_count($albumImages, 4)) That case you need 4 foreach
  • Bobimaru
    Bobimaru almost 6 years
    Great, thank you very much, you made it so clear for me.