oshi.hardware.HardwareAbstractionLayer Java Examples
The following examples show how to use
oshi.hardware.HardwareAbstractionLayer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OshiDevice.java From iot-java with Eclipse Public License 1.0 | 7 votes |
private static JsonObject createOshiData() { HardwareAbstractionLayer hal = si.getHardware(); CentralProcessor processor = hal.getProcessor(); double loadAverage = processor.getSystemCpuLoad() * 100; GlobalMemory memory = hal.getMemory(); long availableMemory = memory.getAvailable(); long totalMemory = memory.getTotal(); long usedMemory = totalMemory - availableMemory; double memoryUtilization = (usedMemory / (double) totalMemory) * 100; JsonObject json = new JsonObject(); json.addProperty("memory", memoryUtilization); json.addProperty("cpu", loadAverage); return json; }
Example #2
Source File: MonitorServiceImpl.java From albedo with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Map<String, Object> getServers() { Map<String, Object> resultMap = new LinkedHashMap<>(8); try { SystemInfo si = new SystemInfo(); OperatingSystem os = si.getOperatingSystem(); HardwareAbstractionLayer hal = si.getHardware(); // 系统信息 resultMap.put("sys", getSystemInfo(os)); // cpu 信息 resultMap.put("cpu", getCpuInfo(hal.getProcessor())); // 内存信息 resultMap.put("memory", getMemoryInfo(hal.getMemory())); // 交换区信息 resultMap.put("swap", getSwapInfo(hal.getMemory())); // 磁盘 resultMap.put("disk", getDiskInfo(os)); resultMap.put("time", DateUtil.format(new Date(), "HH:mm:ss")); } catch (Exception e) { e.printStackTrace(); } return resultMap; }
Example #3
Source File: SystemResourcesMetricsInitializer.java From flink with Apache License 2.0 | 6 votes |
public static void instantiateSystemMetrics(MetricGroup metricGroup, Time probeInterval) { try { MetricGroup system = metricGroup.addGroup("System"); SystemResourcesCounter systemResourcesCounter = new SystemResourcesCounter(probeInterval); systemResourcesCounter.start(); SystemInfo systemInfo = new SystemInfo(); HardwareAbstractionLayer hardwareAbstractionLayer = systemInfo.getHardware(); instantiateMemoryMetrics(system.addGroup("Memory"), hardwareAbstractionLayer.getMemory()); instantiateSwapMetrics(system.addGroup("Swap"), hardwareAbstractionLayer.getMemory()); instantiateCPUMetrics(system.addGroup("CPU"), systemResourcesCounter); instantiateNetworkMetrics(system.addGroup("Network"), systemResourcesCounter); } catch (NoClassDefFoundError ex) { LOG.warn( "Failed to initialize system resource metrics because of missing class definitions." + " Did you forget to explicitly add the oshi-core optional dependency?", ex); } }
Example #4
Source File: StatsTask.java From Lavalink with MIT License | 6 votes |
private double getProcessRecentCpuUsage() { double output; HardwareAbstractionLayer hal = si.getHardware(); OperatingSystem os = si.getOperatingSystem(); OSProcess p = os.getProcess(os.getProcessId()); if (cpuTime != 0) { double uptimeDiff = p.getUpTime() - uptime; double cpuDiff = (p.getKernelTime() + p.getUserTime()) - cpuTime; output = cpuDiff / uptimeDiff; } else { output = ((double) (p.getKernelTime() + p.getUserTime())) / (double) p.getUserTime(); } // Record for next invocation uptime = p.getUpTime(); cpuTime = p.getKernelTime() + p.getUserTime(); return output / hal.getProcessor().getLogicalProcessorCount(); }
Example #5
Source File: ServerServiceImpl.java From DimpleBlog with Apache License 2.0 | 6 votes |
@Override public Map<String, Object> getServers() { Map<String, Object> resultMap = new LinkedHashMap<>(8); try { SystemInfo si = new SystemInfo(); OperatingSystem os = si.getOperatingSystem(); HardwareAbstractionLayer hal = si.getHardware(); // 系统信息 resultMap.put("sys", getSystemInfo(os)); // cpu 信息 resultMap.put("cpu", getCpuInfo(hal.getProcessor())); // 内存信息 resultMap.put("memory", getMemoryInfo(hal.getMemory())); // 交换区信息 resultMap.put("swap", getSwapInfo(hal.getMemory())); // 磁盘 resultMap.put("disk", getDiskInfo(os)); resultMap.put("time", DateUtils.parseDateToStr("HH:mm:ss", new Date())); } catch (Exception e) { e.printStackTrace(); } return resultMap; }
Example #6
Source File: SystemMonitorUtil.java From base-admin with MIT License | 6 votes |
/** * 获取Windows 磁盘使用率 * * @return 磁盘使用率 */ private static HashMap<String, Long> getWinDiskUsage() { HardwareAbstractionLayer hal = systemInfo.getHardware(); HWDiskStore[] diskStores = hal.getDiskStores(); HashMap<String, Long> hashMap = new HashMap<>(); long total = 0; long used = 0; if (diskStores != null && diskStores.length > 0) { for (HWDiskStore diskStore : diskStores) { long size = diskStore.getSize(); long writeBytes = diskStore.getWriteBytes(); total += size; used += writeBytes; } } hashMap.put("total",total); hashMap.put("used",used); return hashMap; }
Example #7
Source File: SystemResourcesMetricsInitializer.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
public static void instantiateSystemMetrics(MetricGroup metricGroup, Time probeInterval) { try { MetricGroup system = metricGroup.addGroup("System"); SystemResourcesCounter systemResourcesCounter = new SystemResourcesCounter(probeInterval); systemResourcesCounter.start(); SystemInfo systemInfo = new SystemInfo(); HardwareAbstractionLayer hardwareAbstractionLayer = systemInfo.getHardware(); instantiateMemoryMetrics(system.addGroup("Memory"), hardwareAbstractionLayer.getMemory()); instantiateSwapMetrics(system.addGroup("Swap"), hardwareAbstractionLayer.getMemory()); instantiateCPUMetrics(system.addGroup("CPU"), systemResourcesCounter); instantiateNetworkMetrics(system.addGroup("Network"), systemResourcesCounter); } catch (NoClassDefFoundError ex) { LOG.warn( "Failed to initialize system resource metrics because of missing class definitions." + " Did you forget to explicitly add the oshi-core optional dependency?", ex); } }
Example #8
Source File: ServerInfo.java From mogu_blog_v2 with Apache License 2.0 | 6 votes |
public void copyTo() { try { SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); setCpuInfo(hal.getProcessor()); setMemInfo(hal.getMemory()); setSysInfo(); setJvmInfo(); setSysFiles(si.getOperatingSystem()); } catch (Exception e) { log.error(e.getMessage()); } }
Example #9
Source File: SystemResourcesMetricsInitializer.java From flink with Apache License 2.0 | 6 votes |
public static void instantiateSystemMetrics(MetricGroup metricGroup, Time probeInterval) { try { MetricGroup system = metricGroup.addGroup("System"); SystemResourcesCounter systemResourcesCounter = new SystemResourcesCounter(probeInterval); systemResourcesCounter.start(); SystemInfo systemInfo = new SystemInfo(); HardwareAbstractionLayer hardwareAbstractionLayer = systemInfo.getHardware(); instantiateMemoryMetrics(system.addGroup("Memory"), hardwareAbstractionLayer.getMemory()); instantiateSwapMetrics(system.addGroup("Swap"), hardwareAbstractionLayer.getMemory()); instantiateCPUMetrics(system.addGroup("CPU"), systemResourcesCounter); instantiateNetworkMetrics(system.addGroup("Network"), systemResourcesCounter); } catch (NoClassDefFoundError ex) { LOG.warn( "Failed to initialize system resource metrics because of missing class definitions." + " Did you forget to explicitly add the oshi-core optional dependency?", ex); } }
Example #10
Source File: UsageStatisticsCollectorImpl.java From hivemq-community-edition with Apache License 2.0 | 5 votes |
private void collectSystemStatistics(final @NotNull Statistic statistic) { if (!SYSTEM_METRICS_ENABLED) { return; } final OperatingSystem operatingSystem; final HardwareAbstractionLayer hardware; try { final SystemInfo systemInfo = new SystemInfo(); operatingSystem = systemInfo.getOperatingSystem(); hardware = systemInfo.getHardware(); } catch (final UnsupportedOperationException e) { log.debug("system metrics are not supported, ignoring extended system information"); log.trace("original exception", e); return; } statistic.setOsManufacturer(operatingSystem.getManufacturer()); statistic.setOs(operatingSystem.getFamily()); final OperatingSystemVersion version = operatingSystem.getVersion(); statistic.setOsVersion(version.getVersion()); statistic.setOpenFileLimit(operatingSystem.getFileSystem().getMaxFileDescriptors()); //disk space in MB long totalDiskSpace = 0; for (final OSFileStore osFileStore : operatingSystem.getFileSystem().getFileStores()) { totalDiskSpace += (osFileStore.getTotalSpace() / 1024 / 1024); } statistic.setDiskSize(totalDiskSpace); final CentralProcessor processor = hardware.getProcessor(); statistic.setCpu(processor.toString()); statistic.setCpuSockets(processor.getPhysicalPackageCount()); statistic.setCpuPhysicalCores(processor.getPhysicalProcessorCount()); statistic.setCpuTotalCores(processor.getLogicalProcessorCount()); statistic.setOsUptime(processor.getSystemUptime()); statistic.setMemorySize(hardware.getMemory().getTotal() / 1024 / 1024); }
Example #11
Source File: NativeCommand.java From LagMonitor with MIT License | 5 votes |
private void displayNativeInfo(CommandSender sender, SystemInfo systemInfo) { HardwareAbstractionLayer hardware = systemInfo.getHardware(); OperatingSystem operatingSystem = systemInfo.getOperatingSystem(); //swap and load is already available in the environment command because MBeans already supports this long uptime = TimeUnit.SECONDS.toMillis(operatingSystem.getSystemUptime()); String uptimeFormat = LagMonitor.formatDuration(Duration.ofMillis(uptime)); sendMessage(sender, "OS Uptime", uptimeFormat); String startTime = LagMonitor.formatDuration(Duration.ofMillis(uptime)); sendMessage(sender, "OS Start time", startTime); sendMessage(sender, "CPU Freq", Arrays.toString(hardware.getProcessor().getCurrentFreq())); sendMessage(sender, "CPU Max Freq", String.valueOf(hardware.getProcessor().getMaxFreq())); sendMessage(sender, "VM Hypervisor", DetectVM.identifyVM()); // //IO wait // double wait = cpuPerc.getWait(); // sender.sendMessage(PRIMARY_COLOR + "CPU Wait (I/O): " + SECONDARY_COLOR + wait + '%'); // // Mem mem = sigar.getMem(); // //included cache // long actualUsed = mem.getActualUsed(); // long used = mem.getUsed(); // // long cache = used - actualUsed; // sender.sendMessage(PRIMARY_COLOR + "Memory Cache: " + SECONDARY_COLOR + Sigar.formatSize(cache)); //disk printDiskInfo(sender, hardware.getDiskStores()); displayMounts(sender, operatingSystem.getFileSystem().getFileStores()); printSensorsInfo(sender, hardware.getSensors()); printBoardInfo(sender, hardware.getComputerSystem()); printRAMInfo(sender, hardware.getMemory().getPhysicalMemory()); }
Example #12
Source File: NativeCommand.java From LagMonitor with MIT License | 5 votes |
private void displayNativeInfo(CommandSender sender, SystemInfo systemInfo) { HardwareAbstractionLayer hardware = systemInfo.getHardware(); OperatingSystem operatingSystem = systemInfo.getOperatingSystem(); //swap and load is already available in the environment command because MBeans already supports this long uptime = TimeUnit.SECONDS.toMillis(operatingSystem.getSystemUptime()); String uptimeFormat = LagMonitor.formatDuration(Duration.ofMillis(uptime)); sendMessage(sender, "OS Uptime", uptimeFormat); String startTime = LagMonitor.formatDuration(Duration.ofMillis(uptime)); sendMessage(sender, "OS Start time", startTime); sendMessage(sender, "CPU Freq", Arrays.toString(hardware.getProcessor().getCurrentFreq())); sendMessage(sender, "CPU Max Freq", String.valueOf(hardware.getProcessor().getMaxFreq())); sendMessage(sender, "VM Hypervisor", DetectVM.identifyVM()); // //IO wait // double wait = cpuPerc.getWait(); // sender.sendMessage(PRIMARY_COLOR + "CPU Wait (I/O): " + SECONDARY_COLOR + wait + '%'); // // Mem mem = sigar.getMem(); // //included cache // long actualUsed = mem.getActualUsed(); // long used = mem.getUsed(); // // long cache = used - actualUsed; // sender.sendMessage(PRIMARY_COLOR + "Memory Cache: " + SECONDARY_COLOR + Sigar.formatSize(cache)); //disk printDiskInfo(sender, hardware.getDiskStores()); displayMounts(sender, operatingSystem.getFileSystem().getFileStores()); printSensorsInfo(sender, hardware.getSensors()); printBoardInfo(sender, hardware.getComputerSystem()); printRAMInfo(sender, hardware.getMemory().getPhysicalMemory()); }
Example #13
Source File: StatsTask.java From Lavalink with MIT License | 4 votes |
private void sendStats() { if (context.getSessionPaused()) return; JSONObject out = new JSONObject(); final int[] playersTotal = {0}; final int[] playersPlaying = {0}; socketServer.getContexts().forEach(socketContext -> { playersTotal[0] += socketContext.getPlayers().size(); playersPlaying[0] += socketContext.getPlayingPlayers().size(); }); out.put("op", "stats"); out.put("players", playersTotal[0]); out.put("playingPlayers", playersPlaying[0]); out.put("uptime", System.currentTimeMillis() - Launcher.INSTANCE.getStartTime()); // In bytes JSONObject mem = new JSONObject(); mem.put("free", Runtime.getRuntime().freeMemory()); mem.put("used", Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()); mem.put("allocated", Runtime.getRuntime().totalMemory()); mem.put("reservable", Runtime.getRuntime().maxMemory()); out.put("memory", mem); HardwareAbstractionLayer hal = si.getHardware(); JSONObject cpu = new JSONObject(); cpu.put("cores", Runtime.getRuntime().availableProcessors()); cpu.put("systemLoad", hal.getProcessor().getSystemCpuLoad()); double load = getProcessRecentCpuUsage(); if (!Double.isFinite(load)) load = 0; cpu.put("lavalinkLoad", load); out.put("cpu", cpu); int totalSent = 0; int totalNulled = 0; int players = 0; for (Player player : context.getPlayingPlayers()) { AudioLossCounter counter = player.getAudioLossCounter(); if (!counter.isDataUsable()) continue; players++; totalSent += counter.getLastMinuteSuccess(); totalNulled += counter.getLastMinuteLoss(); } int totalDeficit = players * AudioLossCounter.EXPECTED_PACKET_COUNT_PER_MIN - (totalSent + totalNulled); // We can't divide by 0 if (players != 0) { JSONObject frames = new JSONObject(); frames.put("sent", totalSent / players); frames.put("nulled", totalNulled / players); frames.put("deficit", totalDeficit / players); out.put("frameStats", frames); } context.send(out); }
Example #14
Source File: PerformanceChart.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
private static String buildSystemInfo() { StringBuilder b = new StringBuilder(); final SystemInfo systemInfo = new SystemInfo(); final HardwareAbstractionLayer hardware = systemInfo.getHardware(); final Processor[] processors = hardware.getProcessors(); b.append("Processor: ").append(processors[0].getIdentifier()).append("\n"); for (Processor p : processors) { b.append("\t").append(p.getName()).append("\n"); } final Memory memory = hardware.getMemory(); b.append(String.format("Memory: %,d Mb\n", memory.getTotal() / (1024 * 1024))); final OperatingSystem os = systemInfo.getOperatingSystem(); b.append(String.format("OS: %s %s %s\n", os.getManufacturer(), os.getFamily(), os.getVersion())); return b.toString(); }
Example #15
Source File: Server.java From LuckyFrameWeb with GNU Affero General Public License v3.0 | 3 votes |
public void copyTo() throws Exception { SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); setCpuInfo(hal.getProcessor()); setMemInfo(hal.getMemory()); setSysInfo(); setJvmInfo(); setSysFiles(si.getOperatingSystem()); }
Example #16
Source File: Server.java From spring-boot-demo with MIT License | 3 votes |
public void copyTo() throws Exception { SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); setCpuInfo(hal.getProcessor()); setMemInfo(hal.getMemory()); setSysInfo(); setJvmInfo(); setSysFiles(si.getOperatingSystem()); }
Example #17
Source File: Server.java From ruoyiplus with MIT License | 3 votes |
public void copyTo() throws Exception { SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); setCpuInfo(hal.getProcessor()); setMemInfo(hal.getMemory()); setSysInfo(); setJvmInfo(); setSysFiles(si.getOperatingSystem()); }
Example #18
Source File: Server.java From LuckyFrameClient with GNU Affero General Public License v3.0 | 3 votes |
public void copyTo() { SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); setCpuInfo(hal.getProcessor()); setMemInfo(hal.getMemory()); setSysInfo(); setJvmInfo(); setSysFiles(si.getOperatingSystem()); }
Example #19
Source File: Server.java From Shiro-Action with MIT License | 3 votes |
public void copyTo() throws Exception { SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); setCpuInfo(hal.getProcessor()); setMemInfo(hal.getMemory()); setSysInfo(); setJvmInfo(); setSysFiles(si.getOperatingSystem()); }
Example #20
Source File: Server.java From spring-boot-demo with MIT License | 3 votes |
public void copyTo() throws Exception { SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); setCpuInfo(hal.getProcessor()); setMemInfo(hal.getMemory()); setSysInfo(); setJvmInfo(); setSysFiles(si.getOperatingSystem()); }
Example #21
Source File: Server.java From RuoYi-Vue with MIT License | 3 votes |
public void copyTo() throws Exception { SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); setCpuInfo(hal.getProcessor()); setMemInfo(hal.getMemory()); setSysInfo(); setJvmInfo(); setSysFiles(si.getOperatingSystem()); }
Example #22
Source File: Server.java From NutzSite with Apache License 2.0 | 3 votes |
public void copyTo() throws Exception { SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); setCpuInfo(hal.getProcessor()); setMemInfo(hal.getMemory()); setSysInfo(); setJvmInfo(); setSysFiles(si.getOperatingSystem()); }
Example #23
Source File: Server.java From spring-boot-demo with MIT License | 3 votes |
public void copyTo() throws Exception { SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); setCpuInfo(hal.getProcessor()); setMemInfo(hal.getMemory()); setSysInfo(); setJvmInfo(); setSysFiles(si.getOperatingSystem()); }
Example #24
Source File: SystemHardwareInfo.java From Guns with GNU Lesser General Public License v3.0 | 3 votes |
public void copyTo() { SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); setCpuInfo(hal.getProcessor()); setMemInfo(hal.getMemory()); setSysInfo(); setJvmInfo(); setSysFiles(si.getOperatingSystem()); }
Example #25
Source File: Server.java From supplierShop with MIT License | 3 votes |
public void copyTo() throws Exception { SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); setCpuInfo(hal.getProcessor()); setMemInfo(hal.getMemory()); setSysInfo(); setJvmInfo(); setSysFiles(si.getOperatingSystem()); }
Example #26
Source File: Server.java From boot-actuator with MIT License | 3 votes |
public void copyTo() throws Exception { SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); setCpuInfo(hal.getProcessor()); setMemInfo(hal.getMemory()); setSysInfo(); setJvmInfo(); setSysFiles(si.getOperatingSystem()); }
Example #27
Source File: Server.java From RuoYi with Apache License 2.0 | 3 votes |
public void copyTo(){ SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); setCpuInfo(hal.getProcessor()); setMemInfo(hal.getMemory()); setSysInfo(); setJvmInfo(); setSysFiles(si.getOperatingSystem()); }
Example #28
Source File: LoadAverageSampler.java From kieker with Apache License 2.0 | 2 votes |
/** * Constructs a new {@link AbstractOshiSampler} with given * {@link HardwareAbstractionLayer} instance used to retrieve the sensor data. * Users should use the factory method * {@link kieker.monitoring.sampler.sigar.SigarSamplerFactory#createSensorLoadAverage()} * to acquire an instance rather than calling this constructor directly. * * @param hardwareAbstractionLayer * The {@link HardwareAbstractionLayer} which will be used to * retrieve the data. */ public LoadAverageSampler(final HardwareAbstractionLayer hardwareAbstractionLayer) { super(hardwareAbstractionLayer); }
Example #29
Source File: CPUsDetailedPercSampler.java From kieker with Apache License 2.0 | 2 votes |
/** * Constructs a new {@link AbstractOshiSampler} with given * {@link HardwareAbstractionLayer} instance used to retrieve the sensor data. * Users should use the factory method * {@link kieker.monitoring.sampler.oshi.OshiSamplerFactory#createSensorCPUsDetailedPerc()} * to acquire an instance rather than calling this constructor directly. * * @param hardwareAbstractionLayer * The {@link HardwareAbstractionLayer} which will be used to * retrieve the data. */ public CPUsDetailedPercSampler(final HardwareAbstractionLayer hardwareAbstractionLayer) { super(hardwareAbstractionLayer); }
Example #30
Source File: DiskUsageSampler.java From kieker with Apache License 2.0 | 2 votes |
/** * Constructs a new {@link AbstractOshiSampler} with given * {@link HardwareAbstractionLayer} instance used to retrieve the sensor data. * Users should use the factory method * {@link kieker.monitoring.sampler.oshi.OshiSamplerFactory#createSensorDiskUsage()} * to acquire an instance rather than calling this constructor directly. * * @param hardwareAbstractionLayer * The {@link HardwareAbstractionLayer} which will be used to * retrieve the data. */ public DiskUsageSampler(final HardwareAbstractionLayer hardwareAbstractionLayer) { super(hardwareAbstractionLayer); }