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


Java UnixOperatingSystemMXBean類代碼示例

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


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

示例1: hydrateSystemHealth

import com.sun.management.UnixOperatingSystemMXBean; //導入依賴的package包/類
public HealthInfo hydrateSystemHealth() {
    Runtime rt = Runtime.getRuntime();
    long memUsage = (rt.totalMemory() - rt.freeMemory());
    long usedMB = memUsage / 1024 / 1024;
    system.setJvmMemoryUsage(memUsage);
    system.setJvmMemoryUsageMb(usedMB);
    system.setDiskFreeAppDirectory(new File(Settings.instance().getTargetFolder()).getUsableSpace());
    system.setDiskFreeDataDirectory(new File(Settings.instance().getDataDirectory()).getUsableSpace());
    system.setDiskFreeDataDirectoryMb(new File(Settings.instance().getDataDirectory()).getUsableSpace() / 1024 / 1024);
    system.setDiskFreeLogDirectory(new File("/tmp").getUsableSpace());
    OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
    if(os instanceof UnixOperatingSystemMXBean){
        UnixOperatingSystemMXBean unixBean = (UnixOperatingSystemMXBean) os;
        //unixBean.
        // get system load
        // get process CPU load

        system.setFileHandlesOpen(unixBean.getOpenFileDescriptorCount());
    }
    return this;
}
 
開發者ID:StallionCMS,項目名稱:stallion-core,代碼行數:22,代碼來源:HealthInfo.java

示例2: tearDown

import com.sun.management.UnixOperatingSystemMXBean; //導入依賴的package包/類
@Override
public void tearDown() throws Exception {
    LOG.info("TearDown started");
    
    OperatingSystemMXBean osMbean =
        ManagementFactory.getOperatingSystemMXBean();
    if (osMbean != null && osMbean instanceof UnixOperatingSystemMXBean) {
        UnixOperatingSystemMXBean unixos =
            (UnixOperatingSystemMXBean)osMbean;
        LOG.info("fdcount after test is: "
                + unixos.getOpenFileDescriptorCount());
    }

    shutdownServers();

    for (String hp : hostPort.split(",")) {
        Assert.assertTrue("waiting for server down",
                   ClientBase.waitForServerDown(hp,
                                       ClientBase.CONNECTION_TIMEOUT));
        LOG.info(hp + " is no longer accepting client connections");
    }

    JMXEnv.tearDown();
}
 
開發者ID:gerritjvv,項目名稱:bigstreams,代碼行數:25,代碼來源:QuorumBase.java

示例3: 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

示例4: doHealthCheck

import com.sun.management.UnixOperatingSystemMXBean; //導入依賴的package包/類
@Override
protected void doHealthCheck(final Builder builder)
        throws Exception {
    final OperatingSystemMXBean os = getOperatingSystemMXBean();
    if (os instanceof UnixOperatingSystemMXBean) {
        final UnixOperatingSystemMXBean unix
                = (UnixOperatingSystemMXBean) os;
        builder.withDetail("max-file-descriptors",
                unix.getMaxFileDescriptorCount()).
                withDetail("open-file-descriptors",
                        unix.getOpenFileDescriptorCount());
    }

    final java.io.File here = new java.io.File(".");
    builder.withDetail("usable-disk", here.getUsableSpace()).
            withDetail("total-disk", here.getTotalSpace());

    builder.up();
}
 
開發者ID:binkley,項目名稱:simple-boot,代碼行數:20,代碼來源:File.java

示例5: 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

示例6: getMetrics

import com.sun.management.UnixOperatingSystemMXBean; //導入依賴的package包/類
public Map<String, Metric> getMetrics() {
  final Map<String, Metric> gauges = new HashMap<>();
  if (osMxBean instanceof UnixOperatingSystemMXBean) {
    gauges.put("open", (Gauge<Long>) () -> getMetricLong("getOpenFileDescriptorCount"));
    gauges.put("max", (Gauge<Long>) () -> getMetricLong("getMaxFileDescriptorCount"));
  }
  return gauges;
}
 
