| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -57,6 +57,7 @@ | |
| import org.libvirt.Domain; | ||
| import org.libvirt.DomainBlockStats; | ||
| import org.libvirt.DomainInfo; | ||
| import org.libvirt.MemoryStatistic; | ||
| import org.libvirt.DomainInfo.DomainState; | ||
| import org.libvirt.DomainInterfaceStats; | ||
| import org.libvirt.LibvirtException; | ||
| Expand Down Expand Up | @@ -190,6 +191,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv | |
| private long _hvVersion; | ||
| private long _kernelVersion; | ||
| private int _timeout; | ||
| private static final int NUMMEMSTATS =2; | ||
|
|
||
| private KVMHAMonitor _monitor; | ||
| public static final String SSHKEYSPATH = "/root/.ssh"; | ||
| Expand Down Expand Up | @@ -3018,6 +3020,9 @@ private class VmStats { | |
| long _ioWrote; | ||
| long _bytesRead; | ||
| long _bytesWrote; | ||
| long _intmemfree; | ||
| long _memory; | ||
| long _maxmemory; | ||
| Calendar _timestamp; | ||
| } | ||
|
|
||
| Expand All | @@ -3026,11 +3031,16 @@ public VmStatsEntry getVmStat(final Connect conn, final String vmName) throws Li | |
| try { | ||
| dm = getDomain(conn, vmName); | ||
| final DomainInfo info = dm.getInfo(); | ||
| final MemoryStatistic[] mems = dm.memoryStats(NUMMEMSTATS); //number of memory statistics required. | ||
|
|
||
| final VmStatsEntry stats = new VmStatsEntry(); | ||
|
|
||
| stats.setNumCPUs(info.nrVirtCpu); | ||
| stats.setEntityType("vm"); | ||
|
|
||
| stats.setMemoryKBs(info.maxMem); | ||
| stats.setTargetMemoryKBs(info.memory); | ||
| stats.setIntFreeMemoryKBs((double) mems[0].getValue()); | ||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Qualitythe same problem pointed out by @swill at line 3128, may happen here.
Sorry, something went wrong.
All reactions
|
||
| /* get cpu utilization */ | ||
| VmStats oldStats = null; | ||
|
|
||
| Expand Down Expand Up | @@ -3115,6 +3125,9 @@ public VmStatsEntry getVmStat(final Connect conn, final String vmName) throws Li | |
| newStat._bytesRead = bytes_rd; | ||
| newStat._bytesWrote = bytes_wr; | ||
| newStat._timestamp = now; | ||
| newStat._intmemfree = mems[0].getValue(); | ||
|
Comment thread
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityIs this guaranteed to have a result? This looks like it is prime to introduce a Null Pointer Exception...
Sorry, something went wrong.
All reactions
|
||
| newStat._memory = info.memory; | ||
| newStat._maxmemory = info.maxMem; | ||
| _vmStats.put(vmName, newStat); | ||
| return stats; | ||
| } finally { | ||
| Expand Down | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -99,6 +99,7 @@ | |
| import org.apache.cloudstack.storage.command.StorageSubSystemCommand; | ||
| import org.apache.cloudstack.storage.to.TemplateObjectTO; | ||
| import org.apache.cloudstack.storage.to.VolumeObjectTO; | ||
| import org.apache.commons.lang.math.NumberUtils; | ||
|
|
||
| import com.cloud.agent.IAgentControl; | ||
| import com.cloud.agent.api.Answer; | ||
| Expand Down Expand Up | @@ -4862,15 +4863,24 @@ private HashMap<String, VmStatsEntry> getVmStats(List<String> vmNames) throws Ex | |
| } | ||
| String instanceNameCustomField = "value[" + key + "]"; | ||
|
|
||
| final String numCpuStr = "summary.config.numCpu"; | ||
| final String cpuUseStr = "summary.quickStats.overallCpuUsage"; | ||
| final String guestMemUseStr = "summary.quickStats.guestMemoryUsage"; | ||
| final String memLimitStr = "resourceConfig.memoryAllocation.limit"; | ||
| final String memMbStr = "config.hardware.memoryMB"; | ||
|
|
||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Qualitysame here. private static final and caps
Sorry, something went wrong.
All reactions
|
||
| ObjectContent[] ocs = | ||
| hyperHost.getVmPropertiesOnHyperHost(new String[] {"name", "summary.config.numCpu", "summary.quickStats.overallCpuUsage", instanceNameCustomField}); | ||
| hyperHost.getVmPropertiesOnHyperHost(new String[] {"name", numCpuStr, cpuUseStr ,guestMemUseStr ,memLimitStr ,memMbStr, instanceNameCustomField}); | ||
| if (ocs != null && ocs.length > 0) { | ||
| for (ObjectContent oc : ocs) { | ||
| List<DynamicProperty> objProps = oc.getPropSet(); | ||
| if (objProps != null) { | ||
| String name = null; | ||
| String numberCPUs = null; | ||
| String maxCpuUsage = null; | ||
| String memlimit = null; | ||
| String memkb = null; | ||
| String guestMemusage = null; | ||
| String vmNameOnVcenter = null; | ||
| String vmInternalCSName = null; | ||
| for (DynamicProperty objProp : objProps) { | ||
| Expand All | @@ -4879,10 +4889,16 @@ private HashMap<String, VmStatsEntry> getVmStats(List<String> vmNames) throws Ex | |
| } else if (objProp.getName().contains(instanceNameCustomField)) { | ||
| if (objProp.getVal() != null) | ||
| vmInternalCSName = ((CustomFieldStringValue)objProp.getVal()).getValue(); | ||
| } else if (objProp.getName().equals("summary.config.numCpu")) { | ||
| }else if(objProp.getName().equals(guestMemusage)){ | ||
| guestMemusage = objProp.getVal().toString(); | ||
| }else if (objProp.getName().equals(numCpuStr)) { | ||
| numberCPUs = objProp.getVal().toString(); | ||
| } else if (objProp.getName().equals("summary.quickStats.overallCpuUsage")) { | ||
| } else if (objProp.getName().equals(cpuUseStr)) { | ||
| maxCpuUsage = objProp.getVal().toString(); | ||
| } else if (objProp.getName().equals(memLimitStr)) { | ||
| memlimit = objProp.getVal().toString(); | ||
| } else if (objProp.getName().equals(memMbStr)) { | ||
| memkb = objProp.getVal().toString(); | ||
| } | ||
| } | ||
| new VirtualMachineMO(hyperHost.getContext(), oc.getObj()); | ||
| Expand Down Expand Up | @@ -4951,7 +4967,7 @@ private HashMap<String, VmStatsEntry> getVmStats(List<String> vmNames) throws Ex | |
| } | ||
| } | ||
| } | ||
| vmResponseMap.put(name, new VmStatsEntry(Integer.parseInt(maxCpuUsage), networkReadKBs, networkWriteKBs, Integer.parseInt(numberCPUs), "vm")); | ||
| vmResponseMap.put(name, new VmStatsEntry( NumberUtils.toDouble(memkb)*1024,NumberUtils.toDouble(guestMemusage)*1024,NumberUtils.toDouble(memlimit)*1024, NumberUtils.toDouble(maxCpuUsage), networkReadKBs, networkWriteKBs, NumberUtils.toInt(numberCPUs), "vm")); | ||
| } | ||
| } | ||
| } | ||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI believe here we can have a null pointer in very specific cases. For instance, if this code is being executed while a call to destroy the VM that has the name “vmName”; this getDomain would return a null value.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.