Automation

 View Only
Expand all | Collapse all

Log of storage vmotions

  • 1.  Log of storage vmotions

    Posted Jan 30, 2012 04:07 AM

    I'm looking for a powerCLI script that will create a log of storage vmotions done for the month.  I think it will involve using Get-ViEvent but not sure how to corelate the VM name, source datastore, destination datastore, and date into one report.  Ideally I would like to see it like this.

    Date, VM Name, Source_datastore, Destination_datastore

    Thank you,



  • 2.  RE: Log of storage vmotions
    Best Answer

    Posted Jan 30, 2012 09:17 AM

    You can fetch the svMotions like this

    $events = Get-VIEvent -MaxSamples [int]::MaxValue -Start (Get-Date).AddMonths(-1) |
    where {$_.GetType().Name -eq "TaskEvent" -and $_.Info.DescriptionId -eq "VirtualMachine.relocate"}

    but afaik the source and destination datastores are not in the event.

    It could be that this is changed in vSphere 5 (don't have access to a vSphere 5 box right now).



  • 3.  RE: Log of storage vmotions

    Posted Jan 30, 2012 03:13 PM

    Looks like a good start.  With powercli 5.0 I get the following

    Get-VIEvent : Cannot bind parameter 'MaxSamples'. Cannot convert value "[int]::
    MaxValue" to type "System.Int32". Error: "Input string was not in a correct for
    mat."
    At line:1 char:34


  • 4.  RE: Log of storage vmotions

    Posted Jan 30, 2012 04:33 PM

    That expression should be in parenthesis

    $events = Get-VIEvent -MaxSamples ([int]::MaxValue) -Start (Get-Date).AddMonths(-1) |
    where {$_.GetType().Name -eq "TaskEvent" -and $_.Info.DescriptionId -eq "VirtualMachine.relocate"}


  • 5.  RE: Log of storage vmotions

    Posted Jan 30, 2012 04:37 PM

    Hi htwnrver,

    I am not sure why [int]::MaxValue is not working - I believe this is specifying to the cmdlet to use the maximum supported value for this type of query. So instead of "[int]::MaxValue" you could try replacing that with a standard integer value such as 500. This should in theory get the last 500 samples then and the cmdlet should work for you.

    *edit* - thanks LucD :smileyhappy: Parenthesis explains why it wasn't working!

    Also another small typo correction for LucD's script - in the DescriptionId part - it is missing the "s". Furthermore, for vSphere 5 I believe the DescriptionId is a bit different. Try the following:

    $events = Get-VIEvent -MaxSamples ([int]::MaxValue) -Start (Get-Date).AddMonths(-1) |
    where {$_.GetType().Name -eq "TaskEvent" -and $_.Info.DescriptionId -eq "StorageResourceManager.applyRecommendation"}

    StorageResourceManager.applyRecommendation is what I get as a DescriptionId for tasks when I storage vMotion a VM in my vSphere 5 lab environment, so the above should work.



  • 6.  RE: Log of storage vmotions

    Posted Jan 30, 2012 04:43 PM

    Thanks for catching the typo, I corrected the missing 's'.

    The [int]::MaxValue is not working because parameter type checking. The cmdlet sees this coming in as a [string], hence the message.

    With the parenthesis we force the PS engine to first convert the expression to an actual [int].



  • 7.  RE: Log of storage vmotions

    Posted Jan 30, 2012 05:03 PM

    Ah that makes sense - the same then in mathematics where the parenthesis are handled first in calculations? MaxValue is working nicely now with those parenthesis added - thanks.

    I have tested in a vSphere 4.0 environment - Info.DescriptionId has a value of VirtualMachine.relocate in 4.0 (and 4.1 too I assume). In my vSphere 5 lab, it appears to be Info.DescriptionId with a value of "StorageResourceManager.applyRecommendation" for storage vMotions...



  • 8.  RE: Log of storage vmotions

    Posted Jan 30, 2012 10:12 PM

    I was curious to know why I was getting different results with storage vMotion using vSphere 5 and using the above examples to fetch svMotion events, so I had a bit of a further play around with this in my lab setup this evening.

    The reason why I saw svMotions only when searching for events using this cmdlet:

    $events = Get-VIEvent -MaxSamples ([int]::MaxValue) -Start (Get-Date).AddMonths(-1) | Where {$_.GetType().Name -eq "TaskEvent" -and $_.Info.DescriptionId -eq "StorageResourceManager.applyRecommendation"} | Select CreatedTime, UserName, FullFormattedMessage

    is because of SDRS and Datastore Clusters it would seem. When you svMotion a VM between Datastore Clusters, the event seems to be come through under Recent Tasks as "Apply Storage DRS recommendations". However, if you svMotion the VM into a normal Datastore, which is not part of a Datastore cluster, then it comes through as "Relocate virtual machine". This is the difference, and hence the reason when I first tried earlier that I saw the event only when searching for "StorageResourceManager.applyRecommendation". (I was testing svMotion by moving a VM between two datastore clusters).

    Now, I disassembled a datastore cluster to create a couple of normal datastores and migrated some VMs around these - the events now come up as expected as "Relocate virtual machine".

    So what that means is if you are using Datastore Clusters with vSphere 5 only, then you should use the example above in this post. If you are using normal datastores in vSphere 4 or 5, then use Luc's example in his first post. Or, if you want to cover all your bases and are using both normal Datastores and Datastore clusters, then the following should work:

    $events = Get-VIEvent -MaxSamples ([int]::MaxValue) -Start (Get-Date).AddMonths(-1) | Where { $_.GetType().Name -eq "TaskEvent" -and $_.Info.DescriptionId -eq "VirtualMachine.relocate" -or $_.Info.DescriptionId -eq "StorageResourceManager.applyRecommendation"} | Select CreatedTime, UserName, FullFormattedMessage

    This will give you a list of both types of storage vMotion that have occurred.

    Here is an example in my environment (vSphere 5) where I have svMotioned between DS clusters and normal Datastores:

    http://dl.dropbox.com/u/450727/svmotion-differences.jpg

    Message was edited by: Shoganator - Syntax highlighting!



  • 9.  RE: Log of storage vmotions

    Posted Jan 30, 2012 10:17 PM

    Ah - we are only licensed for Enteprise so havne't got to play with StorageDRS yet.



  • 10.  RE: Log of storage vmotions

    Posted Jan 30, 2012 10:25 PM

    Aha, that answers which one you need to use then. Anyway, hopefully the above is helpful for others looking at what you were after that have a StorageDRS / Datastore cluster environment! :smileyhappy:



  • 11.  RE: Log of storage vmotions

    Posted Mar 30, 2013 03:26 AM

    This looks good, But if we get the "Target" & "VMname" also that would be great.. can some one help me..



  • 12.  RE: Log of storage vmotions

    Posted Mar 31, 2013 01:03 AM

    Have a look at my Get the vMotion/svMotion history post.



  • 13.  RE: Log of storage vmotions

    Posted Dec 21, 2019 03:32 PM

    LucD,

    I'm trying to fetch the storage vmtion logs to find out what caused the storage exhausted, but it throws an error. Need your help

    PS D:\vmk> .\svmlogs.ps1

    Get-VIEvent : Cannot bind parameter 'MaxSamples'. Cannot convert value "[int]::MaxValue" to type "System.Int32".

    Error: "Input string was not in a correct format."

    At D:\vmk\svmlogs.ps1:1 char:35

    + $events = Get-VIEvent -MaxSamples [int]::MaxValue -Start (Get-Date).A ...

    +                                   ~~~~~~~~~~~~~~~

        + CategoryInfo          : InvalidArgument: (:) [Get-VIEvent], ParameterBindingException

        + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetEvent

    Thanks

    vmk



  • 14.  RE: Log of storage vmotions

    Posted Dec 21, 2019 03:36 PM

    Place brackets around the value

    $events = Get-VIEvent -MaxSamples ([int]::MaxValue)



  • 15.  RE: Log of storage vmotions

    Posted Dec 21, 2019 03:45 PM

    LucD,

    Can we fetch for last 1 day or 1 week  first ? I want see whether its really able to collect data because 1 months is long data.

    Week and day both want to try

    thanks

    vmk



  • 16.  RE: Log of storage vmotions

    Posted Dec 21, 2019 03:53 PM

    In my post Get The VMotion/SvMotion History, I created the function Get-MotionHistory.

    That function accepts Days, Hours or Minutes as a parameter.
    Have a look at the Sample Usage section in that post.



  • 17.  RE: Log of storage vmotions

    Posted Dec 21, 2019 04:04 PM

    Tried, but it runs forever. Can it be faster ?

    $events = Get-VIEvent -MaxSamples ([int]::MaxValue) -Start (Get-Date).AddDays(-1) |

    where {$_.GetType().Name -eq "TaskEvent" -and $_.Info.DescriptionId -eq "VirtualMachine.relocate"}



  • 18.  RE: Log of storage vmotions

    Posted Dec 21, 2019 04:30 PM

    You could use my Get-VIEventPlus function, which is included in that post I referenced in my previous reply.
    But retrieving events from vCenter is not very fast I'm afraid.



  • 19.  RE: Log of storage vmotions

    Posted Jul 24, 2023 05:37 PM

    Hello  I have been trying to get the following information from currently running s-vMotion tasks

    Start Time, SrcHost, SrcStorage, DstHost DstStorage & Percent complete when s-vMotioning to a datastore cluster.

    might you be able to point me in the right direction?



  • 20.  RE: Log of storage vmotions

    Posted Jul 24, 2023 05:50 PM

    You can check the TaskEvent related to the svMotion task.
    You might give my Get-TaskPlus form Task Data Mining – An improved Get-Task a try.
    Use the Realtime switch.

    Not sure if all the info you are after is in there though.



  • 21.  RE: Log of storage vmotions

    Posted Jul 24, 2023 06:22 PM

    I think I have used Get-TaskPlus already, but I will try again

    and I will check into the TaskEvent as well.