WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud Foundation
  • VKS
  • Homelab
    • Resources
    • Nested Virtualization
  • VMware Nostalgia
  • Apple
You are here: Home / Automation / Auditing vMotion Migrations

Auditing vMotion Migrations

04.12.2012 by William Lam // 3 Comments

I saw an interesting question this week about auditing vMotion events and the number of times a VM has migrated to a particular ESX(i) host for license compliance. You can view this information using the Task/Events in your vCenter Server but you can also extract out the various types of events using the EventManager in the vSphere API. You will be able to go as far back in time as your vCenter Server's database retention policy allows you to. We will be searching for the VmMigratedEvent Event which will include variety of information including the source and destination host for the VM. The destination host will only be populated upon a successful vMotion.

Of course I had to write a script to help automate this, so here is a vSphere SDK for Perl script called getNumberOfvMotions.pl that accepts the name of an existing VM and will return the number of vMotions that has been performed on the VM as well as the list of destination hosts and the number of times it has migrated to those hosts. You will need a system that has the vCLI installed or you can you use vMA.

Note:  If you want to look at past vMotion for a VM that no longer exists, this is still possible, but you will need to parse the "message" within the Event as you can no longer look up that VM object in vCenter.

Here is an example of the script running:

You can easily modify the script to audit all VM's in your environment or just use a simple "for" loop to go through a set of VM's you are interested in, but I will leave that as an exercise for you.

More from my site

  • Listing all Events for vCenter Server
  • PowerCLI script to help correlate vCenter, ESXi & vSAN build/versions w/o manual VMware KB lookup
  • An update on how to retrieve useful information from a vSphere login?
  • How to efficiently transfer files to Datastore in vCenter using the vSphere API?
  • Quick Tip - Offline viewing of vSphere API & other API docs using Dash

Categories // Automation, vSphere Tags // event, VmMigratedEvent, vmotion, vSphere, vSphere API, vsphere sdk for perl

Comments

  1. *protectedBrett says

    08/08/2016 at 12:40 am

    Hi, thanks for the awesome script. is there any way of populating the dates that the VM vMotioned?
    I have some application support people who are convinced that the vMotions are causing transactions to mysteriously disappear. So if i have the dates and time that the VM moved then I can use it to troubleshoot and see if there was a vMotion at the time that these transactions disappeared.

    Cheers Brett

    Reply
    • *protectedBrett says

      08/08/2016 at 12:41 am

      .

      Reply

Trackbacks

  1. How to easily disable vMotion & Cross vCenter vMotion for a particular Virtual Machine? | virtuallyGhetto says:
    07/20/2016 at 9:37 am

    […] and the name of the Storage vMotion event is called VmRelocatedEvent. Here is a sample script using the vSphere SDK for Perl that exercises this specific vSphere API and provides you with all […]

    Reply

Leave a Reply to How to easily disable vMotion & Cross vCenter vMotion for a particular Virtual Machine? | virtuallyGhettoCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Search

Thank Author

Author

William is Distinguished Platform Engineering Architect in the VMware Cloud Foundation (VCF) Division at Broadcom. His primary focus is helping customers and partners build, run and operate a modern Private Cloud using the VMware Cloud Foundation (VCF) platform.

Connect

  • Bluesky
  • Email
  • GitHub
  • LinkedIn
  • Mastodon
  • Reddit
  • RSS
  • Twitter
  • Vimeo

Recent

  • Programmatically accessing the Broadcom Compatibility Guide (BCG) 05/06/2025
  • Quick Tip - Validating Broadcom Download Token  05/01/2025
  • Supported chipsets for the USB Network Native Driver for ESXi Fling 04/23/2025
  • vCenter Identity Federation with Authelia 04/16/2025
  • vCenter Server Identity Federation with Kanidm 04/10/2025

Advertisment

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Copyright WilliamLam.com © 2025