Search in sources :

Example 1 with CpuStatistics

use of org.ovirt.engine.core.common.businessentities.CpuStatistics in project ovirt-engine by oVirt.

the class VdsBrokerObjectsBuilder method updateNumaStatisticsData.

public static void updateNumaStatisticsData(VDS vds, Map<String, Object> struct) {
    List<VdsNumaNode> vdsNumaNodes = new ArrayList<>();
    if (vds.getNumaNodeList() != null && !vds.getNumaNodeList().isEmpty()) {
        vdsNumaNodes.addAll(vds.getNumaNodeList());
    }
    List<CpuStatistics> cpuStatsData = new ArrayList<>();
    if (struct.containsKey(VdsProperties.CPU_STATS)) {
        Map<String, Map<String, Object>> cpuStats = (Map<String, Map<String, Object>>) struct.get(VdsProperties.CPU_STATS);
        Map<Integer, List<CpuStatistics>> numaNodeCpuStats = new HashMap<>();
        for (Map.Entry<String, Map<String, Object>> item : cpuStats.entrySet()) {
            CpuStatistics data = buildVdsCpuStatistics(item);
            cpuStatsData.add(data);
            int numaNodeIndex = assignIntValue(item.getValue(), VdsProperties.NUMA_NODE_INDEX);
            if (!numaNodeCpuStats.containsKey(numaNodeIndex)) {
                numaNodeCpuStats.put(numaNodeIndex, new ArrayList<>());
            }
            numaNodeCpuStats.get(numaNodeIndex).add(data);
        }
        DecimalFormat percentageFormatter = new DecimalFormat("#.##");
        for (Map.Entry<Integer, List<CpuStatistics>> item : numaNodeCpuStats.entrySet()) {
            VdsNumaNode nodeWithStatistics = buildVdsNumaNodeStatistics(percentageFormatter, item);
            if (vdsNumaNodes.isEmpty()) {
                vdsNumaNodes.add(nodeWithStatistics);
            } else {
                boolean foundNumaNode = false;
                // append the statistics to the correct numaNode (search by its Index.)
                for (VdsNumaNode currNumaNode : vdsNumaNodes) {
                    if (currNumaNode.getIndex() == nodeWithStatistics.getIndex()) {
                        currNumaNode.setNumaNodeStatistics(nodeWithStatistics.getNumaNodeStatistics());
                        foundNumaNode = true;
                        break;
                    }
                }
                // append new numaNode (contains only statistics) if not found existing
                if (!foundNumaNode) {
                    vdsNumaNodes.add(nodeWithStatistics);
                }
            }
        }
    }
    if (struct.containsKey(VdsProperties.NUMA_NODE_FREE_MEM_STAT)) {
        Map<String, Map<String, Object>> memStats = (Map<String, Map<String, Object>>) struct.get(VdsProperties.NUMA_NODE_FREE_MEM_STAT);
        for (Map.Entry<String, Map<String, Object>> item : memStats.entrySet()) {
            VdsNumaNode node = NumaUtils.getVdsNumaNodeByIndex(vdsNumaNodes, Integer.parseInt(item.getKey()));
            if (node != null && node.getNumaNodeStatistics() != null) {
                node.getNumaNodeStatistics().setMemFree(assignLongValue(item.getValue(), VdsProperties.NUMA_NODE_FREE_MEM));
                node.getNumaNodeStatistics().setMemUsagePercent(assignIntValue(item.getValue(), VdsProperties.NUMA_NODE_MEM_PERCENT));
            }
        }
    }
    vds.getNumaNodeList().clear();
    vds.getNumaNodeList().addAll(vdsNumaNodes);
    vds.getStatisticsData().getCpuCoreStatistics().clear();
    vds.getStatisticsData().getCpuCoreStatistics().addAll(cpuStatsData);
}
Also used : HashMap(java.util.HashMap) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) VdsNumaNode(org.ovirt.engine.core.common.businessentities.VdsNumaNode) ArrayList(java.util.ArrayList) List(java.util.List) CpuStatistics(org.ovirt.engine.core.common.businessentities.CpuStatistics) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with CpuStatistics

use of org.ovirt.engine.core.common.businessentities.CpuStatistics in project ovirt-engine by oVirt.

the class VdsBrokerObjectsBuilder method buildVdsNumaNodeStatistics.

private static VdsNumaNode buildVdsNumaNodeStatistics(DecimalFormat percentageFormatter, Map.Entry<Integer, List<CpuStatistics>> item) {
    VdsNumaNode node = new VdsNumaNode();
    NumaNodeStatistics nodeStat = new NumaNodeStatistics();
    double nodeCpuUser = 0.0;
    double nodeCpuSys = 0.0;
    double nodeCpuIdle = 0.0;
    for (CpuStatistics cpuStat : item.getValue()) {
        nodeCpuUser += cpuStat.getCpuUser();
        nodeCpuSys += cpuStat.getCpuSys();
        nodeCpuIdle += cpuStat.getCpuIdle();
    }
    nodeStat.setCpuUser(Double.parseDouble(percentageFormatter.format(nodeCpuUser / item.getValue().size())));
    nodeStat.setCpuSys(Double.parseDouble(percentageFormatter.format(nodeCpuSys / item.getValue().size())));
    nodeStat.setCpuIdle(Double.parseDouble(percentageFormatter.format(nodeCpuIdle / item.getValue().size())));
    nodeStat.setCpuUsagePercent((int) (nodeStat.getCpuSys() + nodeStat.getCpuUser()));
    node.setIndex(item.getKey());
    node.setNumaNodeStatistics(nodeStat);
    return node;
}
Also used : VdsNumaNode(org.ovirt.engine.core.common.businessentities.VdsNumaNode) NumaNodeStatistics(org.ovirt.engine.core.common.businessentities.NumaNodeStatistics) CpuStatistics(org.ovirt.engine.core.common.businessentities.CpuStatistics)

Example 3 with CpuStatistics

use of org.ovirt.engine.core.common.businessentities.CpuStatistics in project ovirt-engine by oVirt.

the class VdsBrokerObjectsBuilder method buildVdsCpuStatistics.

private static CpuStatistics buildVdsCpuStatistics(Map.Entry<String, Map<String, Object>> item) {
    CpuStatistics data = new CpuStatistics();
    data.setCpuId(Integer.parseInt(item.getKey()));
    data.setCpuUser(assignDoubleValue(item.getValue(), VdsProperties.NUMA_CPU_USER));
    data.setCpuSys(assignDoubleValue(item.getValue(), VdsProperties.NUMA_CPU_SYS));
    data.setCpuIdle(assignDoubleValue(item.getValue(), VdsProperties.NUMA_CPU_IDLE));
    data.setCpuUsagePercent((int) (data.getCpuSys() + data.getCpuUser()));
    return data;
}
Also used : CpuStatistics(org.ovirt.engine.core.common.businessentities.CpuStatistics)

Aggregations

CpuStatistics (org.ovirt.engine.core.common.businessentities.CpuStatistics)3 VdsNumaNode (org.ovirt.engine.core.common.businessentities.VdsNumaNode)2 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 NumaNodeStatistics (org.ovirt.engine.core.common.businessentities.NumaNodeStatistics)1