WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud Foundation
  • VKS
  • Homelab
    • Resources
    • Nested Virtualization
  • VMware Nostalgia
  • Apple
You are here: Home / Automation / Using the vSphere API in vCenter Server to collect ESXTOP & vscsiStats metrics

Using the vSphere API in vCenter Server to collect ESXTOP & vscsiStats metrics

02.15.2017 by William Lam // 1 Comment

Back in 2013, I wrote two articles here and here on how to use the Service Manager API that was introduced in vSphere 5.1 to remotely collect ESXTOP and vscsiStats metrics. At the time, I was told that this API was only available when connecting directly to an ESXi host using the vSphere API. This was still a huge improvement over the previous method which basically required customers to run the commands locally. For ESXTOP, there was resxtop but it was not available for all platforms and some customers still prefer to use the ESXi Shell's version. When I had learned about this API, I was really hoping I could collect both ESXTOP & vscsiStats metrics using vCenter Server which would remove the need to have direct connectivity to each ESXi host.

Last week, an Engineer came across one of my blog posts related to the Service Manager APIs which helped him with a problem he was trying to solve. In the email conversation, I then came to learn from the Engineer that the the Service Manager API can be used from vCenter Server and going directly to the ESXi host was not necessary. It turns out that the QueryServiceList() method which accepts an array of "location" expects a special keyword prefix appended to the list of ESXi hosts that you wish to use the local Service Manager instances on.

The special keyword prefix is "vmware.host." and this is appended to either the Hostname or IP Address of the ESXi hosts being managed by the vCenter Server. For example, in my environment I have an ESXi host (192.168.1.50) that is managed by my VC and so the location string for that host should be "vmware.host.192.168.1.50". If the method was successfully called, you should get back the two service instances for ESXTOP and vscsiStats for each of the ESXi hosts where you can then perform the metric collection.

I have created two sample pyvmomi scripts which exercises the Service Manager API for ESXTOP and vscsiStats:

  • service_manager_esxtop_in_vc.py
  • service_manager_vscsistats_in_vc.py

Note: For more details on how to use Service Manager API to collect ESXTOP and vscsiStats, please refer to this post here and here.

Here is an example of running the ESXTOP sample script and executing the "CounterInfo" operation:


Here is an example of running the vScsiStats sample script and executing the "FetchAllHistograms" operation:


I had initially tried to create the two sample scripts using PowerCLI, but it looks like there may be a bug with PowerCLI when calling the Service Manager instance.

If you try to run the following snippet which retrieves the view for the Service Manager

Get-View $global:DefaultVIServer.ExtensionData.Content.ServiceManager

You will find that it throws the following error. I have already filed an internal bug and hopefully this get resolved in a future PowerCLI update so that customers who wish to retrieve ESXTOP and vScsiStats can do so using PowerCLI. For all other vSphere SDKs, it should work as expected.


UPDATE (02/25/17) - After talking to PowerCLI Dev team, I was able to get the necessary information to come up with a workaround to access both ESXTOP and vScsiStats information using PowerCLI when connected to a vCenter Server. Below are the two examples which exercises the two service APIs:

  • Get-EsxtopAPI.ps1
  • Get-VscsiStats.ps1

Here is an example of running the Get-EsxtopAPI.ps1 script:


Here is an example of running the Get-VscsiStats.ps1 script:

More from my site

  • Required vSphere Privilege for Read-Only RESXTOP View
  • Retrieving vscsiStats Using the vSphere 5.1 API
  • Retrieving ESXTOP Performance Data Using the vSphere 5.1 API
  • How to obtain GID and LWID from esxtop?
  • vSphere Code Capture is your ChatGPT for vSphere Automation

Categories // Automation, vSphere Tags // esxtop, service manager, vscsiStats, vSphere API

Comments

  1. *protectedcarlos says

    08/20/2020 at 3:24 pm

    thank you! this and the auxiliary links helped me a lot!

    Reply

Thanks for the comment!Cancel 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

 

Loading Comments...