Java Code Examples for oshi.hardware.GlobalMemory#getAvailable()
The following examples show how to use
oshi.hardware.GlobalMemory#getAvailable() .
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: MemSwapUsageSampler.java From kieker with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public void sample(final IMonitoringController monitoringCtr) throws SigarException { if (!monitoringCtr.isMonitoringEnabled() || !monitoringCtr.isProbeActivated(SignatureFactory.createMemSwapSignature())) { return; } final GlobalMemory globalMemory = this.hardwareAbstractionLayer.getMemory(); final long memoryTotal = globalMemory.getTotal(); final long memoryAvailable = globalMemory.getAvailable(); final long memoryUsed = memoryTotal - memoryAvailable; final long swapTotal = globalMemory.getSwapTotal(); final long swapUsed = globalMemory.getSwapUsed(); final long swapFree = swapTotal - swapUsed; final MemSwapUsageRecord r = new MemSwapUsageRecord(monitoringCtr.getTimeSource().getTime(), monitoringCtr.getHostname(), memoryTotal, memoryUsed, memoryAvailable, swapTotal, swapUsed, swapFree); monitoringCtr.newMonitoringRecord(r); }
Example 3
Source File: OshiPlatformCacheTest.java From hawkular-agent with Apache License 2.0 | 6 votes |
@Test public void getMemory() { OshiPlatformCache oshi = newOshiPlatformCache(); GlobalMemory memory = oshi.getMemory(); Assert.assertNotNull(memory); long avail = memory.getAvailable(); long total = memory.getTotal(); Assert.assertTrue(avail > -1L); Assert.assertTrue(total > -1L); print("===MEMORY ==="); print(" Available=[%s] (%d)", FormatUtil.formatBytes(avail), avail); print(" Total=[%s] (%d)", FormatUtil.formatBytes(total), total); print(" toString=[%s]", memory.toString()); }
Example 4
Source File: NativeManager.java From LagMonitor with MIT License | 5 votes |
public long getFreeSwap() { if (osBean instanceof com.sun.management.OperatingSystemMXBean) { com.sun.management.OperatingSystemMXBean nativeOsBean = (com.sun.management.OperatingSystemMXBean) osBean; return nativeOsBean.getFreeSwapSpaceSize(); } else if (info != null) { GlobalMemory memory = info.getHardware().getMemory(); return memory.getAvailable(); } return -1; }
Example 5
Source File: NativeManager.java From LagMonitor with MIT License | 5 votes |
public long getFreeSwap() { if (osBean instanceof com.sun.management.OperatingSystemMXBean) { com.sun.management.OperatingSystemMXBean nativeOsBean = (com.sun.management.OperatingSystemMXBean) osBean; return nativeOsBean.getFreeSwapSpaceSize(); } else if (info != null) { GlobalMemory memory = info.getHardware().getMemory(); return memory.getAvailable(); } return -1; }