use of com.cloud.agent.api.GetVmStatsAnswer 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.GetVmStatsAnswer 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.GetVmStatsAnswer in project cloudstack by apache.
the class OvmResourceBase method execute.
protected GetVmStatsAnswer execute(GetVmStatsCommand cmd) {
List<String> vmNames = cmd.getVmNames();
HashMap<String, VmStatsEntry> vmStatsNameMap = new HashMap<String, VmStatsEntry>();
for (String vmName : vmNames) {
try {
VmStatsEntry e = getVmStat(vmName);
vmStatsNameMap.put(vmName, e);
} catch (XmlRpcException e) {
s_logger.debug("Get vm stat for " + vmName + " failed", e);
continue;
}
}
return new GetVmStatsAnswer(cmd, vmStatsNameMap);
}
use of com.cloud.agent.api.GetVmStatsAnswer in project cloudstack by apache.
the class MockVmManagerImpl method getVmStats.
@Override
public Answer getVmStats(final GetVmStatsCommand cmd) {
final HashMap<String, VmStatsEntry> vmStatsNameMap = new HashMap<String, VmStatsEntry>();
final List<String> vmNames = cmd.getVmNames();
for (final String vmName : vmNames) {
final VmStatsEntry entry = new VmStatsEntry(0, 0, 0, 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.GetVmStatsAnswer in project cloudstack by apache.
the class VmwareResource method execute.
protected Answer execute(GetVmStatsCommand cmd) {
if (s_logger.isTraceEnabled()) {
s_logger.trace("Executing resource GetVmStatsCommand: " + _gson.toJson(cmd));
}
HashMap<String, VmStatsEntry> vmStatsMap = null;
try {
HashMap<String, PowerState> vmPowerStates = getVmStates();
// getVmNames should return all i-x-y values.
List<String> requestedVmNames = cmd.getVmNames();
List<String> vmNames = new ArrayList<String>();
if (requestedVmNames != null) {
for (String vmName : requestedVmNames) {
if (vmPowerStates.get(vmName) != null) {
vmNames.add(vmName);
}
}
}
if (vmNames != null) {
vmStatsMap = getVmStats(vmNames);
}
} catch (Throwable e) {
if (e instanceof RemoteException) {
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
invalidateServiceContext();
}
s_logger.error("Unable to execute GetVmStatsCommand due to : " + VmwareHelper.getExceptionMessage(e), e);
}
Answer answer = new GetVmStatsAnswer(cmd, vmStatsMap);
if (s_logger.isTraceEnabled()) {
s_logger.trace("Report GetVmStatsAnswer: " + _gson.toJson(answer));
}
return answer;
}
Aggregations