Package java.lang.management

Examples of java.lang.management.OperatingSystemMXBean


    info.setIp(ReportUtil.getIp());
    info.setJvmTotalMemory(Runtime.getRuntime().totalMemory());
    info.setJvmFreeMemory(Runtime.getRuntime().freeMemory());
    info.setJvmMaxMemory(Runtime.getRuntime().maxMemory());
   
    OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
    info.setOsName(osmxb.getName());
    info.setOsVersion(osmxb.getVersion());
    info.setSystemLoadAverage(osmxb.getSystemLoadAverage());
   
    ThreadMXBean tmxb = ManagementFactory.getThreadMXBean();
    info.setJvmThreadCount(tmxb.getThreadCount());
    info.setJvmPeakThreadCount(tmxb.getPeakThreadCount());
  }
View Full Code Here


    }

    private static long getOSMemory (String methodName, String warning) {
        long ram = 0;

        OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
        Method m;
        try {
            m = operatingSystemMXBean.getClass().getDeclaredMethod(methodName);
            m.setAccessible(true);
            Object value = m.invoke(operatingSystemMXBean);
            if (value != null) {
                ram = Long.valueOf(value.toString()) / 1024 / 1024;
            } else {
View Full Code Here

   */
  public static SimpleOrderedMap<Object> getSystemInfo() throws Exception
  {
    SimpleOrderedMap<Object> info = new SimpleOrderedMap<Object>();
   
    OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
    info.add( "name", os.getName() );
    info.add( "version", os.getVersion() );
    info.add( "arch", os.getArch() );

    // Java 1.6
    addGetterIfAvaliable( os, "systemLoadAverage", info );

    // com.sun.management.UnixOperatingSystemMXBean
    addGetterIfAvaliable( os, "openFileDescriptorCount", info );
    addGetterIfAvaliable( os, "maxFileDescriptorCount", info );

    // com.sun.management.OperatingSystemMXBean
    addGetterIfAvaliable( os, "committedVirtualMemorySize", info );
    addGetterIfAvaliable( os, "totalPhysicalMemorySize", info );
    addGetterIfAvaliable( os, "totalSwapSpaceSize", info );
    addGetterIfAvaliable( os, "processCpuTime", info );

    try {
      if( !os.getName().toLowerCase(Locale.ENGLISH).startsWith( "windows" ) ) {
        // Try some command line things
        info.add( "uname",  execute( "uname -a" ) );
        info.add( "ulimit", execute( "ulimit -n" ) );
        info.add( "uptime", execute( "uptime" ) );
      }
View Full Code Here

                .isEqualTo(0.1);
    }

    @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);
View Full Code Here

    reader.close();
  }

  public static void setupJvmMetrics() {
    final MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
    final OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();

    Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, SYSTEM, LOAD_AVERAGE), new Gauge<Double>() {
      @Override
      public Double value() {
        return operatingSystemMXBean.getSystemLoadAverage();
      }
    });
    Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, JVM, HEAP_USED), new Gauge<Long>() {
      @Override
      public Long value() {
        MemoryUsage usage = memoryMXBean.getHeapMemoryUsage();
        return usage.getUsed();
      }
    });
    Method processCpuTimeMethod = null;
    for (Method method : operatingSystemMXBean.getClass().getDeclaredMethods()) {
      if (method.getName().equals("getProcessCpuTime")) {
        method.setAccessible(true);
        processCpuTimeMethod = method;
      }
    }
    final double availableProcessors = operatingSystemMXBean.getAvailableProcessors();
    if (processCpuTimeMethod != null) {
      final Method pctm = processCpuTimeMethod;
      Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, JVM, CPU_USED), new Gauge<Double>() {
        private long start = System.nanoTime();
        private long lastCpuTime = getProcessCputTime(pctm, operatingSystemMXBean);
View Full Code Here

  }

  @Override
  public Map<String, String> getRecentHealthReport()
  {
    OperatingSystemMXBean osMxBean = ManagementFactory
        .getOperatingSystemMXBean();
    long freeJvmMemory = Runtime.getRuntime().freeMemory();
    long totalJvmMemory = Runtime.getRuntime().totalMemory();
    int availableCPUs = osMxBean.getAvailableProcessors();
    double avgSystemLoad = osMxBean.getSystemLoadAverage();
    long freePhysicalMemory = Long.MAX_VALUE;

    try
    {
      // if( osMxBean instanceof com.sun.management.OperatingSystemMXBean)
View Full Code Here

        map.put("runtime.totalStartedThreadCount", threadMxBean.getTotalStartedThreadCount());
        map.put("runtime.threadCount", Integer.valueOf(threadMxBean.getThreadCount()).longValue());
        map.put("runtime.peakThreadCount", Integer.valueOf(threadMxBean.getPeakThreadCount()).longValue());
        map.put("runtime.daemonThreadCount", Integer.valueOf(threadMxBean.getDaemonThreadCount()).longValue());

        OperatingSystemMXBean osMxBean = ManagementFactory.getOperatingSystemMXBean();
        map.put("osMemory.freePhysicalMemory", get(osMxBean, "getFreePhysicalMemorySize", 0L));
        map.put("osMemory.committedVirtualMemory", get(osMxBean, "getCommittedVirtualMemorySize", 0L));
        map.put("osMemory.totalPhysicalMemory", get(osMxBean, "getTotalPhysicalMemorySize", 0L));

        map.put("osSwap.freeSwapSpace", get(osMxBean, "getFreeSwapSpaceSize", 0L));
View Full Code Here

  public DefaultHealthReportProvider() {
  }

  @Override
  public Map<String, String> getRecentHealthReport() {
    OperatingSystemMXBean osMxBean = ManagementFactory.getOperatingSystemMXBean();
    long freeJvmMemory = Runtime.getRuntime().freeMemory();
    long totalJvmMemory = Runtime.getRuntime().totalMemory();
    int availableCPUs = osMxBean.getAvailableProcessors();
    double avgSystemLoad = osMxBean.getSystemLoadAverage();
    long freePhysicalMemory = Long.MAX_VALUE;

    try {
      // if( osMxBean instanceof com.sun.management.OperatingSystemMXBean)
      // {
View Full Code Here

    }

    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());
        }
View Full Code Here

    writeJsonObjectToResponse(memStats, request);
  }

  private void processOsStats(DatabusRequest request) throws IOException
  {
    OperatingSystemMXBean osStats = ManagementFactory.getOperatingSystemMXBean();
    writeJsonObjectToResponse(osStats, request);
  }
View Full Code Here

TOP

Related Classes of java.lang.management.OperatingSystemMXBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.