當前位置: 首頁>>代碼示例>>Java>>正文


Java UnixOperatingSystemMXBean.getOpenFileDescriptorCount方法代碼示例

本文整理匯總了Java中com.sun.management.UnixOperatingSystemMXBean.getOpenFileDescriptorCount方法的典型用法代碼示例。如果您正苦於以下問題:Java UnixOperatingSystemMXBean.getOpenFileDescriptorCount方法的具體用法?Java UnixOperatingSystemMXBean.getOpenFileDescriptorCount怎麽用?Java UnixOperatingSystemMXBean.getOpenFileDescriptorCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.sun.management.UnixOperatingSystemMXBean的用法示例。


在下文中一共展示了UnixOperatingSystemMXBean.getOpenFileDescriptorCount方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getOpenFileDescriptorsAndPrintMemoryUsage

import com.sun.management.UnixOperatingSystemMXBean; //導入方法依賴的package包/類
public static long getOpenFileDescriptorsAndPrintMemoryUsage() {
    // Below courtesy of:
    // http://stackoverflow.com/questions/10999076/programmatically-print-the-heap-usage-that-is-typically-printed-on-jvm-exit-when
    MemoryUsage mu = ManagementFactory.getMemoryMXBean()
            .getHeapMemoryUsage();
    MemoryUsage muNH = ManagementFactory.getMemoryMXBean()
            .getNonHeapMemoryUsage();
    System.out.println("Init :" + mu.getInit() + "\nMax :" + mu.getMax()
            + "\nUsed :" + mu.getUsed() + "\nCommitted :"
            + mu.getCommitted() + "\nInit NH :" + muNH.getInit()
            + "\nMax NH :" + muNH.getMax() + "\nUsed NH:" + muNH.getUsed()
            + "\nCommitted NH:" + muNH.getCommitted());

    OperatingSystemMXBean osMxBean = ManagementFactory.getOperatingSystemMXBean();

    if (osMxBean instanceof UnixOperatingSystemMXBean) {
        UnixOperatingSystemMXBean unixOsMxBean = (UnixOperatingSystemMXBean) osMxBean;
        return unixOsMxBean.getOpenFileDescriptorCount();
    } else {
        throw new UnsupportedOperationException("Unable to determine number of open file handles on non-Unix system");
    }
}
 
開發者ID:wxyzZ,項目名稱:little_mitm,代碼行數:23,代碼來源:TestUtils.java

示例2: getMetrics

import com.sun.management.UnixOperatingSystemMXBean; //導入方法依賴的package包/類
@Override
public Map<String, Metric> getMetrics() {
    Map<String, Metric> metrics = super.getMetrics();
    UnixOperatingSystemMXBean osMxBean = ((UnixOperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean());

    registerGauge(metrics, CPU_LOAD_METRIC_NAME, osMxBean.getProcessCpuLoad());
    registerGauge(metrics, CPU_LOAD_SYSTEM_METRIC_NAME, osMxBean.getSystemCpuLoad());
    registerGauge(metrics, CPU_LOAD_SYSTEM_AVERAGE_METRIC_NAME, osMxBean.getSystemLoadAverage());
    registerGauge(metrics, CPU_PROCESSOR_COUNT_METRIC_NAME, osMxBean.getAvailableProcessors());
    registerGauge(metrics, CPU_TIME_METRIC_NAME, osMxBean.getProcessCpuTime());
    registerGauge(metrics, OS_ARCH_METRIC_NAME, osMxBean.getArch());
    registerGauge(metrics, OS_NAME_METRIC_NAME, osMxBean.getName());
    registerGauge(metrics, OS_VERSION_METRIC_NAME, osMxBean.getVersion());

    long fileDescOpenCount = osMxBean.getOpenFileDescriptorCount(), fileDescMaxCount = osMxBean.getMaxFileDescriptorCount();

    registerGauge(metrics, FILE_DESCRIPTOR_OPEN_COUNT_METRIC_NAME, fileDescOpenCount);
    registerGauge(metrics, FILE_DESCRIPTOR_MAX_COUNT_METRIC_NAME, fileDescMaxCount);
    registerRatioGauge(metrics, FILE_DESCRIPTOR_USAGE_METRIC_NAME, fileDescOpenCount, fileDescMaxCount);

    registerMemoryUsageMetrics(metrics, MEMORY_PHYSICAL_METRIC_NAME_PREFIX, osMxBean.getFreePhysicalMemorySize(), -1,
        osMxBean.getTotalPhysicalMemorySize());
    registerMemoryUsageMetrics(metrics, MEMORY_SWAP_METRIC_NAME_PREFIX, osMxBean.getFreeSwapSpaceSize(), -1, osMxBean.getTotalSwapSpaceSize());

    return metrics;
}
 
開發者ID:esacinc,項目名稱:sdcct,代碼行數:27,代碼來源:SystemMetricSet.java

示例3: setUp

import com.sun.management.UnixOperatingSystemMXBean; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
    /* some useful information - log the number of fds used before
     * and after a test is run. Helps to verify we are freeing resources
     * correctly. Unfortunately this only works on unix systems (the
     * only place sun has implemented as part of the mgmt bean api.
     */
    OperatingSystemMXBean osMbean =
        ManagementFactory.getOperatingSystemMXBean();
    if (osMbean != null && osMbean instanceof UnixOperatingSystemMXBean) {
        UnixOperatingSystemMXBean unixos =
            (UnixOperatingSystemMXBean)osMbean;
        initialFdCount = unixos.getOpenFileDescriptorCount();
        LOG.info("Initial fdcount is: "
                + initialFdCount);
    }

    setupTestEnv();

    JMXEnv.setUp();

    setUpAll();

    tmpDir = createTmpDir(BASETEST);

    startServer();

    LOG.info("Client test setup finished");
}
 
