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);
}
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;
}
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;
}
Aggregations