use of org.ovirt.engine.core.vdsbroker.NetworkStatisticsBuilder in project ovirt-engine by oVirt.
the class VdsBrokerObjectsBuilder method updateVDSStatisticsData.
public static void updateVDSStatisticsData(VDS vds, Map<String, Object> struct) {
// ------------- vds memory usage ---------------------------
vds.setUsageMemPercent(assignIntValue(struct, VdsProperties.mem_usage));
// ------------- vds network statistics ---------------------
Map<String, Object> interfaces = (Map<String, Object>) struct.get(VdsProperties.NETWORK);
if (interfaces != null) {
int networkUsage = 0;
Map<String, VdsNetworkInterface> nicsByName = Entities.entitiesByName(vds.getInterfaces());
NetworkStatisticsBuilder statsBuilder = new NetworkStatisticsBuilder();
for (Entry<String, Object> entry : interfaces.entrySet()) {
if (nicsByName.containsKey(entry.getKey())) {
VdsNetworkInterface existingIface = nicsByName.get(entry.getKey());
existingIface.setVdsId(vds.getId());
Map<String, Object> dict = (Map<String, Object>) entry.getValue();
VdsNetworkInterface reportedIface = new VdsNetworkInterface();
extractInterfaceStatistics(dict, reportedIface);
statsBuilder.updateExistingInterfaceStatistics(existingIface, reportedIface);
existingIface.getStatistics().setStatus(assignInterfaceStatusValue(dict, VdsProperties.iface_status));
if (!NetworkCommonUtils.isVlan(existingIface) && !existingIface.isPartOfBond()) {
Double ifaceUsage = computeInterfaceUsage(existingIface);
if (ifaceUsage != null) {
networkUsage = (int) Math.max(networkUsage, ifaceUsage);
}
}
}
}
vds.setUsageNetworkPercent(networkUsage);
}
// ----------- vds cpu statistics info ---------------------
vds.setCpuSys(assignDoubleValue(struct, VdsProperties.cpu_sys));
vds.setCpuUser(assignDoubleValue(struct, VdsProperties.cpu_user));
if (vds.getCpuSys() != null && vds.getCpuUser() != null) {
vds.setUsageCpuPercent((int) (vds.getCpuSys() + vds.getCpuUser()));
}
// CPU load reported by VDSM is in uptime-style format, i.e. normalized
// to unity, so that say an 8% load is reported as 0.08
Double d = assignDoubleValue(struct, VdsProperties.cpu_load);
d = (d != null) ? d : 0;
vds.setCpuLoad(d.doubleValue() * 100.0);
vds.setCpuIdle(assignDoubleValue(struct, VdsProperties.cpu_idle));
vds.setMemAvailable(assignLongValue(struct, VdsProperties.mem_available));
vds.setMemFree(assignLongValue(struct, VdsProperties.memFree));
vds.setMemShared(assignLongValue(struct, VdsProperties.mem_shared));
vds.setSwapFree(assignLongValue(struct, VdsProperties.swap_free));
vds.setSwapTotal(assignLongValue(struct, VdsProperties.swap_total));
vds.setKsmCpuPercent(assignIntValue(struct, VdsProperties.ksm_cpu_percent));
vds.setKsmPages(assignLongValue(struct, VdsProperties.ksm_pages));
vds.setKsmState(assignBoolValue(struct, VdsProperties.ksm_state));
// dynamic data got from GetVdsStats
if (struct.containsKey(VdsProperties.transparent_huge_pages_state)) {
vds.setTransparentHugePagesState(EnumUtils.valueOf(VdsTransparentHugePagesState.class, struct.get(VdsProperties.transparent_huge_pages_state).toString(), true));
}
if (struct.containsKey(VdsProperties.anonymous_transparent_huge_pages)) {
vds.setAnonymousHugePages(assignIntValue(struct, VdsProperties.anonymous_transparent_huge_pages));
}
if (struct.containsKey(VdsProperties.hugepages)) {
Object hugepages = struct.get(VdsProperties.hugepages);
if (hugepages instanceof Map) {
Map<String, Map<String, String>> hugepagesMap = (Map<String, Map<String, String>>) hugepages;
List<HugePage> parsedHugePages = hugepagesMap.entrySet().stream().map(entry -> new HugePage(Integer.parseInt(entry.getKey()), assignIntValue(entry.getValue(), VdsProperties.free_hugepages))).collect(Collectors.toList());
vds.setHugePages(parsedHugePages);
}
}
vds.setNetConfigDirty(assignBoolValue(struct, VdsProperties.netConfigDirty));
vds.setImagesLastCheck(assignDoubleValue(struct, VdsProperties.images_last_check));
vds.setImagesLastDelay(assignDoubleValue(struct, VdsProperties.images_last_delay));
Integer vm_count = assignIntValue(struct, VdsProperties.vm_count);
vds.setVmCount(vm_count == null ? 0 : vm_count);
vds.setVmActive(assignIntValue(struct, VdsProperties.vm_active));
vds.setVmMigrating(assignIntValue(struct, VdsProperties.vm_migrating));
Integer inOutMigrations;
inOutMigrations = assignIntValue(struct, VdsProperties.INCOMING_VM_MIGRATIONS);
if (inOutMigrations != null) {
vds.setIncomingMigrations(inOutMigrations);
} else {
// TODO remove in 4.x when all hosts will send in/out migrations separately
vds.setIncomingMigrations(-1);
}
inOutMigrations = assignIntValue(struct, VdsProperties.OUTGOING_VM_MIGRATIONS);
if (inOutMigrations != null) {
vds.setOutgoingMigrations(inOutMigrations);
} else {
// TODO remove in 4.x when all hosts will send in/out migrations separately
vds.setOutgoingMigrations(-1);
}
updateVDSDomainData(vds, struct);
updateLocalDisksUsage(vds, struct);
// hosted engine
Integer haScore = null;
Boolean haIsConfigured = null;
Boolean haIsActive = null;
Boolean haGlobalMaint = null;
Boolean haLocalMaint = null;
if (struct.containsKey(VdsProperties.ha_stats)) {
Map<String, Object> haStats = (Map<String, Object>) struct.get(VdsProperties.ha_stats);
if (haStats != null) {
haScore = assignIntValue(haStats, VdsProperties.ha_stats_score);
haIsConfigured = assignBoolValue(haStats, VdsProperties.ha_stats_is_configured);
haIsActive = assignBoolValue(haStats, VdsProperties.ha_stats_is_active);
haGlobalMaint = assignBoolValue(haStats, VdsProperties.ha_stats_global_maintenance);
haLocalMaint = assignBoolValue(haStats, VdsProperties.ha_stats_local_maintenance);
}
} else {
haScore = assignIntValue(struct, VdsProperties.ha_score);
// prior to 3.4, haScore was returned if ha was installed; assume active if > 0
if (haScore != null) {
haIsConfigured = true;
haIsActive = haScore > 0;
}
}
vds.setHighlyAvailableScore(haScore != null ? haScore : 0);
vds.setHighlyAvailableIsConfigured(haIsConfigured != null ? haIsConfigured : false);
vds.setHighlyAvailableIsActive(haIsActive != null ? haIsActive : false);
vds.setHighlyAvailableGlobalMaintenance(haGlobalMaint != null ? haGlobalMaint : false);
vds.setHighlyAvailableLocalMaintenance(haLocalMaint != null ? haLocalMaint : false);
vds.setBootTime(assignLongValue(struct, VdsProperties.bootTime));
updateNumaStatisticsData(vds, struct);
updateV2VJobs(vds, struct);
}
use of org.ovirt.engine.core.vdsbroker.NetworkStatisticsBuilder in project ovirt-engine by oVirt.
the class VmAnalyzer method updateInterfaceStatistics.
private void updateInterfaceStatistics() {
List<VmNetworkInterface> ifsStats = vdsmVm.getInterfaceStatistics();
if (ifsStats == null || ifsStats.isEmpty()) {
return;
}
loadVmNetworkInterfaces();
List<String> macs = new ArrayList<>();
statistics.setUsageNetworkPercent(0);
NetworkStatisticsBuilder statsBuilder = new NetworkStatisticsBuilder();
for (VmNetworkInterface ifStats : ifsStats) {
boolean firstTime = !macs.contains(ifStats.getMacAddress());
VmNetworkInterface vmIface = ifaces.stream().filter(iface -> iface.getMacAddress().equals(ifStats.getMacAddress())).findFirst().orElse(null);
if (vmIface == null) {
continue;
}
// VDSM is going to stop reporting the speed, so we override it with the value from the database
// TODO: the speed should not be part of the statistics at all, needs to move it elsewhere
ifStats.setSpeed(vmIface.getSpeed());
// if rtl+pv it will get here 2 times (we take the max one)
if (firstTime) {
statsBuilder.updateExistingInterfaceStatistics(vmIface, ifStats);
} else {
vmIface.getStatistics().setReceiveRate(max(vmIface.getStatistics().getReceiveRate(), ifStats.getStatistics().getReceiveRate()));
vmIface.getStatistics().setReceiveDropRate(max(vmIface.getStatistics().getReceiveDropRate(), ifStats.getStatistics().getReceiveDropRate()));
vmIface.getStatistics().setTransmitRate(max(vmIface.getStatistics().getTransmitRate(), ifStats.getStatistics().getTransmitRate()));
vmIface.getStatistics().setTransmitDropRate(max(vmIface.getStatistics().getTransmitDropRate(), ifStats.getStatistics().getTransmitDropRate()));
}
vmIface.setVmId(dbVm.getId());
if (ifStats.getSpeed() != null && vmIface.getStatistics().getReceiveRate() != null && vmIface.getStatistics().getReceiveRate() > 0) {
double rx_percent = vmIface.getStatistics().getReceiveRate();
double tx_percent = vmIface.getStatistics().getTransmitRate();
statistics.setUsageNetworkPercent(max(statistics.getUsageNetworkPercent(), (int) max(rx_percent, tx_percent)));
}
if (firstTime) {
macs.add(ifStats.getMacAddress());
}
}
statistics.setUsageNetworkPercent(min(statistics.getUsageNetworkPercent(), 100));
Integer usageHistoryLimit = Config.getValue(ConfigValues.UsageHistoryLimit);
statistics.addNetworkUsageHistory(statistics.getUsageNetworkPercent(), usageHistoryLimit);
}
Aggregations