PowerCLI

 View Only
Expand all | Collapse all

Settings DiskIOPS Limit for all VMs in Cluster

nicholas1982

nicholas1982Nov 04, 2013 10:43 AM

LucD

LucDNov 05, 2013 07:33 AM

  • 1.  Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 04, 2013 04:30 AM

    Just wondering if there is a simple script to modify all attached disks to all VM's in the inventory whether powered on/off to limit IOPS to 500 for example?



  • 2.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 04, 2013 06:52 AM

    Try something like this

    foreach($vm in Get-VM){
     
    $hd = Get-HardDisk -VM $vm
     
    Get-VMResourceConfiguration -VM $vm |
     
    Set-VMResourceConfiguration -Disk $hd -DiskLimitIOPerSecond 500 -Confirm:$false
    }


  • 3.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 04, 2013 07:03 AM

    Thanks Luc,

    If I wanted to narrow it down to VM's in a cluster would it be something like this ?

    foreach($vm in Get-Cluster "MyCluster" Get-VM){
     
    $hd = Get-HardDisk -VM $vm
     
    Get-VMResourceConfiguration -VM $vm |
     
    Set-VMResourceConfiguration -Disk $hd -DiskLimitIOPerSecond 500 -Confirm:$false
    }



  • 4.  RE: Settings DiskIOPS Limit for all VMs in Cluster
    Best Answer

    Posted Nov 04, 2013 07:06 AM

    Nearly there, you have to use the pipeline ('|'), like this

    foreach($vm in (Get-Cluster -Name MyCluster | Get-VM)){
     
    $hd = Get-HardDisk -VM $vm
     
    Get-VMResourceConfiguration -VM $vm |
     
    Set-VMResourceConfiguration -Disk $hd -DiskLimitIOPerSecond -1 -Confirm:$false
    }


  • 5.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 04, 2013 07:10 AM

    Ahh yes of course thanks again Luc.

    Luc I know you have probably covered this before somewhere else, but would happen to have a simple report script to assess the IOPS of all guest vms over a certain period and have it spit out a neat report ?



  • 6.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 04, 2013 07:24 AM

    You mean something similar to this 3.  Re: Script to Generate IOPS Report  ?



  • 7.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 04, 2013 10:04 AM

    Hi Luc,

    Seems like it will do the trick, if I change the AddDays -1 too -7 will that average all the stats to 1 week ?



  • 8.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 04, 2013 10:16 AM

    Hi Luc,

    not sure what i'm doing wrong with that script to generate iops report, i get the following errors for all guests



  • 9.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 04, 2013 10:20 AM

    It looks as if your Statistic levels on the vCenter are not high enough.

    These counters require a Level 3 setting.



  • 10.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 04, 2013 10:34 AM

    Ok so if I set level 3 now, should it start working or will I have to wait a few days, also does the script take into account of the 20 sec vCenter samples ?



  • 11.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 04, 2013 10:41 AM

    It depends on the timeframe you ask for and on the time when the aggregation jobs run.

    If you change it now, then tomorrow you will most probably have less than 1 day of data available since the aggregation jobs run probably at night.

    So it's better to wait at least for the time interval you want + 1 day I would say.



  • 12.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 04, 2013 10:43 AM

    Thanks Luc, you're a Superstar!



  • 13.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 04, 2013 11:29 PM

    Hey Luc,

    Works a treat, is there an easy way to format the report into tables ?



  • 14.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 05, 2013 05:50 AM

    You mean a table in the email body ?

    Or an export to a CSV file ?



  • 15.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 05, 2013 05:55 AM

    Hi Luc,

    Table in the email body, a very long time ago you did this for a snapshot report, something similar to this would be perfect

    # Format html report

    $htmlReport = @"

    <style type='text/css'>

    .heading {

         color:#3366FF;

    font-size:12.0pt;

    font-weight:700;

    font-family:Verdana, sans-serif;

    text-align:left;

    vertical-align:middle;

    height:20.0pt;

    width:416pt

    }

    .bodytext {

         color:##000000;

    font-size:9.0pt;

    font-weight:400;

    font-family:Arial;

    text-align:left;

    vertical-align:middle;

    height:30.0pt;

    width:416pt

    }

    .colnames {

         color:white;

    font-size:8.0pt;

    font-weight:700;

    font-family:Tahoma, sans-serif;

    text-align:center;

    vertical-align:middle;

    border:.5pt solid windowtext;

    background:#99CC00;

    }

    .text {

    color:windowtext;

    font-size:8.0pt;

    font-family:Arial;

    text-align:center;

    vertical-align:middle;

    border:.5pt solid windowtext;

    background:#CCCCFF;

    }

    </style>

    <table border=0 cellpadding=0 cellspacing=0 width=555

    style='border-collapse:collapse;table-layout:fixed;width:600pt'>

    <tr style='height:15.0pt'>

      <th colspan=5 height=40 width=555 class="heading">

    Virtual.Offis vSphere Snapshot Report</th>

    </style>

    <table border=0 cellpadding=0 cellspacing=0 width=555

    style='border-collapse:collapse;table-layout:fixed;width:600pt'>

    <tr style='height:15.0pt'>

      <th colspan=5 height=40 width=555 class="bodytext">

    This is a reminder email of all the current snaphots.</th>

    <tr>

      <th class="colnames">VM</th>

      <th class="colnames">VM Current State</th>

      <th class="colnames">Name</th>

      <th class="colnames">VM Snapshot State</th>

      <th class="colnames">Date Created</th>

      <th class="colnames">Snapshot Created By</th>

    </tr>

    "@

    foreach($snapshot in $mySnaps){

      $htmlReport = $htmlReport +

      "<tr><td class='text'>" + $snapshot.vm.Name + "</td>" +

      "<td class='text'>" + $snapshot.CurrentPowerState + "</td>" +

      "<td class='text'>" + $snapshot.Name + "</td>" +

      "<td class='text'>" + $snapshot.PowerState + "</td>" +

      "<td class='text'>" + $snapshot.Created.ToString("dd/MM/yyyy HH:mm") + "</td>" +

      "<td class='text'>" + $snapshot.Creator + "</td></tr>"



  • 16.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 05, 2013 07:33 AM

    Try the attached script



  • 17.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 05, 2013 01:17 PM

    Hi Luc,

    Fantastic, I will run if the next few days and let you know how it goes.



  • 18.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 05, 2013 01:33 PM

    Sorry Luc, I wasn't going to bother you with this as its not a huge deal, but just in case you off the top of your head I will throw it out there.

    Whenever the email report gets sen,t Symantec Cloud email scanning injects the following message


    "This email has been scanned by the Symantec Email Security.cloud service."

    The only problem is it puts it smack bang in the middle (See Attached) this only happens with this report and the snapshot report. I have a feeling it something to do with the tables, again its not worth any effort to fix as its not big deal. Thanks



  • 19.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 05, 2013 02:38 PM

    I'll have a look at the generated HTML, but I'm no webpage specialist, so no guarantee for any result I'm afraid :smileygrin:



  • 20.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 05, 2013 09:55 PM

    Hey Luc, I really appreciate your efforts, it's all good however it not a huge issue :smileyhappy:



  • 21.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 05, 2013 11:59 PM

    Hi Luc,

    I would like a bit more control over the DateTime period, I tried to play around a bit with the $start $finish variables, the best I could get is setting the finish time minus how many days, in addition the preferred date format is dd/mm/yyyy. May I get your assistance here?

    $metrics = "disk.numberwrite.summation","disk.numberread.summation"

    $finish = Get-Date -Hour 23 -Minute 59 -Second 0

    $start = $finish.AddDays(-1)

    $report = @()

    $vms = Get-VM -Name "MyVM"| where {$_.PowerState -eq "PoweredOn"}

    $stats = Get-Stat -Stat $metrics -Entity $vms -Start $start -Finish $finish

    $interval = $stats[0].IntervalSecs

    $lunTab = @{}

    foreach($ds in (Get-Datastore -VM $vms | where {$_.Type -eq "VMFS"})){

      $ds.ExtensionData.Info.Vmfs.Extent | %{

        $lunTab[$_.DiskName] = $ds.Name

      }

    }

    $report = $stats | Group-Object -Property {$_.Entity.Name},Instance | %{

      $readStat = $_.Group |

        where{$_.MetricId -eq "disk.numberread.summation"} |

        Measure-Object -Property Value -Average -Maximum

      $writeStat = $_.Group |

        where{$_.MetricId -eq "disk.numberwrite.summation"} |

        Measure-Object -Property Value -Average -Maximum

      New-Object PSObject -Property @{

        VM = $_.Values[0]

        Start = $start

        Finish = $finish

        Disk = $_.Values[1]

        IOPSWriteMax = [math]::Round($writeStat.Maximum/$interval,0)

        IOPSWriteAvg = [math]::Round($writeStat.Average/$interval,0)

        IOPSReadMax = [math]::Round($readStat.Maximum/$interval,0)

        IOPSReadAvg = [math]::Round($readStat.Average/$interval,0)

        Datastore = $lunTab[$_.Values[1]]

      }

    }



  • 22.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 06, 2013 12:26 AM

    Ok I managed to get what I want using this

    $start = Get-Date -Day 6 -Month 11 -Year 2013 -Hour 10 -Minute 23 -Second 0

    $finish = Get-Date -Day 6 -Month 11 -Year 2013 -Hour 10 -Minute 25 -Second 0

    Just trying to figure out changing the Date format.



  • 23.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 06, 2013 05:46 AM

    You can use the Format parameter like this

    Get-Date -Format "dd/MM/yy"

    Or from a variable with a DateTime value

    $start.ToString("dd/MM/yy")



  • 24.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 06, 2013 09:50 AM

    Thanks Luc,

    I'm having a strange issue, to test the scripts, I'm generating about 4500 iops on one VM for a very short interval about 1 - 2 mins and then ran the script only against that VM.

    The first thing I noticed was if I specified the TimeDate period of a few minutes the results came through as expected with the correct MaxRead IO.

    After about 1 hour I couldn't run the script again with that short period, it generated the following error

    Cannot index into a null array.

    At C:\scripts\VM-IOPS-report-HTML.ps1:10 char:20

    + $interval = $stats[ <<<< 0].IntervalSecs

        + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException

        + FullyQualifiedErrorId : NullArray

    I then noticed by increasing the period I could run it again however i lose the MaxReadIO result, see attached. I think it must have something to do with vCenter statistics.

    This was run shortly after the generated IO at about 10.50

    This was run just a few moments ago at about 20.35

    I changed the stats logging today to this.



  • 25.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 06, 2013 11:49 AM

    Did the aggregation jobs do their work ?

    On an SQL server you can go to Management Studio and look at the Jobs.

    Check the History for those jobs. Did they run and when ?

    A quick verification can be done from the vSphere Client.

    Go to the Performance tab and under Advanced select the counter.

    Is there data visible for the time frame you specified ?



  • 26.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 06, 2013 12:13 PM

    Hi Luc, This is what shows up.



  • 27.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 06, 2013 12:20 PM

    Hi Luc,

    So I checked SQL and the jobs have been running, the past day stats rollup have been running every 30 mins.

    Is that what you were wanting to know?



  • 28.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 06, 2013 12:30 PM

    Yes, so the data is aggregated.

    That strange line you see is because there are apparently only 2 samples, each for a 5-minute interval.

    Wait a bit longer till you have more samples for the 5-minute intervals, and then specify a longer period (with $start and $finish)



  • 29.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 06, 2013 12:34 PM

    Hi Luc,

    So if one VM did nothing most of everyday except for a 1 -2 min period when IO spiked to 5K+ IOPS would there be any way of capturing that information? the day or week after the event ?



  • 30.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 06, 2013 01:34 PM

    That is correct, the Min/Max require level 4, but the script gets the Min/Max of the Average counters.

    So it only requires level 3.

    With aggregation you loose granularity.

    In Historical Interval 4, the metrics are averaged over a 1 day interval.

    In there it is impossible to discover a 2 minute burst.

    After  1 week, the interval will already be aggregated to a 30 minute interval.

    Even there it will be very difficult to detect 2 minute bursts I'm afraid.

    Even collecting the Min/Max for that Historical Interval will not give you all the info.

    You will know about the Max, but you have no direct indication how long that Max was maintained.

    In combination with the Avg, you should be able to deduce an estimate of the duration, but that will not be foolproof.

    I have an section on just this in my upcoming book :smileycool:



  • 31.  RE: Settings DiskIOPS Limit for all VMs in Cluster

    Posted Nov 06, 2013 12:30 PM

    Hi Luc,

    It may have something to do with the statistic type which "Read Request" is a Delta stat and if i'm reading this correctly this document says something about only level 4 retains min/ max stats.

    VMware vSphere 4 - ESX and vCenter Server