Vijava 学习笔记之HostSystem(内存利用率)

熊孩纸 阅读:636 2021-03-31 22:38:19 评论:0
package com.vmware.client; 
 
import com.vmware.util.ClientSesion; 
import com.vmware.vim25.HostHardwareInfo; 
import com.vmware.vim25.VirtualHardware; 
import com.vmware.vim25.VirtualMachineConfigInfo; 
import com.vmware.vim25.mo.*; 
 
import java.net.URL; 
 
/** 
 * Created by vixuan-008 on 2015/4/15. 
 */ 
public class HostHaedwareInfoClient{ 
    public static  void main(String[] args){ 
        try { 
            ClientSesion session = new ClientSesion("IP地址", "用户名", "密码"); 
            URL url = new URL("https", session.getHost(), "/sdk"); 
            ServiceInstance si = new ServiceInstance(url, session.getUsername(), session.getPassword(), true); 
 
            Folder rootFolder = si.getRootFolder(); 
 
 
            ManagedEntity[] mes =new InventoryNavigator(rootFolder).searchManagedEntities("HostSystem"); 
            //物理服务器Memory 
            long HostSystemMemory=0; 
            //物理服务器关联虚拟机Memory 
            long VirtualMachineMemory=0; 
            if(mes.length>0){ 
                HostSystem systems=(HostSystem)mes[0]; 
                //物理服务器所关联的虚拟机 
                VirtualMachine[] virtualMachines=systems.getVms(); 
 
                if(virtualMachines.length>0){ 
                    for(int i=0;i<virtualMachines.length;i++){ 
                        System.out.println("virtualMacheines name is:" + virtualMachines[i].getName()); 
                        VirtualMachine virtualMachine=virtualMachines[i]; 
                        VirtualMachineConfigInfo config = virtualMachine.getConfig(); 
                        VirtualHardware hw = config.getHardware(); 
                        VirtualMachineMemory=VirtualMachineMemory+hw.getMemoryMB(); 
 
                    } 
                } 
                System.out.println("hostSystem name is:" + systems.getName()); 
                System.out.println("VirtualMachine Memory in MB: " +VirtualMachineMemory ); 
                if(systems !=null){ 
                    //服务器物理硬件配置信息 
                    HostHardwareInfo hostHardwareInfo=systems.getHardware(); 
                    if(hostHardwareInfo !=null){ 
                        //服务器总内存大小 
                        HostSystemMemory=hostHardwareInfo.getMemorySize(); 
                        System.out.println("memery size is:"+HostSystemMemory); 
                       // HostReliableMemoryInfo hostReliableMemoryInfo=hostHardwareInfo.getReliableMemoryInfo(); 
 
                    }else{ 
                        System.out.println("hostHardwareInfo is null"); 
                    } 
                }else{ 
                    System.out.println("HostSystem is null"); 
                } 
            } 
 
 
 
 
            si.getServerConnection().logout(); 
        }catch (Exception e){ 
            e.printStackTrace(); 
        } 
 
    } 
} 

相关截图:


声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

关注我们

一个IT知识分享的公众号