Search in sources :

Example 1 with HostStatsEntry

use of com.cloud.legacymodel.dc.HostStatsEntry 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 HostStatsEntry

use of com.cloud.legacymodel.dc.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.legacymodel.dc.HostStatsEntry) XenAPIObject(com.xensource.xenapi.XenAPIObject)

Aggregations

HostStatsEntry (com.cloud.legacymodel.dc.HostStatsEntry)2 GetHostStatsAnswer (com.cloud.legacymodel.communication.answer.GetHostStatsAnswer)1 CpuStat (com.cloud.utils.linux.CpuStat)1 MemStat (com.cloud.utils.linux.MemStat)1 XenAPIObject (com.xensource.xenapi.XenAPIObject)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1