VMware {code} Community
ChanKaiShi
Enthusiast
Enthusiast
Jump to solution

Sample code to retrieve history of CPU usage for a host

Hi,

SDK severely lacks any samples and that's how I prefer to learn. Can somebody post a brief code in any language which will show me how to retrieve perfomance history for specific HostSystem. I already have all neccessary plumbing setup (ManagedObjecteReference etc). I need just code which will give me CSV output of last 1 hour of CPU utilization for specific hostname I'll pass to API.

Thanks,

G

0 Kudos
1 Solution

Accepted Solutions
Niket
Enthusiast
Enthusiast
Jump to solution

Oops!! Wrong attachement.

Attached is the file you can use.

View solution in original post

0 Kudos
8 Replies
heyitspablo
VMware Employee
VMware Employee
Jump to solution

ChanKaiShi,

I have asked our team to provide pointers, hoping it sample already exists Smiley Wink

There are 3 places where we put our samples.

#1. Our SDK Documentation

#2 VMware Code Sample site (needs refreshing)

http://www.vmware.com/communities/content/developer/samplecode/

#3 VMware Community Sample code site

http://communities.vmware.com/community/developer/utilities?view=documents

(We sure could use more contributions in here)

thanks

Pablo

Keep up with latest info on vSphere PowerCLI http://blogs.vmware.com/vipowershell - Follow me on Twitter @heyitspablo
0 Kudos
ChanKaiShi
Enthusiast
Enthusiast
Jump to solution

Thanks,

Yes, I visited that URL but there were no specific samples for what I'm trying to accomplish. There were Perl sample but it was not using API directly but used some precompiled libraries instead.

0 Kudos
Niket
Enthusiast
Enthusiast
Jump to solution

Hi,

Attached is the C# sample code which create a csv file at location C:\TestFile.csv. This csv file have the cpu usage data in percentage in past 1 hour.

Parameters to be passed:

<url> <username> <password> <HostName>

Thanks

Niket

0 Kudos
ChanKaiShi
Enthusiast
Enthusiast
Jump to solution

Thanks,

Your code file is empty. Only constructor for class specified.

0 Kudos
Niket
Enthusiast
Enthusiast
Jump to solution

Oops!! Wrong attachement.

Attached is the file you can use.

0 Kudos
ChanKaiShi
Enthusiast
Enthusiast
Jump to solution

Thanks,

You guys need to put more of those in documentation compared to what is there right now.

0 Kudos
heyitspablo
VMware Employee
VMware Employee
Jump to solution

ChanKaishi - agreed we need to do a better job with our sample code and we have plans in place for improvements this year.

Thanks for the feedback please keep it coming.

Regards,

Pablo

Keep up with latest info on vSphere PowerCLI http://blogs.vmware.com/vipowershell - Follow me on Twitter @heyitspablo
0 Kudos
ChanKaiShi
Enthusiast
Enthusiast
Jump to solution

Niket this works very well but a bit slow on our server. I beleive current code retrieves all data for last hourin 20s increments, I don't need this granularity, will it speed up things if only every 1min or 5min is being fetched?

Thanks,

Greg

0 Kudos