The last topic that I would like to explore before concluding my VSAN API blog series are some of the advanced VSAN disk statistics that are available for either troubleshooting or informational purposes. One such statistic that would be handy to know about is the number of VSAN Components per ESXi host, which I have already demonstrated in my recent VSAN configuration maximum query script and VSAN PowerCLI vCheck Plugins.
These disk statistics are made available through the VSAN InternalSystem manager and using the QueryPhysicalVsanDisks() vSphere API method, we can either retrieve all or a specific set of properties for each ESXi host. I have created a sample vSphere SDK for Perl script called vsanDiskStatsQueries.pl that will demonstrate the use of this API.
Disclaimer: These scripts are provided for informational and educational purposes only. It should be thoroughly tested before attempting to use in a production environment.
Here is an example of running the script against a VSAN Cluster which will produce the number of VSAN components for each ESXi host:
./vsanDiskStatsQueries.pl --server vcenter55-1.primp-industries.com --username root --cluster VSAN-Cluster
If we take a look at the script, you will notice we filtered on two specific properties: lsom_objects_count and owner. One thing to note is the output for this method is JSON string, so you will need to parse the output accordingly.
The owner property indicates the UUID of a specific ESXi host and the lsom_objects_count represents the number of VSAN components. To be able to identify the particular ESXi host and compare it to the owner property, we use the QueryHostStatus() API which was discussed in Exploring VSAN APIs Part 5. Once we have a match for the current ESXi host, we simply extract the lsom_objects_count property which I use a simple hash table to keep track of the results and display it at the very end of the script.
This concludes my 9-part series of exploring the new VSAN APIs. Hopefully for those of you who followed the series have enjoyed it, I know I definitely had fun learning about the new APIs and how you can automate every aspect of VSAN from a scripting and programmatic perspective.
- Exploring VSAN APIs Part 1 – Enable VSAN Cluster
- Exploring VSAN APIs Part 2 – Query available SSDs
- Exploring VSAN APIs Part 3 – Enable VSAN Traffic Type
- Exploring VSAN APIs Part 4 – VSAN Disk Mappings
- Exploring VSAN APIs Part 5 – VSAN Host Status
- Exploring VSAN APIs Part 6 – Modifying Virtual Machine VM Storage Policy
- Exploring VSAN APIs Part 7 – VSAN Datastore Folder Management
- Exploring VSAN APIs Part 8 – Maintenance Mode
- Exploring VSAN APIs Part 9 – VSAN Component count
- Exploring VSAN APIs Part 10 – VSAN Disk Health
Rob Neff says
Is there a simple way to list the associated VM's whose components are being hosted by the host's vsandatastore?
The idea is to easily see how VM's are distributed across the vsandatastore.
ESXi Host 1
--- Disk Group 1
- Component for VM1
- Component for VM3
--- Disk Group 2
- Component for VM2
- Component for VM4
William Lam says
Yes, an example of a similar implementation is in RVC's VSAN vsan.vm_object_info command. You can take a look at vsan.rb (Ruby Module) to get an idea of how to call the appropriate APIs to fetch this information. Regarding your other question, there is no such property that VSAN provides to verify whether components are evenly distributed.
Rob Neff says
I forgot to say in the previous post that you have a really helpful blog. A couple additional questions...
Is there a flag which indicates that a vsandatastore believes it has been optimally distributed across the cluster?
How about a trigger that tells VSAN to immediately optimally re-distribute its components across the cluster starting now. For example, you migrate a lot of components off of 2 hosts going into Maintenance Mode.
I imagine this reconfiguring activity could be monitored with "vsan.resync_dashboard", but I'm looking for a state indicator.