public Double getCpuIdle() { return vdsStatistics.getCpuIdle(); }
public Double getCpuLoad() { return vdsStatistics.getCpuLoad(); }
public Double getCpuSys() { return vdsStatistics.getCpuSys(); }
private long getSwapUsed(VdsStatistics s) { if (s==null) { return 0; } else { if (s.getSwapTotal()==null) { return 0; } else { if (s.getSwapFree()==null) { return s.getSwapTotal(); } else { return s.getSwapTotal() - s.getSwapFree(); } } } } }
@Override public void save(VdsStatistics stats) { MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() .addValue("cpu_idle", stats.getCpuIdle()) .addValue("cpu_load", stats.getCpuLoad()) .addValue("cpu_sys", stats.getCpuSys()) .addValue("cpu_user", stats.getCpuUser()) .addValue("usage_cpu_percent", stats.getUsageCpuPercent()) .addValue("usage_mem_percent", stats.getUsageMemPercent()) .addValue("usage_network_percent", stats.getUsageNetworkPercent()) .addValue("vds_id", stats.getId()) .addValue("mem_available", stats.getMemAvailable()) .addValue("mem_free" , stats.getMemFree()) .addValue("mem_shared", stats.getMemShared()) .addValue("swap_free", stats.getSwapFree()) .addValue("swap_total", stats.getSwapTotal()) .addValue("ksm_cpu_percent", stats.getKsmCpuPercent()) .addValue("ksm_pages", stats.getKsmPages()) .addValue("ksm_state", stats.getKsmState()) .addValue("anonymous_hugepages", stats.getAnonymousHugePages()) .addValue("boot_time", stats.getBootTime()) .addValue("ha_score", stats.getHighlyAvailableScore()) .addValue("ha_configured", stats.getHighlyAvailableIsConfigured()) .addValue("ha_active", stats.getHighlyAvailableIsActive()) .addValue("ha_global_maintenance", stats.getHighlyAvailableGlobalMaintenance()) .addValue("ha_local_maintenance", stats.getHighlyAvailableLocalMaintenance()) .addValue("cpu_over_commit_time_stamp", stats.getCpuOverCommitTimeStamp()) .addValue("hugepages", serializeHugePages(stats.getHugePages()));
@Override public VdsStatistics mapRow(ResultSet rs, int i) throws SQLException { VdsStatistics entity = new VdsStatistics(); entity.setCpuIdle(rs.getDouble("cpu_idle")); entity.setCpuLoad(rs.getDouble("cpu_load")); entity.setCpuSys(rs.getDouble("cpu_sys")); entity.setCpuUser(rs.getDouble("cpu_user")); entity.setUsageCpuPercent((Integer) rs.getObject("usage_cpu_percent")); entity.setUsageMemPercent((Integer) rs.getObject("usage_mem_percent")); entity.setUsageNetworkPercent((Integer) rs.getObject("usage_network_percent")); entity.setId(getGuidDefaultEmpty(rs, "vds_id")); entity.setMemAvailable(rs.getLong("mem_available")); entity.setMemFree(rs.getLong("mem_free")); entity.setMemShared(rs.getLong("mem_shared")); entity.setSwapFree(rs.getLong("swap_free")); entity.setSwapTotal(rs.getLong("swap_total")); entity.setKsmCpuPercent((Integer) rs.getObject("ksm_cpu_percent")); entity.setKsmPages(rs.getLong("ksm_pages")); entity.setKsmState((Boolean) rs.getObject("ksm_state")); entity.setAnonymousHugePages(rs.getInt("anonymous_hugepages")); entity.setBootTime((Long) rs.getObject("boot_time")); entity.setHighlyAvailableScore(rs.getInt("ha_score")); entity.setHighlyAvailableIsConfigured(rs.getBoolean("ha_configured")); entity.setHighlyAvailableIsActive(rs.getBoolean("ha_active")); entity.setHighlyAvailableGlobalMaintenance(rs.getBoolean("ha_global_maintenance")); entity.setHighlyAvailableLocalMaintenance(rs.getBoolean("ha_local_maintenance")); entity.setCpuOverCommitTimeStamp(DbFacadeUtils.fromDate(rs.getTimestamp("cpu_over_commit_time_stamp"))); entity.setHugePages(deserializeHugePages(rs.getString("hugepages"))); return entity; }
public List<Statistic> getStatistics(VDS entity) { VdsStatistics s = entity.getStatisticsData(); // if user queries host statistics before host installation completed, null values are possible (therefore added checks). long memTotal = entity.getPhysicalMemMb()==null ? 0 : entity.getPhysicalMemMb() * Mb; long memUsed = (s==null || s.getUsageMemPercent()==null) ? 0 : memTotal * s.getUsageMemPercent() / 100; List<Statistic> statistics = asList(setDatum(clone(MEM_TOTAL), memTotal), setDatum(clone(MEM_USED), memUsed), setDatum(clone(MEM_FREE), memTotal-memUsed), setDatum(clone(MEM_SHARED), (s==null || s.getMemShared()==null) ? 0 : s.getMemShared()*Mb), setDatum(clone(MEM_BUFFERS), 0), setDatum(clone(MEM_CACHED), 0), setDatum(clone(SWAP_TOTAL), (s==null || s.getSwapTotal()==null) ? 0 : s.getSwapTotal()*Mb), setDatum(clone(SWAP_FREE), (s==null || s.getSwapFree()==null) ? 0 : s.getSwapFree()*Mb), setDatum(clone(SWAP_USED), getSwapUsed(s)*Mb), setDatum(clone(SWAP_CACHED), 0), setDatum(clone(CPU_KSM), (s==null || s.getKsmCpuPercent()==null) ? 0 : s.getKsmCpuPercent()), setDatum(clone(CPU_USER), (s==null || s.getCpuUser()==null) ? 0 : s.getCpuUser()), setDatum(clone(CPU_SYS), (s==null || s.getCpuSys()==null) ? 0 : s.getCpuSys()), setDatum(clone(CPU_IDLE), (s==null || s.getCpuIdle()==null) ? 0 : s.getCpuIdle()), setDatum(clone(CPU_LOAD), (s==null || s.getCpuLoad()==null) ? 0 : s.getCpuLoad()/100), setDatum(clone(BOOT_TIME), (s==null || s.getBootTime()==null) ? 0 : s.getBootTime())); if (s != null && s.getHugePages() != null) { s.getHugePages().stream() .filter(page -> page.getAmount() != null) .map(this::createHugePagesFree) .forEach(statistics::add); } return statistics; }
static VDS setUpStatisticalEntityExpectations(VDS entity, VdsStatistics statistics) { when(entity.getPhysicalMemMb()).thenReturn(5120); when(entity.getStatisticsData()).thenReturn(statistics); when(statistics.getUsageMemPercent()).thenReturn(20); when(statistics.getSwapFree()).thenReturn(25L); when(statistics.getSwapTotal()).thenReturn(30L); when(statistics.getMemAvailable()).thenReturn(35L); when(statistics.getMemShared()).thenReturn(38L); when(statistics.getKsmCpuPercent()).thenReturn(40); when(statistics.getCpuUser()).thenReturn(45.0); when(statistics.getCpuSys()).thenReturn(50.0); when(statistics.getCpuIdle()).thenReturn(55.0); when(statistics.getCpuLoad()).thenReturn(0.60); return entity; }
private static VdsStatistics randomVdsStatistics() { RandomUtils random = RandomUtils.instance(); VdsStatistics vdsStatistics = new VdsStatistics(); vdsStatistics.setCpuIdle(random.nextDouble()); vdsStatistics.setCpuLoad(random.nextDouble()); vdsStatistics.setCpuSys(random.nextDouble()); vdsStatistics.setCpuUser(random.nextDouble()); vdsStatistics.setMemAvailable(random.nextLong()); vdsStatistics.setMemFree(random.nextLong()); vdsStatistics.setMemShared(random.nextLong()); vdsStatistics.setUsageCpuPercent(random.nextInt()); vdsStatistics.setUsageMemPercent(random.nextInt()); vdsStatistics.setUsageNetworkPercent(random.nextInt()); vdsStatistics.setCpuOverCommitTimeStamp(new Date(random.nextLong())); return vdsStatistics; }
@Override protected VdsStatistics generateNewEntity() { VdsStatistics newStatistics = new VdsStatistics(); newStatistics.setId(FixturesTool.VDS_JUST_STATIC_ID); return newStatistics; }
public Long getMemShared() { return vdsStatistics.getMemShared(); }
public Integer getUsageMemPercent() { return vdsStatistics.getUsageMemPercent(); }
public Long getSwapFree() { return vdsStatistics.getSwapFree(); }
public Long getSwapTotal() { return vdsStatistics.getSwapTotal(); }
public Double getCpuUser() { return vdsStatistics.getCpuUser(); }
public Integer getKsmCpuPercent() { return vdsStatistics.getKsmCpuPercent(); }
public VDS() { vdsStatic = new VdsStatic(); vdsDynamic = new VdsDynamic(); vdsStatistics = new VdsStatistics(); storagePoolId = Guid.Empty; spmStatus = VdsSpmStatus.None; interfaces = new ArrayList<>(); networkNames = new HashSet<>(); fenceAgents = new LinkedList<>(); }
@Override public void update(VdsStatistics stats) { MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() .addValue("cpu_idle", stats.getCpuIdle()) .addValue("cpu_load", stats.getCpuLoad()) .addValue("cpu_sys", stats.getCpuSys()) .addValue("cpu_user", stats.getCpuUser()) .addValue("usage_cpu_percent", stats.getUsageCpuPercent()) .addValue("usage_mem_percent", stats.getUsageMemPercent()) .addValue("usage_network_percent", stats.getUsageNetworkPercent()) .addValue("vds_id", stats.getId()) .addValue("mem_available", stats.getMemAvailable()) .addValue("mem_free" , stats.getMemFree()) .addValue("mem_shared", stats.getMemShared()) .addValue("swap_free", stats.getSwapFree()) .addValue("swap_total", stats.getSwapTotal()) .addValue("ksm_cpu_percent", stats.getKsmCpuPercent()) .addValue("ksm_pages", stats.getKsmPages()) .addValue("ksm_state", stats.getKsmState()) .addValue("anonymous_hugepages", stats.getAnonymousHugePages()) .addValue("boot_time", stats.getBootTime()) .addValue("ha_score", stats.getHighlyAvailableScore()) .addValue("ha_configured", stats.getHighlyAvailableIsConfigured()) .addValue("ha_active", stats.getHighlyAvailableIsActive()) .addValue("ha_global_maintenance", stats.getHighlyAvailableGlobalMaintenance()) .addValue("ha_local_maintenance", stats.getHighlyAvailableLocalMaintenance()) .addValue("cpu_over_commit_time_stamp", stats.getCpuOverCommitTimeStamp()) .addValue("hugepages", serializeHugePages(stats.getHugePages()));
public Integer getMemSharedPercent() { Long shared = vdsStatistics.getMemShared(); Integer physical = vdsDynamic.getPhysicalMemMb(); if (shared == null || physical == null || physical == 0) { return 0; } return (int) ((shared * 100) / physical); }