/** * Execute the collector to get the system info model. * * @return SystemInfo in current time */ public synchronized SystemInfo execute() { SystemInfo systemInfo = new SystemInfo(); systemInfo.setCollectTime(System.currentTimeMillis()); try { BandWidth networkUsage = getNetworkUsage(); BandWidth bandWidth = networkUsage.adjust(prev.getBandWidth()); systemInfo.setBandWidth(bandWidth); systemInfo.setCPUUsedPercentage((float) sigar.getCpuPerc().getCombined() * 100); Cpu cpu = sigar.getCpu(); systemInfo.setTotalCpuValue(cpu.getTotal()); systemInfo.setIdleCpuValue(cpu.getIdle()); Mem mem = sigar.getMem(); systemInfo.setTotalMemory(mem.getTotal() / 1024L); systemInfo.setFreeMemory(mem.getActualFree() / 1024L); systemInfo.setSystem(OperatingSystem.IS_WIN32 ? SystemInfo.System.WINDOW : SystemInfo.System.LINUX); systemInfo.setCustomValues(getCustomMonitorData()); } catch (Throwable e) { LOGGER.error("Error while getting system perf data:{}", e.getMessage()); LOGGER.debug("Error trace is ", e); } prev = systemInfo; return systemInfo; }
private void addCpu(final Collection<Definition> definitions, final String base, final ThrowingSupplier<Cpu> provider) { definitions.add(new Definition( base + "idle", "CPU Idle Time", "The idle time of the CPU, in [ms]", "ms", () -> provider.get().getIdle())); definitions.add(new Definition( base + "nice", "CPU Nice Priority Time", "The time of the CPU spent on nice priority, in [ms]", "ms", () -> provider.get().getNice())); definitions.add(new Definition( base + "sys", "CPU User Time", "The time of the CPU used by the system, in [ms]", "ms", () -> provider.get().getSys())); definitions.add(new Definition( base + "total", "CPU Total Time", "The total time of the CPU, in [ms]", "ms", () -> provider.get().getTotal())); definitions.add(new Definition( base + "wait", "CPU Wait Time", "The time the CPU had to wait for data to be loaded, in [ms]", "ms", () -> provider.get().getWait())); } }