VMware {code} Community
travisj1
Contributor
Contributor

VI SDK Performance Counter Sample

Hello! I am a newbie on the VI SDK, and I have been using C# as my primary language for accessing it (along with the VIForDotNet open source project on SourceForge). I need sample code (in any language, but preferably C# or Java) that shows the correct way to retrieve single instances (real time) of memory and CPU counter data. By "single instance", I mean a SINGLE value in the result that is guaranteed to either be a real time reading of the information or the absolute LATEST sample.

I wish to retrieve this value without having to use begin and end timesif possibleso I don't have multiple results from multiple samples to parse through. I am interested, specifically, in CPU utilization, memory active, memory reserved, memory used, CPU used, CPU idle, etc.

Can anyone help?

Tags (1)
0 Kudos
1 Reply
njain
Expert
Expert

Hi,

VI API provides "QueryPerf" method that returns performance statistics for an entity. This method takes in the "PerfQuerySpec" as a parameter. In order to fetch a single value for a counter, you can set the "maxSample" property to get the recent most sample. Please note that this property can be used only when querying for real-time statistics. This argument is ignored for historical statistics.

The attached C# sample takes in the entity type and retrieves the statistics for the same. You can edit the sample to filter the information as per your needs.

Hope this information is helpful.

0 Kudos