開發者ID:gerritjvv,項目名稱:bigstreams,代碼行數:30,代碼來源:ClientBase.java

示例4: tearDown

import com.sun.management.UnixOperatingSystemMXBean; //導入方法依賴的package包/類
@After
public void tearDown() throws Exception {
    LOG.info("tearDown starting");

    tearDownAll();

    stopServer();

    if (tmpDir != null) {
        Assert.assertTrue("delete " + tmpDir.toString(), recursiveDelete(tmpDir));
    }

    // This has to be set to null when the same instance of this class is reused between test cases
    serverFactory = null;

    JMXEnv.tearDown();

    /* some useful information - log the number of fds used before
     * and after a test is run. Helps to verify we are freeing resources
     * correctly. Unfortunately this only works on unix systems (the
     * only place sun has implemented as part of the mgmt bean api.
     */
    OperatingSystemMXBean osMbean =
        ManagementFactory.getOperatingSystemMXBean();
    if (osMbean != null && osMbean instanceof UnixOperatingSystemMXBean) {
        UnixOperatingSystemMXBean unixos =
            (UnixOperatingSystemMXBean)osMbean;
        long fdCount = unixos.getOpenFileDescriptorCount();
        String message = "fdcount after test is: "
                + fdCount + " at start it was " + initialFdCount;
        LOG.info(message);
        if (fdCount > initialFdCount) {
            LOG.info("sleeping for 20 secs");
            //Thread.sleep(60000);
            //assertTrue(message, fdCount <= initialFdCount);
        }
    }
}
 
開發者ID:gerritjvv,項目名稱:bigstreams,代碼行數:39,代碼來源:ClientBase.java

示例5: openFileDescriptorCount

