Search in sources :

Example 1 with GetHostStatsAnswer

use of com.cloud.legacymodel.communication.answer.GetHostStatsAnswer in project cosmic by MissionCriticalCloud.

the class LibvirtGetHostStatsCommandWrapper method execute.

@Override
public Answer execute(final GetHostStatsCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final CpuStat cpuStat = libvirtComputingResource.getCpuStat();
    final MemStat memStat = libvirtComputingResource.getMemStat();
    final double cpuUtil = cpuStat.getCpuUsedPercent();
    memStat.refresh();
    final double totMem = memStat.getTotal();
    final 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);
}
Also used : GetHostStatsAnswer(com.cloud.legacymodel.communication.answer.GetHostStatsAnswer) CpuStat(com.cloud.utils.linux.CpuStat) HostStatsEntry(com.cloud.legacymodel.dc.HostStatsEntry) MemStat(com.cloud.utils.linux.MemStat)

Example 2 with GetHostStatsAnswer

use of com.cloud.legacymodel.communication.answer.GetHostStatsAnswer in project cosmic by MissionCriticalCloud.

the class ResourceManagerImpl method getHostStatistics.

@Override
public HostStats getHostStatistics(final long hostId) {
    final Answer answer = this._agentMgr.easySend(hostId, new GetHostStatsCommand(this._hostDao.findById(hostId).getGuid(), this._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;
}
Also used : UnsupportedAnswer(com.cloud.legacymodel.communication.answer.UnsupportedAnswer) GetHostStatsAnswer(com.cloud.legacymodel.communication.answer.GetHostStatsAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) GetGPUStatsAnswer(com.cloud.legacymodel.communication.answer.GetGPUStatsAnswer) MaintainAnswer(com.cloud.legacymodel.communication.answer.MaintainAnswer) UnsupportedAnswer(com.cloud.legacymodel.communication.answer.UnsupportedAnswer) GetHostStatsAnswer(com.cloud.legacymodel.communication.answer.GetHostStatsAnswer) GetHostStatsCommand(com.cloud.legacymodel.communication.command.GetHostStatsCommand)

Aggregations

GetHostStatsAnswer (com.cloud.legacymodel.communication.answer.GetHostStatsAnswer)2 Answer (com.cloud.legacymodel.communication.answer.Answer)1 GetGPUStatsAnswer (com.cloud.legacymodel.communication.answer.GetGPUStatsAnswer)1 MaintainAnswer (com.cloud.legacymodel.communication.answer.MaintainAnswer)1 UnsupportedAnswer (com.cloud.legacymodel.communication.answer.UnsupportedAnswer)1 GetHostStatsCommand (com.cloud.legacymodel.communication.command.GetHostStatsCommand)1 HostStatsEntry (com.cloud.legacymodel.dc.HostStatsEntry)1 CpuStat (com.cloud.utils.linux.CpuStat)1 MemStat (com.cloud.utils.linux.MemStat)1