Quantcast
Channel: VMware Communities : All Content - VMware vCenter™
Viewing all articles
Browse latest Browse all 24426

How to collect information of all esx hosts connected to vCenter server using vSphere API and Java?

$
0
0

I am collecting information of esx systems using vSphere API. By using this API, I am able to collect information of esx hosts by giving IP.



try{
ServiceInstance si =newServiceInstance(new URL(url), user, pass,true);
  
System.out.println("host :"+host+"---"+si.getAboutInfo().getFullName());

System.out.println(" Version is .. "+si.getAboutInfo().version);
System.out.println(" os type is .. "+si.getAboutInfo().osType);
System.out.println("Vendor is .. "+ si.getAboutInfo().vendor);
System.out.println("name is"+ si.getAboutInfo().name);

ManagedEntity[] managedEntities =newInventoryNavigator(
  si
.getRootFolder()).searchManagedEntities("VirtualMachine");
  
ManagedEntity[] hostmanagedEntities =newInventoryNavigator(
  si
.getRootFolder()).searchManagedEntities("HostSystem");

for(ManagedEntity hostmanagedEntity : hostmanagedEntities){
  
HostSystem hostsys =(HostSystem) hostmanagedEntity;

  
StringESXhostname= hostsys.getName();

  
HostListSummary hls = hostsys.getSummary();
  
HostHardwareSummary hosthwi = hls.getHardware();
  
HostListSummaryQuickStats hqs = hls.getQuickStats();
  
Datastore[] HDS = hostsys.getDatastores();
  
StringBuilder DS =newStringBuilder();
  
for(int i=0;i <HDS.length;i++){
  
DatastoreSummary dsm =HDS[i].getSummary();

  DS
.append(dsm.name+":"+dsm.capacity+":"+dsm.freeSpace+"-");
  
}

  
int MEM=hqs.overallMemoryUsage;
  
int UPT=hqs.getUptime();
  
Integer CPU=hqs.getOverallCpuUsage();  

  
String esxkey ="ESXRealInfo";
  
String esxvalue ="ESXhostname-"+ESXhostname
  
+";CPU Usage-"+ CPU +";MEM Usage-"
  
+ MEM +";UPTIME-"+ UPT+"; Datastores -"+DS;
  
}


}
catch(Exception e){ e.printStackTrace();}


By using this code and manipulating managedentities object I can extract information of each host and vm working on each host.

Now instead of collecting information from different hosts, I want to collect information from vcenter server. vCenter server also contains all details about hosts and their VMs.

I want to get this information by using vCenter server instead of visiting each host. Is it possible to get this information? how?


Viewing all articles
Browse latest Browse all 24426

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>