Search in sources :

Example 6 with HostStatsEntry

use of com.cloud.agent.api.HostStatsEntry in project cosmic by MissionCriticalCloud.

the class CitrixResourceBase method getHostStats.

public HostStatsEntry getHostStats(final Connection conn, final GetHostStatsCommand cmd, final String hostGuid, final long hostId) {
    final HostStatsEntry hostStats = new HostStatsEntry(hostId, 0, 0, 0, "host", 0, 0, 0, 0);
    // call rrd method with 1
    final Object[] rrdData = getRRDData(conn, 1);
    if (rrdData == null) {
        return null;
    }
    final Integer numRows = (Integer) rrdData[0];
    final Integer numColumns = (Integer) rrdData[1];
    final Node legend = (Node) rrdData[2];
    final Node dataNode = (Node) rrdData[3];
    final NodeList legendChildren = legend.getChildNodes();
    for (int col = 0; col < numColumns; col++) {
        if (legendChildren == null || legendChildren.item(col) == null) {
            continue;
        }
        final String columnMetadata = getXMLNodeValue(legendChildren.item(col));
        if (columnMetadata == null) {
            continue;
        }
        final String[] columnMetadataList = columnMetadata.split(":");
        if (columnMetadataList.length != 4) {
            continue;
        }
        final String type = columnMetadataList[1];
        final String param = columnMetadataList[3];
        if (type.equalsIgnoreCase("host")) {
            if (param.matches("pif_eth0_rx")) {
                hostStats.setNetworkReadKBs(getDataAverage(dataNode, col, numRows) / 1000);
            } else if (param.matches("pif_eth0_tx")) {
                hostStats.setNetworkWriteKBs(getDataAverage(dataNode, col, numRows) / 1000);
            } else if (param.contains("memory_total_kib")) {
                hostStats.setTotalMemoryKBs(getDataAverage(dataNode, col, numRows));
            } else if (param.contains("memory_free_kib")) {
                hostStats.setFreeMemoryKBs(getDataAverage(dataNode, col, numRows));
            } else if (param.matches("cpu_avg")) {
                // hostStats.setNumCpus(hostStats.getNumCpus() + 1);
                hostStats.setCpuUtilization(hostStats.getCpuUtilization() + getDataAverage(dataNode, col, numRows));
            }
        /*
                 * if (param.contains("loadavg")) { hostStats.setAverageLoad((hostStats.getAverageLoad() +
                 * getDataAverage(dataNode, col, numRows))); }
                 */
        }
    }
    return hostStats;
}
Also used : Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) HostStatsEntry(com.cloud.agent.api.HostStatsEntry) XenAPIObject(com.xensource.xenapi.XenAPIObject)

Example 7 with HostStatsEntry

use of com.cloud.agent.api.HostStatsEntry in project cloudstack by apache.

the class VmwareResource method execute.

protected Answer execute(GetHostStatsCommand 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) {
            s_logger.debug(String.format("Host stats response from hypervisor is: [%s].", _gson.toJson(entry)));
            entry.setHostId(cmd.getHostId());
            answer = new GetHostStatsAnswer(cmd, entry);
        }
    } catch (Exception e) {
        s_logger.error(createLogMessageException(e, cmd), e);
    }
    if (s_logger.isTraceEnabled()) {
        s_logger.trace("GetHostStats Answer: " + _gson.toJson(answer));
    }
    return answer;
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) SetupPersistentNetworkAnswer(com.cloud.agent.api.SetupPersistentNetworkAnswer) ModifyTargetsAnswer(com.cloud.agent.api.ModifyTargetsAnswer) MigrateVmToPoolAnswer(com.cloud.agent.api.MigrateVmToPoolAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) GetVmVncTicketAnswer(com.cloud.agent.api.GetVmVncTicketAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) GetVolumeStatsAnswer(com.cloud.agent.api.GetVolumeStatsAnswer) SetupAnswer(com.cloud.agent.api.SetupAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) GetVmNetworkStatsAnswer(com.cloud.agent.api.GetVmNetworkStatsAnswer) 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) AttachIsoAnswer(com.cloud.agent.api.AttachIsoAnswer) 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) GetStoragePoolCapabilitiesAnswer(com.cloud.agent.api.GetStoragePoolCapabilitiesAnswer) 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) ReplugNicAnswer(com.cloud.agent.api.ReplugNicAnswer) 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) GetUnmanagedInstancesAnswer(com.cloud.agent.api.GetUnmanagedInstancesAnswer) ValidateSnapshotAnswer(com.cloud.agent.api.ValidateSnapshotAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareUnmanageVMInstanceAnswer(com.cloud.agent.api.PrepareUnmanageVMInstanceAnswer) 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) 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)

Example 8 with HostStatsEntry

use of com.cloud.agent.api.HostStatsEntry in project cloudstack by apache.

the class MockAgentManagerImpl method getHostStatistic.