開發者ID:ApptuitAI,項目名稱:JInsight,代碼行數:9,代碼來源:FileDescriptorMetrics.java

示例7: getOpenFileDescriptorCount

import com.sun.management.UnixOperatingSystemMXBean; //導入依賴的package包/類
private long getOpenFileDescriptorCount() {
  if (os instanceof UnixOperatingSystemMXBean) {
    return ((UnixOperatingSystemMXBean) os).getOpenFileDescriptorCount();
  } else {
    return -1;
  }
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:8,代碼來源:TestAsyncHBaseSink.java

示例8: StandardMetric

import com.sun.management.UnixOperatingSystemMXBean; //導入依賴的package包/類
StandardMetric(final StatusReader statusReader, final OperatingSystemMXBean osBean, final RuntimeMXBean runtimeBean) {
    this.statusReader = statusReader;
    this.osBean = osBean;
    this.runtimeBean = runtimeBean;
    this.unix = (osBean instanceof UnixOperatingSystemMXBean);
    this.linux = (osBean.getName().indexOf("Linux") == 0);
}
 
開發者ID:outbrain,項目名稱:prometheus-client,代碼行數:8,代碼來源:StandardMetric.java

示例9: tearDown

import com.sun.management.UnixOperatingSystemMXBean; //導入依賴的package包/類
public void tearDown() throws Exception {
    LOG.info("TearDown started");

    OperatingSystemMXBean osMbean = ManagementFactory.getOperatingSystemMXBean();
    if (osMbean != null && osMbean instanceof UnixOperatingSystemMXBean) {
        UnixOperatingSystemMXBean unixos = (UnixOperatingSystemMXBean) osMbean;
        LOG.info("fdcount after test is: " + unixos.getOpenFileDescriptorCount());
    }

    shutdownAll();
    JMXEnv.tearDown();
}
 
開發者ID:gerritjvv,項目名稱:bigstreams,代碼行數:13,代碼來源:QuorumUtil.java

示例10: 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

示例11: 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

示例12: getFileHandleCount

import com.sun.management.UnixOperatingSystemMXBean; //導入依賴的package包/類
/**
 * Counts how many files are currently opened by this JVM.
 * 
 * @return File handle count
 */
private long getFileHandleCount() {
	OperatingSystemMXBean osStats = ManagementFactory.getOperatingSystemMXBean();
	if (osStats instanceof UnixOperatingSystemMXBean) {
		return ((UnixOperatingSystemMXBean) osStats).getOpenFileDescriptorCount();
	} else {
		throw new RuntimeException("Could not get file handle count");
	}
}
 
開發者ID:gentics,項目名稱:mesh,代碼行數:14,代碼來源:AbstractMeshTest.java

示例13: getOpenFilesAmount

import com.sun.management.UnixOperatingSystemMXBean; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:thelastpickle,項目名稱:cassandra-reaper,代碼行數:12,代碼來源:SegmentRunner.java

示例14: stats_files

import com.sun.management.UnixOperatingSystemMXBean; //導入依賴的package包/類
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() );
	}
}
 
開發者ID:jolie,項目名稱:jolie,代碼行數:10,代碼來源:RuntimeService.java

示例15: FileDescriptorCountHealthChecker

import com.sun.management.UnixOperatingSystemMXBean; //導入依賴的package包/類
public FileDescriptorCountHealthChecker(FileDescriptorCountHealthCheckerConfig config) {
    super(config);
    this.config = config;

    OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
    this.os = operatingSystemMXBean instanceof UnixOperatingSystemMXBean ? (UnixOperatingSystemMXBean) operatingSystemMXBean : null;
}
 
開發者ID:jivesoftware,項目名稱:routing-bird,代碼行數:8,代碼來源:FileDescriptorCountHealthChecker.java


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