com.sun.management.UnixOperatingSystemMXBean Java Examples
The following examples show how to use
com.sun.management.UnixOperatingSystemMXBean.
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: LiveSourceTest.java From clarity with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test(enabled = false) @Parameters({"srcFile", "dstFile"}) public void testLiveSourceMMap(final String srcFile, final String dstFile) throws Exception { createWriterThread(srcFile, dstFile); while (true) { long t0 = System.currentTimeMillis(); Path filePath = Paths.get(dstFile); FileChannel open = FileChannel.open(filePath); MappedByteBuffer buf = open.map(FileChannel.MapMode.READ_ONLY, 0L, Files.size(filePath)); long t1 = System.currentTimeMillis(); OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); if(os instanceof UnixOperatingSystemMXBean){ System.out.println("Number of open fd: " + ((UnixOperatingSystemMXBean) os).getOpenFileDescriptorCount()); } System.out.println(t1 - t0); System.out.println(buf.remaining()); Thread.sleep(500); } }
Example #2
Source File: ProcessMonitor.java From ns4_gear_watchdog with Apache License 2.0 | 6 votes |
Report() { this.isUnix = osMxBean instanceof UnixOperatingSystemMXBean; // Defaults are -1 if (this.isUnix) { UnixOperatingSystemMXBean unixOsBean = (UnixOperatingSystemMXBean) osMxBean;; this.openFds = unixOsBean.getOpenFileDescriptorCount(); this.maxFds = unixOsBean.getMaxFileDescriptorCount(); this.cpuMillisTotal = TimeUnit.MILLISECONDS.convert( unixOsBean.getProcessCpuTime(), TimeUnit.NANOSECONDS ); this.cpuProcessPercent = scaleLoadToPercent(unixOsBean.getProcessCpuLoad()); this.cpuSystemPercent = scaleLoadToPercent(unixOsBean.getSystemCpuLoad()); this.memTotalVirtualInBytes = unixOsBean.getCommittedVirtualMemorySize(); } }
Example #3
Source File: OperatingSystemMetricSet.java From styx with Apache License 2.0 | 6 votes |
@Override public Map<String, Metric> getMetrics() { Map<String, Gauge<?>> gauges = new HashMap<>(); castIfInstance(bean, UnixOperatingSystemMXBean.class).ifPresent(unixBean -> { gauges.put("fileDescriptors.max", unixBean::getMaxFileDescriptorCount); gauges.put("fileDescriptors.open", unixBean::getOpenFileDescriptorCount); }); gauges.put("process.cpu.load", bean::getProcessCpuLoad); gauges.put("process.cpu.time", bean::getProcessCpuTime); gauges.put("system.cpu.load", bean::getSystemCpuLoad); gauges.put("memory.physical.free", bean::getFreePhysicalMemorySize); gauges.put("memory.physical.total", bean::getTotalPhysicalMemorySize); gauges.put("memory.virtual.committed", bean::getCommittedVirtualMemorySize); gauges.put("swapSpace.free", bean::getFreeSwapSpaceSize); gauges.put("swapSpace.total", bean::getTotalSwapSpaceSize); // Using a Map<String, Gauge<?>> to avoid casting each metric provider to Gauge<?> above, but at the expense of having to cast the return value toMap`. return rawCast(gauges); }
Example #4
Source File: FileDescriptorRatioGauge.java From metrics with Apache License 2.0 | 6 votes |
private Ratio getRatioInternal() { if (os instanceof UnixOperatingSystemMXBean) { final UnixOperatingSystemMXBean unixOs = (UnixOperatingSystemMXBean) os; return Ratio.of(unixOs.getOpenFileDescriptorCount(), unixOs.getMaxFileDescriptorCount()); } else { return Ratio.of(Double.NaN, Double.NaN); } // try { // return Ratio.of(invoke("getOpenFileDescriptorCount"), // invoke("getMaxFileDescriptorCount")); // } catch (NoSuchMethodException e) { // return Ratio.of(Double.NaN, Double.NaN); // } catch (IllegalAccessException e) { // return Ratio.of(Double.NaN, Double.NaN); // } catch (InvocationTargetException e) { // return Ratio.of(Double.NaN, Double.NaN); // } }
Example #5
Source File: BaseSystemTest.java From sparkey-java with Apache License 2.0 | 5 votes |
static long countOpenFileDescriptors() { OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); if(os instanceof UnixOperatingSystemMXBean){ long openFileDescriptorCount = ((UnixOperatingSystemMXBean) os).getOpenFileDescriptorCount(); return openFileDescriptorCount; } return -1; }
Example #6
Source File: Sys.java From boon with Apache License 2.0 | 5 votes |
public static double processCpuLoad() { if (oracleJVMAndUnix) { UnixOperatingSystemMXBean unix = (UnixOperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); return unix.getProcessCpuLoad(); }else { return -1; } }
Example #7
Source File: Sys.java From boon with Apache License 2.0 | 5 votes |
public static double systemCpuLoad() { if (oracleJVMAndUnix) { UnixOperatingSystemMXBean unix = (UnixOperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); return unix.getSystemCpuLoad(); }else { return -1; } }
Example #8
Source File: Sys.java From boon with Apache License 2.0 | 5 votes |
public static long totalPhysicalMemorySize() { if (oracleJVMAndUnix) { UnixOperatingSystemMXBean unix = (UnixOperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); return unix.getTotalPhysicalMemorySize(); }else { return -1; } }
Example #9
Source File: Sys.java From boon with Apache License 2.0 | 5 votes |
public static long freePhysicalMemorySize() { if (oracleJVMAndUnix) { UnixOperatingSystemMXBean unix = (UnixOperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); return unix.getFreePhysicalMemorySize(); }else { return -1; } }
Example #10
Source File: Sys.java From boon with Apache License 2.0 | 5 votes |
public static long processCpuTime() { if (oracleJVMAndUnix) { UnixOperatingSystemMXBean unix = (UnixOperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); return unix.getProcessCpuTime(); }else { return -1; } }
Example #11
Source File: Sys.java From boon with Apache License 2.0 | 5 votes |
public static long freeSwapSpaceSize() { if (oracleJVMAndUnix) { UnixOperatingSystemMXBean unix = (UnixOperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); return unix.getFreeSwapSpaceSize(); }else { return -1; } }
Example #12
Source File: Sys.java From boon with Apache License 2.0 | 5 votes |
public static long totalSwapSpaceSize() { if (oracleJVMAndUnix) { UnixOperatingSystemMXBean unix = (UnixOperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); return unix.getTotalSwapSpaceSize(); }else { return -1; } }
Example #13
Source File: Sys.java From boon with Apache License 2.0 | 5 votes |
public static long committedVirtualMemorySize() { if (oracleJVMAndUnix) { UnixOperatingSystemMXBean unix = (UnixOperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); return unix.getCommittedVirtualMemorySize(); }else { return -1; } }
Example #14
Source File: Sys.java From boon with Apache License 2.0 | 5 votes |
public static long openFileDescriptorCount() { if (oracleJVMAndUnix) { UnixOperatingSystemMXBean unix = (UnixOperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); return unix.getOpenFileDescriptorCount(); }else { return -1; } }
Example #15
Source File: Sys.java From boon with Apache License 2.0 | 5 votes |
public static long maxFileDescriptorCount() { if (oracleJVMAndUnix) { UnixOperatingSystemMXBean unix = (UnixOperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); return unix.getMaxFileDescriptorCount(); }else { return -1; } }
Example #16
Source File: LogHelper.java From blog-non-blocking-rest-service-with-spring-mvc with Apache License 2.0 | 5 votes |
protected void updateStatistics(long reqId, long concReqs) { if (concReqs > maxConcurrentRequests) { maxConcurrentRequests = concReqs; } if (reqId % requestsPerLog == 0 && reqId > 0) { Object openFiles = "UNKNOWN"; if (os instanceof UnixOperatingSystemMXBean) { openFiles = ((UnixOperatingSystemMXBean) os).getOpenFileDescriptorCount(); } log.info("Statistics: noOfReqs: {}, maxConcReqs: {}, openFiles: {}", reqId, maxConcurrentRequests, openFiles); } }
Example #17
Source File: ProcessingController.java From blog-non-blocking-rest-service-with-spring-mvc with Apache License 2.0 | 5 votes |
private void updateStatistics(long reqId, long concReqs) { if (concReqs > maxConcurrentRequests) { maxConcurrentRequests = concReqs; } if (reqId % STAT_REQS_PER_LOG == 0 && reqId > 0) { Object openFiles = "UNKNOWN"; if (os instanceof UnixOperatingSystemMXBean) { openFiles = ((UnixOperatingSystemMXBean) os).getOpenFileDescriptorCount(); } LOG.info("Statistics: noOfReqs: {}, maxConcReqs: {}, openFiles: {}", reqId, maxConcurrentRequests, openFiles); } }
Example #18
Source File: NativeManager.java From LagMonitor with MIT License | 5 votes |
public long getMaxFileDescriptors() { if (osBean instanceof com.sun.management.UnixOperatingSystemMXBean) { return ((UnixOperatingSystemMXBean) osBean).getMaxFileDescriptorCount(); } else if (info != null) { return info.getOperatingSystem().getFileSystem().getMaxFileDescriptors(); } return -1; }
Example #19
Source File: NoProcessFilesBehind.java From activemq-artemis with Apache License 2.0 | 5 votes |
public static long getOpenFD() { if (os instanceof UnixOperatingSystemMXBean) { return ((UnixOperatingSystemMXBean) os).getOpenFileDescriptorCount(); } else { return 0; } }
Example #20
Source File: NativeManager.java From LagMonitor with MIT License | 5 votes |
public long getOpenFileDescriptors() { if (osBean instanceof com.sun.management.UnixOperatingSystemMXBean) { return ((UnixOperatingSystemMXBean) osBean).getOpenFileDescriptorCount(); } else if (info != null) { return info.getOperatingSystem().getFileSystem().getOpenFileDescriptors(); } return -1; }
Example #21
Source File: ProcessMonitor.java From ns4_gear_watchdog with Apache License 2.0 | 5 votes |
private static short scaleLoadToPercent(double load) { if (osMxBean instanceof UnixOperatingSystemMXBean) { if (load >= 0) { return (short) (load * 100); } else { return -1; } } else { return -1; } }
Example #22
Source File: FileDescriptorRatioGaugeTest.java From metrics with Apache License 2.0 | 5 votes |
@Test public void validateFileDescriptorRatioPresenceOnNixPlatforms() throws Exception { OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean(); assumeTrue(osBean instanceof com.sun.management.UnixOperatingSystemMXBean); assertThat(new FileDescriptorRatioGauge().getValue()) .isGreaterThanOrEqualTo(0.0) .isLessThanOrEqualTo(1.0); }
Example #23
Source File: HotSpotMXBeanStatistics.java From garmadon with Apache License 2.0 | 5 votes |
private AbstractStatistic createFileDescriptorStatistics() { java.lang.management.OperatingSystemMXBean os = ManagementFactoryHelper.getOperatingSystemMXBean(); if (os instanceof UnixOperatingSystemMXBean) { UnixOperatingSystemMXBean unixOs = (UnixOperatingSystemMXBean) os; return new FileDescriptorStatistics(unixOs); } return null; }
Example #24
Source File: SystemUsageDataCollectorTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void testSystemUsageDataIsCollected() { HBData systemUsage = grabDataByCollectorId(usageSystemCollector.getCollectorId()); assertNotNull("Repository usage data missing.", systemUsage); Map<String,Object> data = systemUsage.getData(); assertTrue(data.containsKey("cpu")); Map<String, Object> cpu = (Map<String, Object>) data.get("cpu"); assertTrue(cpu.containsKey("availableProcessors")); OperatingSystemMXBean osMBean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class); if (osMBean != null) { if (osMBean instanceof UnixOperatingSystemMXBean) { assertTrue(data.containsKey("openFileDescriptorCount")); } assertTrue(cpu.containsKey("percentageProcessLoad")); assertTrue(cpu.containsKey("percentageSystemLoad")); assertTrue(cpu.containsKey("systemLoadAverage")); } assertTrue(data.containsKey("db")); Map<String, Object> db = (Map<String, Object>) data.get("db"); assertTrue(db.containsKey("idleConnections")); assertTrue(db.containsKey("activeConnections")); assertTrue(data.containsKey("mem")); Map<String, Object> mem = (Map<String, Object>) data.get("mem"); assertTrue(mem.containsKey("free")); assertTrue(mem.containsKey("total")); assertTrue(mem.containsKey("max")); }
Example #25
Source File: NativeManager.java From LagMonitor with MIT License | 5 votes |
public long getOpenFileDescriptors() { if (osBean instanceof com.sun.management.UnixOperatingSystemMXBean) { return ((UnixOperatingSystemMXBean) osBean).getOpenFileDescriptorCount(); } else if (info != null) { return info.getOperatingSystem().getFileSystem().getOpenFileDescriptors(); } return -1; }
Example #26
Source File: NativeManager.java From LagMonitor with MIT License | 5 votes |
public long getMaxFileDescriptors() { if (osBean instanceof com.sun.management.UnixOperatingSystemMXBean) { return ((UnixOperatingSystemMXBean) osBean).getMaxFileDescriptorCount(); } else if (info != null) { return info.getOperatingSystem().getFileSystem().getMaxFileDescriptors(); } return -1; }
Example #27
Source File: SegmentRunner.java From cassandra-reaper with Apache License 2.0 | 5 votes |
/** * This method is intended to be temporary, until we find the root issue of too many open files issue. */ private static long getOpenFilesAmount() { OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); long amountOfOpenFiles = -1; if (os instanceof UnixOperatingSystemMXBean) { amountOfOpenFiles = ((UnixOperatingSystemMXBean) os).getOpenFileDescriptorCount(); } return amountOfOpenFiles; }
Example #28
Source File: RuntimeService.java From jolie with GNU Lesser General Public License v2.1 | 5 votes |
private void stats_files( Value stats ) { OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean(); if( osBean instanceof UnixOperatingSystemMXBean ) { UnixOperatingSystemMXBean unixBean = (UnixOperatingSystemMXBean) osBean; stats.setFirstChild( "openCount", unixBean.getOpenFileDescriptorCount() ); stats.setFirstChild( "maxCount", unixBean.getMaxFileDescriptorCount() ); } }
Example #29
Source File: Main.java From outbackcdx with Apache License 2.0 | 5 votes |
private static int maxOpenSstFilesHeuristic() { Object bean = ManagementFactory.getOperatingSystemMXBean(); if (!(bean instanceof OperatingSystemMXBean)) { System.err.println("Warning: unable to get OS memory information"); return -1; } // assume each open SST file takes 10MB of RAM // allow RocksDB half of whatever's left after the JVM takes its share OperatingSystemMXBean osBean = (OperatingSystemMXBean) bean; long physicalMemory = osBean.getTotalPhysicalMemorySize(); long jvmMaxHeap = Runtime.getRuntime().maxMemory(); long memoryAvailableToRocksDB = physicalMemory / 2 - jvmMaxHeap; long maxOpenFiles = memoryAvailableToRocksDB / (10 * 1024 * 1024); // but if ulimit -n is lower use that instead so we don't hit IO errors if (bean instanceof UnixOperatingSystemMXBean) { UnixOperatingSystemMXBean unixBean = (UnixOperatingSystemMXBean) bean; long maxFileDescriptors = unixBean.getMaxFileDescriptorCount() - unixBean.getOpenFileDescriptorCount() - 20; if (maxOpenFiles > maxFileDescriptors) { maxOpenFiles = maxFileDescriptors; } } // if we've got 40 terabytes of RAM we can't actually apply a limit // and hey we probably don't need one anyway! if (maxOpenFiles > Integer.MAX_VALUE) { return -1; } // we need to be able to open at least a few files // if there's this little RAM we're in trouble anyway if (maxOpenFiles < 16) { return 16; } return (int)maxOpenFiles; }
Example #30
Source File: TestFileContext.java From datacollector with Apache License 2.0 | 5 votes |
private long getOpenFileDescriptors() { OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); if (os instanceof UnixOperatingSystemMXBean) { return ((UnixOperatingSystemMXBean) os).getOpenFileDescriptorCount(); } else { return -1; } }