@Override
public GetHostStatsAnswer getHostStatistic(GetHostStatsCommand cmd) {
    String hostGuid = cmd.getHostGuid();
    MockHost host = null;
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        txn.start();
        host = _mockHostDao.findByGuid(hostGuid);
        txn.commit();
        if (host == null) {
            return null;
        }
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Unable to get host " + hostGuid + " due to " + ex.getMessage(), ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    TransactionLegacy vmtxn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        vmtxn.start();
        List<MockVMVO> vms = _mockVmDao.findByHostId(host.getId());
        vmtxn.commit();
        double usedMem = 0.0;
        double usedCpu = 0.0;
        for (MockVMVO vm : vms) {
            usedMem += vm.getMemory();
            usedCpu += vm.getCpu();
        }
        HostStatsEntry hostStats = new HostStatsEntry();
        hostStats.setTotalMemoryKBs(host.getMemorySize());
        hostStats.setFreeMemoryKBs(host.getMemorySize() - usedMem);
        hostStats.setNetworkReadKBs(32768);
        hostStats.setNetworkWriteKBs(16384);
        hostStats.setCpuUtilization(usedCpu / (host.getCpuCount() * host.getCpuSpeed()));
        hostStats.setEntityType("simulator-host");
        hostStats.setHostId(cmd.getHostId());
        return new GetHostStatsAnswer(cmd, hostStats);
    } catch (Exception ex) {
        vmtxn.rollback();
        throw new CloudRuntimeException("Unable to get Vms on host " + host.getGuid() + " due to " + ex.getMessage(), ex);
    } finally {
        vmtxn.close();
        vmtxn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        vmtxn.close();
    }
}
Also used : MockVMVO(com.cloud.simulator.MockVMVO) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) MockHost(com.cloud.simulator.MockHost) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HostStatsEntry(com.cloud.agent.api.HostStatsEntry) DiscoveryException(com.cloud.exception.DiscoveryException) PatternSyntaxException(java.util.regex.PatternSyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 9 with HostStatsEntry

use of com.cloud.agent.api.HostStatsEntry 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 10 with HostStatsEntry

use of com.cloud.agent.api.HostStatsEntry in project cloudstack by apache.

the class CitrixResourceBase method getHostStats.

public HostStatsEntry getHostStats(final Connection conn, final GetHostStatsCommand cmd, final String hostGuid, final long hostId) {
    final HostStatsEntry hostStats = new HostStatsEntry(hostId, 0, 0, 0, "host", 0, 0, 0, 0);
    // call rrd method with 1
    final Object[] rrdData = getRRDData(conn, 1);
    if (rrdData == null) {
        return null;
    }
    final Integer numRows = (Integer) rrdData[0];
    final Integer numColumns = (Integer) rrdData[1];
    final Node legend = (Node) rrdData[2];
    final Node dataNode = (Node) rrdData[3];
    final NodeList legendChildren = legend.getChildNodes();
    for (int col = 0; col < numColumns; col++) {
        if (legendChildren == null || legendChildren.item(col) == null) {
            continue;
        }
        final String columnMetadata = getXMLNodeValue(legendChildren.item(col));
        if (columnMetadata == null) {
            continue;
        }
        final String[] columnMetadataList = columnMetadata.split(":");
        if (columnMetadataList.length != 4) {
            continue;
        }
        final String type = columnMetadataList[1];
        final String param = columnMetadataList[3];
        if (type.equalsIgnoreCase("host")) {
            if (param.matches("pif_eth0_rx")) {
                hostStats.setNetworkReadKBs(getDataAverage(dataNode, col, numRows) / 1000);
            } else if (param.matches("pif_eth0_tx")) {
                hostStats.setNetworkWriteKBs(getDataAverage(dataNode, col, numRows) / 1000);
            } else if (param.contains("memory_total_kib")) {
                hostStats.setTotalMemoryKBs(getDataAverage(dataNode, col, numRows));
            } else if (param.contains("memory_free_kib")) {
                hostStats.setFreeMemoryKBs(getDataAverage(dataNode, col, numRows));
            } else if (param.matches("cpu_avg")) {
                // hostStats.setNumCpus(hostStats.getNumCpus() + 1);
                hostStats.setCpuUtilization(hostStats.getCpuUtilization() + getDataAverage(dataNode, col, numRows));
            }
        /*
                 * if (param.contains("loadavg")) {
                 * hostStats.setAverageLoad((hostStats.getAverageLoad() +
                 * getDataAverage(dataNode, col, numRows))); }
                 */
        }
    }
    return hostStats;
}
Also used : Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) HostStatsEntry(com.cloud.agent.api.HostStatsEntry) XenAPIObject(com.xensource.xenapi.XenAPIObject)

Aggregations

HostStatsEntry (com.cloud.agent.api.HostStatsEntry)12 GetHostStatsAnswer (com.cloud.agent.api.GetHostStatsAnswer)8 Answer (com.cloud.agent.api.Answer)4 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)4 MaintainAnswer (com.cloud.agent.api.MaintainAnswer)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