/** * Returns the compressed memory of a virtual machine */ private void getVmMemCompressed(String vmName, PrintWriter out) throws IOException { try { VirtualMachine vm = (VirtualMachine) getManagedEntity(vmName, "VirtualMachine"); Long amount = new Long(0); if (vm == null) { LOG.warn("No vm named '" + vmName + "' found"); } else { VirtualMachineSummary vmSummary = vm.getSummary(); VirtualMachineQuickStats vmQuickStats = vmSummary.getQuickStats(); amount = vmQuickStats.getCompressedMemory(); if (amount == null) { amount = new Long(0); } } out.print(amount); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
/** * Returns the committed storage of a virtual machine */ private void getVmStorageCommitted(String vmName, PrintWriter out) throws IOException { try { VirtualMachine vm = (VirtualMachine) getManagedEntity(vmName, "VirtualMachine"); Long size = 0L; if (vm == null) { LOG.warn("No vm named '" + vmName + "' found"); } else { VirtualMachineSummary vmSummary = vm.getSummary(); VirtualMachineStorageSummary vmStorage = vmSummary.getStorage(); size = vmStorage.getCommitted(); } out.print(size); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
/** * Returns the uncommitted storage of a virtual machine */ private void getVmStorageUncommitted(String vmName, PrintWriter out) throws IOException { try { VirtualMachine vm = (VirtualMachine) getManagedEntity(vmName, "VirtualMachine"); Long size = 0L; if (vm == null) { LOG.warn("No vm named '" + vmName + "' found"); } else { VirtualMachineSummary vmSummary = vm.getSummary(); VirtualMachineStorageSummary vmStorage = vmSummary.getStorage(); size = vmStorage.getUncommitted(); } out.print(size); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
/** * Returns the unshared storage of a virtual machine */ private void getVmStorageUnshared(String vmName, PrintWriter out) throws IOException { try { VirtualMachine vm = (VirtualMachine) getManagedEntity(vmName, "VirtualMachine"); Long size = 0L; if (vm == null) { LOG.warn("No vm named '" + vmName + "' found"); } else { VirtualMachineSummary vmSummary = vm.getSummary(); VirtualMachineStorageSummary vmStorage = vmSummary.getStorage(); size = vmStorage.getUnshared(); } out.print(size); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
/** * Returns the shared memory of a virtual machine */ private void getVmMemShared(String vmName, PrintWriter out) throws IOException { try { VirtualMachine vm = (VirtualMachine) getManagedEntity(vmName, "VirtualMachine"); Integer amount = 0; if (vm == null) { LOG.warn("No vm named '" + vmName + "' found"); } else { VirtualMachineSummary vmSummary = vm.getSummary(); VirtualMachineQuickStats vmQuickStats = vmSummary.getQuickStats(); amount = vmQuickStats.getSharedMemory(); if (amount == null) { amount = 0; } } out.print(amount); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
/** * Returns the active memory of a virtual machine */ private void getVmMemActive(String vmName, PrintWriter out) throws IOException { try { VirtualMachine vm = (VirtualMachine) getManagedEntity(vmName, "VirtualMachine"); Integer amount = 0; if (vm == null) { LOG.warn("No vm named '" + vmName + "' found"); } else { VirtualMachineSummary vmSummary = vm.getSummary(); VirtualMachineQuickStats vmQuickStats = vmSummary.getQuickStats(); amount = vmQuickStats.getGuestMemoryUsage(); if (amount == null) { amount = 0; } } out.print(amount); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
/** * Returns the guest OS full description of a virtual machine */ private void getVmGuestFullName(String vmName, PrintWriter out) throws IOException { try { VirtualMachine vm = (VirtualMachine) getManagedEntity(vmName, "VirtualMachine"); String guestFullName = ""; if (vm == null) { LOG.warn("No vm named '" + vmName + "' found"); } else { VirtualMachineSummary vmSummary = vm.getSummary(); VirtualMachineGuestSummary vmGuest = vmSummary.getGuest(); if (vmGuest == null) { LOG.info("Cannot query guest OS for VM '" + vmName); } else { guestFullName = vmGuest.getGuestFullName(); } } out.print(guestFullName); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
/** * Returns the CPU usage of a virtual machine */ private void getVmCpuUsed(String vmName, PrintWriter out) throws IOException { try { VirtualMachine vm = (VirtualMachine) getManagedEntity(vmName, "VirtualMachine"); Integer usedMhz = 0; if (vm == null) { LOG.warn("No vm named '" + vmName + "' found"); } else { VirtualMachineSummary vmSummary = vm.getSummary(); VirtualMachineQuickStats vmQuickStats = vmSummary.getQuickStats(); usedMhz = vmQuickStats.getOverallCpuUsage(); if (usedMhz == null) { usedMhz = 0; } } out.print(usedMhz); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
/** * Returns the memory size of a virtual machine */ private void getVmMemSize(String vmName, PrintWriter out) throws IOException { try { VirtualMachine vm = (VirtualMachine) getManagedEntity(vmName, "VirtualMachine"); Integer amount = 0; if (vm == null) { LOG.warn("No vm named '" + vmName + "' found"); } else { VirtualMachineSummary vmSummary = vm.getSummary(); VirtualMachineConfigSummary vmConfigSum = vmSummary.getConfig(); amount = vmConfigSum.getMemorySizeMB(); if (amount == null) { amount = 0; } } out.print(amount); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
/** * Returns the overhead memory of a virtual machine */ private void getVmMemOverheadConsumed(String vmName, PrintWriter out) throws IOException { try { VirtualMachine vm = (VirtualMachine) getManagedEntity(vmName, "VirtualMachine"); Integer amount = 0; if (vm == null) { LOG.warn("No vm named '" + vmName + "' found"); } else { VirtualMachineSummary vmSummary = vm.getSummary(); VirtualMachineQuickStats vmQuickStats = vmSummary.getQuickStats(); amount = vmQuickStats.getConsumedOverheadMemory(); if (amount == null) { amount = 0; } } out.print(amount); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
/** * Returns the private memory of a virtual machine */ private void getVmMemPrivate(String vmName, PrintWriter out) throws IOException { try { VirtualMachine vm = (VirtualMachine) getManagedEntity(vmName, "VirtualMachine"); Integer amount = 0; if (vm == null) { LOG.warn("No vm named '" + vmName + "' found"); } else { VirtualMachineSummary vmSummary = vm.getSummary(); VirtualMachineQuickStats vmQuickStats = vmSummary.getQuickStats(); amount = vmQuickStats.getPrivateMemory(); if (amount == null) { amount = 0; } } out.print(amount); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
/** * Returns the swapped memory of a virtual machine */ private void getVmMemSwapped(String vmName, PrintWriter out) throws IOException { try { VirtualMachine vm = (VirtualMachine) getManagedEntity(vmName, "VirtualMachine"); Integer amount = 0; if (vm == null) { LOG.warn("No vm named '" + vmName + "' found"); } else { VirtualMachineSummary vmSummary = vm.getSummary(); VirtualMachineQuickStats vmQuickStats = vmSummary.getQuickStats(); amount = vmQuickStats.getSwappedMemory(); if (amount == null) { amount = 0; } } out.print(amount); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
/** * Returns the consumed memory of a virtual machine */ private void getVmMemConsumed(String vmName, PrintWriter out) throws IOException { try { VirtualMachine vm = (VirtualMachine) getManagedEntity(vmName, "VirtualMachine"); Integer amount = 0; if (vm == null) { LOG.warn("No vm named '" + vmName + "' found"); } else { VirtualMachineSummary vmSummary = vm.getSummary(); VirtualMachineQuickStats vmQuickStats = vmSummary.getQuickStats(); amount = vmQuickStats.getHostMemoryUsage(); if (amount == null) { amount = 0; } } out.print(amount); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
/** * Returns the ballooned memory of a virtual machine */ private void getVmMemBallooned(String vmName, PrintWriter out) throws IOException { try { VirtualMachine vm = (VirtualMachine) getManagedEntity(vmName, "VirtualMachine"); Integer amount = 0; if (vm == null) { LOG.warn("No vm named '" + vmName + "' found"); } else { VirtualMachineSummary vmSummary = vm.getSummary(); VirtualMachineQuickStats vmQuickStats = vmSummary.getQuickStats(); amount = vmQuickStats.getBalloonedMemory(); if (amount == null) { amount = 0; } } out.print(amount); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
/** * Returns the uptime in seconds of a virtual machine */ private void getVmUptime(String vmName, PrintWriter out) throws IOException { try { VirtualMachine vm = (VirtualMachine) getManagedEntity(vmName, "VirtualMachine"); Integer uptime = 0; if (vm == null) { LOG.warn("No vm named '" + vmName + "' found"); } else { VirtualMachineSummary vmSummary = vm.getSummary(); VirtualMachineQuickStats vmQuickStats = vmSummary.getQuickStats(); if (vmQuickStats != null) { uptime = vmQuickStats.getUptimeSeconds(); if (uptime == null) { uptime = 0; } } } out.print(uptime); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
/** * To stress IO usage on {@link CorfuServer} node. */ @Override public void stressIOLoad() { log.info("Stressing I/O on corfu server: {}", params.getName()); String cmd = "stress -i " + vm.getSummary().getConfig().getNumCpu(); executeOnVm(cmd); }
/** * To stress memory (RAM) usage on {@link CorfuServer} node. */ @Override public void stressMemoryLoad() { log.info("Stressing Memory (RAM) on corfu server: {}", params.getName()); String cmd = "stress -m " + vm.getSummary().getConfig().getNumCpu() + " --vm-bytes 1G"; executeOnVm(cmd); }
/** * To stress CPU usage on {@link CorfuServer} node. */ @Override public void stressCPULoad() { log.info("Stressing CPU on corfu server: {}", params.getName()); String cmd = "stress -c " + vm.getSummary().getConfig().getNumCpu(); executeOnVm(cmd); }
/** * To stress disk usage on {@link CorfuServer} node. */ @Override public void stressDiskLoad() { log.info("Stressing disk on corfu server: {}", params.getName()); String cmd = "stress -d " + vm.getSummary().getConfig().getNumCpu() + " --hdd-bytes 5G"; executeOnVm(cmd); }
public static void main(String[] args) throws Exception { long start = System.currentTimeMillis(); ServiceInstance si = SampleUtil.createServiceInstance(); long end = System.currentTimeMillis(); Folder rootFolder = si.getRootFolder(); System.out.println("time taken:" + (end - start)); String name = rootFolder.getName(); System.out.println("vc root folder:" + name); ManagedEntity[] mes = new InventoryNavigator(rootFolder).searchManagedEntities("VirtualMachine"); if (mes == null || mes.length == 0) { return; } VirtualMachine vm = (VirtualMachine) mes[0]; VirtualMachineConfigInfo vminfo = vm.getConfig(); VirtualMachineCapability vmc = vm.getCapability(); System.out.println("Name: " + vm.getName()); System.out.println("IP: " + vm.getGuest().getIpAddress()); System.out.println("FQDN: " + vm.getGuest().getHostName()); System.out.println("MOID: " + vm.getMOR().val); System.out.println("InstanceUUID: " + vm.getSummary().getConfig().getInstanceUuid()); System.out.println("GuestOS: " + vminfo.getGuestFullName()); System.out.println("Multiple snapshot supported: " + vmc.isMultipleSnapshotsSupported()); si.getServerConnection().logout(); }