use of com.cloud.agent.api.VmStatsEntry in project cloudstack by apache.
the class Ovm3VmSupport method execute.
public GetVmStatsAnswer execute(GetVmStatsCommand cmd) {
List<String> vmNames = cmd.getVmNames();
Map<String, VmStatsEntry> vmStatsNameMap = new HashMap<String, VmStatsEntry>();
for (String vmName : vmNames) {
VmStatsEntry e = getVmStat(vmName);
vmStatsNameMap.put(vmName, e);
}
return new GetVmStatsAnswer(cmd, (HashMap<String, VmStatsEntry>) vmStatsNameMap);
}
use of com.cloud.agent.api.VmStatsEntry in project CloudStack-archive by CloudStack-extras.
the class MockVmManagerImpl method getVmStats.
@Override
public Answer getVmStats(GetVmStatsCommand cmd) {
HashMap<String, VmStatsEntry> vmStatsNameMap = new HashMap<String, VmStatsEntry>();
List<String> vmNames = cmd.getVmNames();
for (String vmName : vmNames) {
VmStatsEntry entry = new VmStatsEntry(0, 0, 0, 0, "vm");
// default values 256 KBps
entry.setNetworkReadKBs(32768);
entry.setNetworkWriteKBs(16384);
entry.setCPUUtilization(10);
entry.setNumCPUs(1);
vmStatsNameMap.put(vmName, entry);
}
return new GetVmStatsAnswer(cmd, vmStatsNameMap);
}
use of com.cloud.agent.api.VmStatsEntry in project CloudStack-archive by CloudStack-extras.
the class LibvirtComputingResource method execute.
protected GetVmStatsAnswer execute(GetVmStatsCommand cmd) {
List<String> vmNames = cmd.getVmNames();
try {
HashMap<String, VmStatsEntry> vmStatsNameMap = new HashMap<String, VmStatsEntry>();
Connect conn = LibvirtConnection.getConnection();
for (String vmName : vmNames) {
VmStatsEntry statEntry = getVmStat(conn, vmName);
if (statEntry == null) {
continue;
}
vmStatsNameMap.put(vmName, statEntry);
}
return new GetVmStatsAnswer(cmd, vmStatsNameMap);
} catch (LibvirtException e) {
s_logger.debug("Can't get vm stats: " + e.toString());
return new GetVmStatsAnswer(cmd, null);
}
}
use of com.cloud.agent.api.VmStatsEntry in project cloudstack by apache.
the class LibvirtGetVmStatsCommandWrapper method execute.
@Override
public Answer execute(final GetVmStatsCommand command, final LibvirtComputingResource libvirtComputingResource) {
final List<String> vmNames = command.getVmNames();
try {
final HashMap<String, VmStatsEntry> vmStatsNameMap = new HashMap<String, VmStatsEntry>();
for (final String vmName : vmNames) {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(vmName);
try {
final VmStatsEntry statEntry = libvirtComputingResource.getVmStat(conn, vmName);
if (statEntry == null) {
continue;
}
vmStatsNameMap.put(vmName, statEntry);
} catch (LibvirtException e) {
s_logger.warn("Can't get vm stats: " + e.toString() + ", continue");
}
}
return new GetVmStatsAnswer(command, vmStatsNameMap);
} catch (final LibvirtException e) {
s_logger.debug("Can't get vm stats: " + e.toString());
return new GetVmStatsAnswer(command, null);
}
}
use of com.cloud.agent.api.VmStatsEntry in project cloudstack by apache.
the class OvmResourceBase method getVmStat.
private VmStatsEntry getVmStat(String vmName) throws XmlRpcException {
Map<String, String> vmStat = OvmVm.getVmStats(_conn, vmName);
int nvcpus = Integer.parseInt(vmStat.get("cpuNum"));
float cpuUtil = Float.parseFloat(vmStat.get("cpuUtil"));
long rxBytes = Long.parseLong(vmStat.get("rxBytes"));
long txBytes = Long.parseLong(vmStat.get("txBytes"));
Pair<Long, Long> oldNetworkStat = _vmNetworkStats.get(vmName);
long rx = rxBytes;
long tx = txBytes;
if (oldNetworkStat != null) {
rx -= oldNetworkStat.first();
tx -= oldNetworkStat.second();
oldNetworkStat.set(rxBytes, txBytes);
} else {
oldNetworkStat = new Pair<Long, Long>(rx, tx);
}
_vmNetworkStats.put(vmName, oldNetworkStat);
VmStatsEntry e = new VmStatsEntry();
e.setCPUUtilization(cpuUtil);
e.setNumCPUs(nvcpus);
e.setNetworkReadKBs(rx);
e.setNetworkWriteKBs(tx);
e.setEntityType("vm");
return e;
}
Aggregations