import com.sun.management.UnixOperatingSystemMXBean; //導入方法依賴的package包/類
public static long openFileDescriptorCount() {

        if (oracleJVMAndUnix) {

            UnixOperatingSystemMXBean unix = (UnixOperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
            return unix.getOpenFileDescriptorCount();
        }else {
            return -1;
        }
    }
 
開發者ID:advantageous,項目名稱:boon,代碼行數:11,代碼來源:Sys.java

示例6: process

import com.sun.management.UnixOperatingSystemMXBean; //導入方法依賴的package包/類
@Counter
public void process(CounterBasket pw) {
	if (availableFdInfo == false) {
		 return;
	}
	
	// Currently supported only sun jvm on unix platform
	try {
		OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
		if(os instanceof UnixOperatingSystemMXBean){
			UnixOperatingSystemMXBean unixOs = (UnixOperatingSystemMXBean) os;
			long max = unixOs.getMaxFileDescriptorCount();
			long open = unixOs.getOpenFileDescriptorCount();
			
			ListValue fdUsage = new ListValue();
			fdUsage.add(max);
			fdUsage.add(open);
			
			PerfCounterPack p = pw.getPack(TimeTypeEnum.REALTIME);
			p.put(CounterConstants.JAVA_FD_USAGE, fdUsage);
		} else {
			availableFdInfo = false;
		}
	} catch (Throwable th) {
		Logger.println(th.getMessage());
		availableFdInfo = false;
	}
}
 
開發者ID:scouter-project,項目名稱:scouter,代碼行數:29,代碼來源:FDInfo.java

示例7: shouldReleaseFileDescriptorsResources

import com.sun.management.UnixOperatingSystemMXBean; //導入方法依賴的package包/類
@Test
public void shouldReleaseFileDescriptorsResources() throws Exception {
    // given
    assumeTrue(os instanceof UnixOperatingSystemMXBean);
    UnixOperatingSystemMXBean unix = (UnixOperatingSystemMXBean) os;
    long openedFileDescriptors = unix.getOpenFileDescriptorCount();
    Path cql_bootstrap = getResourcePath("cql_bootstrap");

    // when
    CqlPaths.create(Collections.singletonList(cql_bootstrap));

    // Then
    assertThat(unix.getOpenFileDescriptorCount(), is(openedFileDescriptors));
}
 
開發者ID:sky-uk,項目名稱:cqlmigrate,代碼行數:15,代碼來源:CqlPathsTest.java

示例8: testClientCleanup

import com.sun.management.UnixOperatingSystemMXBean; //導入方法依賴的package包/類
/**
 * Verify that the client is cleaning up properly. Open/close a large
 * number of sessions. Essentially looking to see if sockets/selectors
 * are being cleaned up properly during close.
 *
 * @throws Throwable
 */
@Test
public void testClientCleanup() throws Throwable {
    OperatingSystemMXBean osMbean =
        ManagementFactory.getOperatingSystemMXBean();
    if (osMbean == null 
            || !(osMbean instanceof UnixOperatingSystemMXBean))
    {
        LOG.warn("skipping testClientCleanup, only available on Unix");
        return;
    }

    final int threadCount = 3;
    final int clientCount = 10;

    /* Log the number of fds used before and after a test is run. Verifies
     * we are freeing resources correctly. Unfortunately this only works
     * on unix systems (the only place sun has implemented as part of the
     * mgmt bean api).
     */
    UnixOperatingSystemMXBean unixos =
        (UnixOperatingSystemMXBean) osMbean;
    long initialFdCount = unixos.getOpenFileDescriptorCount();

    VerifyClientCleanup threads[] = new VerifyClientCleanup[threadCount];

    for (int i = 0; i < threads.length; i++) {
        threads[i] = new VerifyClientCleanup("VCC" + i, clientCount);
        threads[i].start();
    }

    for (int i = 0; i < threads.length; i++) {
        threads[i].join(CONNECTION_TIMEOUT);
        Assert.assertTrue(threads[i].current == threads[i].count);
    }

    // if this Assert.fails it means we are not cleaning up after the closed
    // sessions.
    long currentCount = unixos.getOpenFileDescriptorCount();
    final String logmsg = "open fds after test ({}) are not significantly higher than before ({})";
    
    if (currentCount > initialFdCount + 10) {
        // consider as error
    	LOG.error(logmsg,Long.valueOf(currentCount),Long.valueOf(initialFdCount));
    } else {
    	LOG.info(logmsg,Long.valueOf(currentCount),Long.valueOf(initialFdCount));
    }
}
 
開發者ID:gerritjvv,項目名稱:bigstreams,代碼行數:55,代碼來源:ClientTest.java

示例9: addVendorInfoSunJmx

import com.sun.management.UnixOperatingSystemMXBean; //導入方法依賴的package包/類
private void addVendorInfoSunJmx(UaObjectNode vendorServerInfo) {
    try {
        com.sun.management.OperatingSystemMXBean osBean =
            (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();

        UaVariableNode processCpuLoad = new UaVariableNode(
            nodeMap,
            new NodeId(1, "VendorServerInfo/ProcessCpuLoad"),
            new QualifiedName(1, "ProcessCpuLoad"),
            LocalizedText.english("ProcessCpuLoad")) {

            @Override
            public DataValue getValue() {
                return new DataValue(new Variant(osBean.getProcessCpuLoad() * 100d));
            }
        };
        processCpuLoad.setDataType(Identifiers.Double);

        UaVariableNode systemCpuLoad = new UaVariableNode(
            nodeMap,
            new NodeId(1, "VendorServerInfo/SystemCpuLoad"),
            new QualifiedName(1, "SystemCpuLoad"),
            LocalizedText.english("SystemCpuLoad")) {
            @Override
            public DataValue getValue() {
                return new DataValue(new Variant(osBean.getSystemCpuLoad() * 100d));
            }
        };
        systemCpuLoad.setDataType(Identifiers.Double);

        vendorServerInfo.addComponent(processCpuLoad);
        vendorServerInfo.addComponent(systemCpuLoad);

        if (osBean instanceof UnixOperatingSystemMXBean) {
            UnixOperatingSystemMXBean unixBean = (UnixOperatingSystemMXBean) osBean;

            UaVariableNode openFileDescriptors = new UaVariableNode(
                nodeMap,
                new NodeId(1, "VendorServerInfo/OpenFileDescriptors"),
                new QualifiedName(1, "OpenFileDescriptors"),
                LocalizedText.english("OpenFileDescriptors")) {
                @Override
                public DataValue getValue() {
                    return new DataValue(new Variant(unixBean.getOpenFileDescriptorCount()));
                }
            };
            openFileDescriptors.setDataType(Identifiers.Int64);

            UaVariableNode maxFileDescriptors = new UaVariableNode(
                nodeMap,
                new NodeId(1, "VendorServerInfo/MaxFileDescriptors"),
                new QualifiedName(1, "MaxFileDescriptors"),
                LocalizedText.english("MaxFileDescriptors")) {
                @Override
                public DataValue getValue() {
                    return new DataValue(new Variant(unixBean.getMaxFileDescriptorCount()));
                }
            };
            maxFileDescriptors.setDataType(Identifiers.Int64);

            vendorServerInfo.addComponent(openFileDescriptors);
            vendorServerInfo.addComponent(maxFileDescriptors);
        }
    } catch (Throwable e) {
        // ignore
    }
}
 
開發者ID:eclipse,項目名稱:milo,代碼行數:68,代碼來源:VendorNamespace.java

示例10: testClientCleanup

import com.sun.management.UnixOperatingSystemMXBean; //導入方法依賴的package包/類
/**
 * Verify that the client is cleaning up properly. Open/close a large
 * number of sessions. Essentially looking to see if sockets/selectors
 * are being cleaned up properly during close.
 *
 * @throws Throwable
 */
@Test
public void testClientCleanup() throws Throwable {
    OperatingSystemMXBean osMbean =
        ManagementFactory.getOperatingSystemMXBean();
    if (osMbean == null 
            || !(osMbean instanceof UnixOperatingSystemMXBean))
    {
        LOG.warn("skipping testClientCleanup, only available on Unix");
        return;
    }

    final int threadCount = 3;
    final int clientCount = 10;

    /* Log the number of fds used before and after a test is run. Verifies
     * we are freeing resources correctly. Unfortunately this only works
     * on unix systems (the only place sun has implemented as part of the
     * mgmt bean api).
     */
    UnixOperatingSystemMXBean unixos =
        (UnixOperatingSystemMXBean) osMbean;
    long initialFdCount = unixos.getOpenFileDescriptorCount();

    VerifyClientCleanup threads[] = new VerifyClientCleanup[threadCount];

    for (int i = 0; i < threads.length; i++) {
        threads[i] = new VerifyClientCleanup("VCC" + i, clientCount);
        threads[i].start();
    }

    for (int i = 0; i < threads.length; i++) {
        threads[i].join(CONNECTION_TIMEOUT);
        assertTrue(threads[i].current == threads[i].count);
    }

    // if this fails it means we are not cleaning up after the closed
    // sessions.
    assertTrue("open fds after test are not significantly higher than before",
            unixos.getOpenFileDescriptorCount() <= initialFdCount + 10);
}
 
開發者ID:prodigeni,項目名稱:zookeeper.dsc,代碼行數:48,代碼來源:ClientTest.java


注:本文中的com.sun.management.UnixOperatingSystemMXBean.getOpenFileDescriptorCount方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。