Search in sources :

Example 6 with GetHostStatsAnswer

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;
}
Also used : UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) GetGPUStatsAnswer(com.cloud.agent.api.GetGPUStatsAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) Answer(com.cloud.agent.api.Answer) UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) GetHostStatsCommand(com.cloud.agent.api.GetHostStatsCommand)

Example 7 with GetHostStatsAnswer

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);
}
Also used : GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CPUStat(org.apache.cloudstack.utils.linux.CPUStat) HostStatsEntry(com.cloud.agent.api.HostStatsEntry) MemStat(org.apache.cloudstack.utils.linux.MemStat)

Example 8 with GetHostStatsAnswer

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());
    }
}
Also used : FenceAnswer(com.cloud.agent.api.FenceAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) Answer(com.cloud.agent.api.Answer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) SecurityGroupRuleAnswer(com.cloud.agent.api.SecurityGroupRuleAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) HostStatsEntry(com.cloud.agent.api.HostStatsEntry) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(javax.naming.ConfigurationException)

Example 9 with GetHostStatsAnswer

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;
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) ModifyTargetsAnswer(com.cloud.agent.api.ModifyTargetsAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) SetupAnswer(com.cloud.agent.api.SetupAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) CheckOnHostAnswer(com.cloud.agent.api.CheckOnHostAnswer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) RevertToVMSnapshotAnswer(com.cloud.agent.api.RevertToVMSnapshotAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) CreateVMSnapshotAnswer(com.cloud.agent.api.CreateVMSnapshotAnswer) DeleteVMSnapshotAnswer(com.cloud.agent.api.DeleteVMSnapshotAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) ScaleVmAnswer(com.cloud.agent.api.ScaleVmAnswer) MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) ValidateSnapshotAnswer(com.cloud.agent.api.ValidateSnapshotAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) GetVmDiskStatsAnswer(com.cloud.agent.api.GetVmDiskStatsAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) HostStatsEntry(com.cloud.agent.api.HostStatsEntry) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) RemoteException(java.rmi.RemoteException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException)

Aggregations

GetHostStatsAnswer (com.cloud.agent.api.GetHostStatsAnswer)9 HostStatsEntry (com.cloud.agent.api.HostStatsEntry)7 Answer (com.cloud.agent.api.Answer)5 MaintainAnswer (com.cloud.agent.api.MaintainAnswer)5 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)4 ReadyAnswer (com.cloud.agent.api.ReadyAnswer)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 ConfigurationException (javax.naming.ConfigurationException)4 CheckHealthAnswer (com.cloud.agent.api.CheckHealthAnswer)3 CheckNetworkAnswer (com.cloud.agent.api.CheckNetworkAnswer)3 FenceAnswer (com.cloud.agent.api.FenceAnswer)3 GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)3 GetVmStatsAnswer (com.cloud.agent.api.GetVmStatsAnswer)3 GetVncPortAnswer (com.cloud.agent.api.GetVncPortAnswer)3 MigrateAnswer (com.cloud.agent.api.MigrateAnswer)3 ModifyStoragePoolAnswer (com.cloud.agent.api.ModifyStoragePoolAnswer)3 PrepareForMigrationAnswer (com.cloud.agent.api.PrepareForMigrationAnswer)3 RebootAnswer (com.cloud.agent.api.RebootAnswer)3 StartAnswer (com.cloud.agent.api.StartAnswer)3 StopAnswer (com.cloud.agent.api.StopAnswer)3