use of com.cloud.agent.api.GetHostStatsAnswer in project cloudstack by apache.
the class ResourceManagerImpl method getHostStatistics.
@Override
public HostStats getHostStatistics(final long hostId) {
final Answer answer = _agentMgr.easySend(hostId, new GetHostStatsCommand(_hostDao.findById(hostId).getGuid(), _hostDao.findById(hostId).getName(), hostId));
if (answer != null && answer instanceof UnsupportedAnswer) {
return null;
}
if (answer == null || !answer.getResult()) {
final String msg = "Unable to obtain host " + hostId + " statistics. ";
s_logger.warn(msg);
return null;
} else {
// now construct the result object
if (answer instanceof GetHostStatsAnswer) {
return ((GetHostStatsAnswer) answer).getHostStats();
}
}
return null;
}
use of com.cloud.agent.api.GetHostStatsAnswer in project cloudstack by apache.
the class LibvirtGetHostStatsCommandWrapper method execute.
@Override
public Answer execute(final GetHostStatsCommand command, final LibvirtComputingResource libvirtComputingResource) {
CPUStat cpuStat = libvirtComputingResource.getCPUStat();
MemStat memStat = libvirtComputingResource.getMemStat();
final double cpuUtil = cpuStat.getCpuUsedPercent();
memStat.refresh();
double totMem = memStat.getTotal();
double freeMem = memStat.getAvailable();
final Pair<Double, Double> nicStats = libvirtComputingResource.getNicStats(libvirtComputingResource.getPublicBridgeName());
final HostStatsEntry hostStats = new HostStatsEntry(command.getHostId(), cpuUtil, nicStats.first() / 1024, nicStats.second() / 1024, "host", totMem, freeMem, 0, 0);
return new GetHostStatsAnswer(command, hostStats);
}
use of com.cloud.agent.api.GetHostStatsAnswer in project cloudstack by apache.
the class OvmResourceBase method execute.
protected Answer execute(GetHostStatsCommand cmd) {
try {
Map<String, String> res = OvmHost.getPerformanceStats(_conn, _publicNetworkName);
Double cpuUtil = Double.parseDouble(res.get("cpuUtil"));
Double rxBytes = Double.parseDouble(res.get("rxBytes"));
Double txBytes = Double.parseDouble(res.get("txBytes"));
Double totalMemory = Double.parseDouble(res.get("totalMemory"));
Double freeMemory = Double.parseDouble(res.get("freeMemory"));
HostStatsEntry hostStats = new HostStatsEntry(cmd.getHostId(), cpuUtil, rxBytes, txBytes, "host", totalMemory, freeMemory, 0, 0);
return new GetHostStatsAnswer(cmd, hostStats);
} catch (Exception e) {
s_logger.debug("Get host stats of " + cmd.getHostName() + " failed", e);
return new Answer(cmd, false, e.getMessage());
}
}
use of com.cloud.agent.api.GetHostStatsAnswer in project cloudstack by apache.
the class VmwareResource method execute.
protected Answer execute(GetHostStatsCommand cmd) {
if (s_logger.isTraceEnabled()) {
s_logger.trace("Executing resource GetHostStatsCommand: " + _gson.toJson(cmd));
}
VmwareContext context = getServiceContext();
VmwareHypervisorHost hyperHost = getHyperHost(context);
HostStatsEntry hostStats = new HostStatsEntry(cmd.getHostId(), 0, 0, 0, "host", 0, 0, 0, 0);
Answer answer = new GetHostStatsAnswer(cmd, hostStats);
try {
HostStatsEntry entry = getHyperHostStats(hyperHost);
if (entry != null) {
entry.setHostId(cmd.getHostId());
answer = new GetHostStatsAnswer(cmd, entry);
}
} catch (Exception e) {
if (e instanceof RemoteException) {
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
invalidateServiceContext();
}
String msg = "Unable to execute GetHostStatsCommand due to " + VmwareHelper.getExceptionMessage(e);
s_logger.error(msg, e);
}
if (s_logger.isTraceEnabled()) {
s_logger.trace("GetHostStats Answer: " + _gson.toJson(answer));
}
return answer;
}
Aggregations