当前位置: 首页>>代码示例>>Java>>正文


Java ManagementFactory.getPlatformMXBean方法代码示例

本文整理汇总了Java中java.lang.management.ManagementFactory.getPlatformMXBean方法的典型用法代码示例。如果您正苦于以下问题:Java ManagementFactory.getPlatformMXBean方法的具体用法?Java ManagementFactory.getPlatformMXBean怎么用?Java ManagementFactory.getPlatformMXBean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.management.ManagementFactory的用法示例。


在下文中一共展示了ManagementFactory.getPlatformMXBean方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
@Override
public void start() throws Exception {
  systemMBean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class);

  // A random identifier
  String pid = UUID.randomUUID().toString();

  // Get the kafka producer config
  JsonObject config = config();

  // Create the producer
  producer = KafkaWriteStream.create(vertx.getDelegate(), config.getMap(), String.class, JsonObject.class);

  // Publish the metircs in Kafka
  vertx.setPeriodic(1000, id -> {
    JsonObject metrics = new JsonObject();
    metrics.put("CPU", systemMBean.getProcessCpuLoad());
    metrics.put("Mem", systemMBean.getTotalPhysicalMemorySize() - systemMBean.getFreePhysicalMemorySize());
    producer.write(new ProducerRecord<>("the_topic", new JsonObject().put(pid, metrics)));
  });
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:22,代码来源:MetricsVerticle.java

示例2: getSystemStats

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
Map<String, Object> getSystemStats() {
    Map<String, Object> stats = new HashMap<>();
    OperatingSystemMXBean osBean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class);
    double cpuUsage = osBean.getProcessCpuLoad() < 0 ? 0 : osBean.getProcessCpuLoad() * 100.0;

    stats.put("javaVersion", System.getProperty("java.version"));
    stats.put("osName", System.getProperty("os.name"));
    stats.put("osArch", System.getProperty("os.arch"));
    stats.put("osVersion", System.getProperty("os.version"));
    stats.put("maxMemory", Runtime.getRuntime().maxMemory());
    stats.put("totalMemory", Runtime.getRuntime().totalMemory());
    stats.put("freeMemory", Runtime.getRuntime().freeMemory());
    stats.put("cores", Long.parseLong(String.valueOf(Runtime.getRuntime().availableProcessors()))); // Is this really necessary?
    stats.put("cpuUsage", Math.min(round(cpuUsage), 100.0));

    return stats;
}
 
开发者ID:MinecraftMarket,项目名称:MinecraftMarket-Plugin,代码行数:18,代码来源:MCMarketStats.java

示例3: main

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static void main(String[] argv) throws Exception {
    PlatformLoggingMXBean mbean =
        ManagementFactory.getPlatformMXBean(PlatformLoggingMXBean.class);
    ObjectName objname = mbean.getObjectName();
    if (!objname.equals(new ObjectName(LogManager.LOGGING_MXBEAN_NAME))) {
        throw new RuntimeException("Invalid ObjectName " + objname);
    }

    // check if the PlatformLoggingMXBean is registered in the platform MBeanServer
    MBeanServer platformMBS = ManagementFactory.getPlatformMBeanServer();
    ObjectName objName = new ObjectName(LogManager.LOGGING_MXBEAN_NAME);

    // We could call mbs.isRegistered(objName) here.
    // Calling getMBeanInfo will throw exception if not found.
    platformMBS.getMBeanInfo(objName);

    if (!platformMBS.isInstanceOf(objName, "java.lang.management.PlatformLoggingMXBean") ||
        !platformMBS.isInstanceOf(objName, "java.util.logging.LoggingMXBean")) {
        throw new RuntimeException(objName + " is of unexpected type");
    }

    // test if PlatformLoggingMXBean works properly in a MBeanServer
    PlatformLoggingMXBeanTest test = new PlatformLoggingMXBeanTest();
    test.runTest(mbean);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:26,代码来源:PlatformLoggingMXBeanTest.java

示例4: getVMOptionAsString

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
protected String getVMOptionAsString() {
    if (WHITE_BOX.isConstantVMFlag(flagName) || WHITE_BOX.isLockedVMFlag(flagName)) {
      // JMM cannot access debug flags in product builds or locked flags,
      // use whitebox methods to get such flags value.
      return asString(getValue());
    }
    HotSpotDiagnosticMXBean diagnostic
            = ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
    VMOption tmp;
    try {
        tmp = diagnostic.getVMOption(flagName);
    } catch (IllegalArgumentException e) {
        tmp = null;
    }
    return tmp == null ? null : tmp.getValue();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:VmFlagTest.java

示例5: main

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static void main(String[] argv) throws Exception {
    PlatformLoggingMXBean mbean =
        ManagementFactory.getPlatformMXBean(PlatformLoggingMXBean.class);
    ObjectName objname = mbean.getObjectName();
    if (!objname.equals(new ObjectName(LogManager.LOGGING_MXBEAN_NAME))) {
        throw new RuntimeException("Invalid ObjectName " + objname);
    }

    // check if the PlatformLoggingMXBean is registered in the platform MBeanServer
    MBeanServer platformMBS = ManagementFactory.getPlatformMBeanServer();
    ObjectName objName = new ObjectName(LogManager.LOGGING_MXBEAN_NAME);

    // We could call mbs.isRegistered(objName) here.
    // Calling getMBeanInfo will throw exception if not found.
    platformMBS.getMBeanInfo(objName);

    if (!platformMBS.isInstanceOf(objName, "java.lang.management.PlatformLoggingMXBean")) {
        throw new RuntimeException(objName + " is of unexpected type");
    }

    // test if PlatformLoggingMXBean works properly in a MBeanServer
    PlatformLoggingMXBeanTest test = new PlatformLoggingMXBeanTest();
    test.runTest(mbean);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:PlatformLoggingMXBeanTest.java

示例6: main

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static void main(String... args) throws Exception {
    MBeanServerConnection msc = ManagementFactory.getPlatformMBeanServer();
    HotSpotDiagnosticMXBean mxbean =
        ManagementFactory.getPlatformMXBean(msc, HotSpotDiagnosticMXBean.class);


    String[] signatures = new String[] {
        String.class.getName()
    };
    Object obj = msc.invoke(mxbean.getObjectName(), "getVMOption",
        new String[] { "PrintVMOptions"}, signatures);

    CompositeData data = (CompositeData)obj;
    validateType(data);

    VMOption option = mxbean.getVMOption("PrintVMOptions");
    VMOption o = VMOption.from(data);
    assertEquals(option, o);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:VMOptionOpenDataTest.java

示例7: main

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    HotSpotDiagnosticMXBean diagnostic =
            ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);

    System.out.println("Max memory= " + MAX_MEMORY + " bytes");

    int obj_size = 0;
    long seconds_to_run = 0;
    if (args.length != 2) {
        throw new RuntimeException("Object size argument must be supplied");
    } else {
        obj_size = Integer.parseInt(args[0]);
        seconds_to_run = Integer.parseInt(args[1]);
    }
    System.out.println("Objects size= " + obj_size + " bytes");
    System.out.println("Seconds to run=" + seconds_to_run);

    int region_size =
        Integer.parseInt(diagnostic.getVMOption("G1HeapRegionSize").getValue());
    if (obj_size < (region_size / 2)) {
        throw new RuntimeException("Object size " + obj_size +
                                   " is not humongous with region size " + region_size);
    }

    ExecutorService executor =
        Executors.newFixedThreadPool(THREAD_COUNT, new NamedThreadFactory());
    System.out.println("Starting " + THREAD_COUNT + " threads");

    for (int i = 0; i < THREAD_COUNT; i++) {
        executor.execute(new Runner(obj_size));
    }

    Thread.sleep(seconds_to_run * 1000);
    executor.shutdownNow();

    if (!executor.awaitTermination(10, TimeUnit.SECONDS)) {
        System.err.println("Thread pool did not terminate after 10 seconds after shutdown");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:40,代码来源:TestGreyReclaimedHumongousObjects.java

示例8: getCompressedClassSpaceSize

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
private static long getCompressedClassSpaceSize() {
  HotSpotDiagnosticMXBean diagnostic =
      ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);

  VMOption option = diagnostic.getVMOption("CompressedClassSpaceSize");
  return Long.parseLong(option.getValue());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:TestUseCompressedOopsErgoTools.java

示例9: getVMOption

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
/**
 * Returns value of VM option.
 *
 * @param name option's name
 * @return value of option or {@code null}, if option doesn't exist
 * @throws NullPointerException if name is null
 */
public static String getVMOption(String name) {
    String result;
    HotSpotDiagnosticMXBean diagnostic
            = ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
    result = diagnostic.getVMOption(name).getValue();
    return result;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:Utils.java

示例10: main

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    mbean =
        ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);

    VMOption option = findPrintGCDetailsOption();
    if (!option.getValue().equalsIgnoreCase(EXPECTED_VALUE)) {
        throw new RuntimeException("Unexpected value: " +
            option.getValue() + " expected: " + EXPECTED_VALUE);
    }
    if (option.getOrigin() != Origin.VM_CREATION) {
        throw new RuntimeException("Unexpected origin: " +
            option.getOrigin() + " expected: VM_CREATION");
    }
    if (!option.isWriteable()) {
        throw new RuntimeException("Expected " + PRINT_GC_DETAILS +
            " to be writeable");
    }

    // set VM option to a new value
    mbean.setVMOption(PRINT_GC_DETAILS, NEW_VALUE);

    option = findPrintGCDetailsOption();
    if (!option.getValue().equalsIgnoreCase(NEW_VALUE)) {
        throw new RuntimeException("Unexpected value: " +
            option.getValue() + " expected: " + NEW_VALUE);
    }
    if (option.getOrigin() != Origin.MANAGEMENT) {
        throw new RuntimeException("Unexpected origin: " +
            option.getOrigin() + " expected: MANAGEMENT");
    }
    VMOption o = mbean.getVMOption(PRINT_GC_DETAILS);
    if (!option.getValue().equals(o.getValue())) {
        throw new RuntimeException("Unmatched value: " +
            option.getValue() + " expected: " + o.getValue());
    }
    if (!option.getValue().equals(o.getValue())) {
        throw new RuntimeException("Unmatched value: " +
            option.getValue() + " expected: " + o.getValue());
    }
    if (option.getOrigin() != o.getOrigin()) {
        throw new RuntimeException("Unmatched origin: " +
            option.getOrigin() + " expected: " + o.getOrigin());
    }
    if (option.isWriteable() != o.isWriteable()) {
        throw new RuntimeException("Unmatched writeable: " +
            option.isWriteable() + " expected: " + o.isWriteable());
    }

    // check if ManagementServer is not writeable
    List<VMOption> options = mbean.getDiagnosticOptions();
    VMOption mgmtServerOption = null;
    for (VMOption o1 : options) {
        if (o1.getName().equals(MANAGEMENT_SERVER)) {
             mgmtServerOption = o1;
             break;
        }
    }
    if (mgmtServerOption != null) {
        throw new RuntimeException(MANAGEMENT_SERVER +
            " is not expected to be writeable");
    }
    mgmtServerOption = mbean.getVMOption(MANAGEMENT_SERVER);
    if (mgmtServerOption == null) {
        throw new RuntimeException(MANAGEMENT_SERVER +
            " should exist.");
    }
    if (mgmtServerOption.getOrigin() != Origin.DEFAULT) {
        throw new RuntimeException(MANAGEMENT_SERVER +
            " should have the default value.");
    }
    if (mgmtServerOption.isWriteable()) {
        throw new RuntimeException(MANAGEMENT_SERVER +
            " is not expected to be writeable");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:76,代码来源:SetVMOption.java

示例11: main

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static void main(String... args) throws Exception {
    if (args.length == 0) {
        // start a process that has options set in a number of different ways

        File flagsFile = File.createTempFile("CheckOriginFlags", null);
        try (PrintWriter pw =
               new PrintWriter(new FileWriter(flagsFile))) {
            pw.println("+PrintSafepointStatistics");
        }

        ProcessBuilder pb = ProcessTools.
            createJavaProcessBuilder(
                "--add-exports", "jdk.attach/sun.tools.attach=ALL-UNNAMED",
                "-XX:+UseConcMarkSweepGC",  // this will cause MaxNewSize to be FLAG_SET_ERGO
                "-XX:+UseCodeAging",
                "-XX:+UseCerealGC",         // Should be ignored.
                "-XX:Flags=" + flagsFile.getAbsolutePath(),
                "-Djdk.attach.allowAttachSelf",
                "-cp", System.getProperty("test.class.path"),
                "CheckOrigin",
                "-runtests");

        Map<String, String> env = pb.environment();
        // "UseCMSGC" should be ignored.
        env.put("_JAVA_OPTIONS", "-XX:+CheckJNICalls -XX:+UseCMSGC");
        // "UseGOneGC" should be ignored.
        env.put("JAVA_TOOL_OPTIONS", "-XX:+IgnoreUnrecognizedVMOptions "
            + "-XX:+PrintVMOptions -XX:+UseGOneGC");

        pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);
        pb.redirectError(ProcessBuilder.Redirect.INHERIT);
        Process p = pb.start();
        int exit = p.waitFor();
        System.out.println("sub process exit == " + exit);
        if (exit != 0) {
            throw new Exception("Unexpected exit code from subprocess == " + exit);
        }
    } else {
        mbean =
            ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);

        // set a few more options
        mbean.setVMOption("HeapDumpOnOutOfMemoryError", "true");
        setOptionUsingAttach("HeapDumpPath", "/a/sample/path");

        // check the origin field for all the options we set

        // Not set, so should be default
        checkOrigin("ManagementServer", Origin.DEFAULT);
        // Set on the command line
        checkOrigin("UseCodeAging", Origin.VM_CREATION);
        // Set in _JAVA_OPTIONS
        checkOrigin("CheckJNICalls", Origin.ENVIRON_VAR);
        // Set in JAVA_TOOL_OPTIONS
        checkOrigin("IgnoreUnrecognizedVMOptions", Origin.ENVIRON_VAR);
        checkOrigin("PrintVMOptions", Origin.ENVIRON_VAR);
        // Set in -XX:Flags file
        checkOrigin("PrintSafepointStatistics", Origin.CONFIG_FILE);
        // Set through j.l.m
        checkOrigin("HeapDumpOnOutOfMemoryError", Origin.MANAGEMENT);
        // Should be set by the VM, when we set UseConcMarkSweepGC
        checkOrigin("MaxNewSize", Origin.ERGONOMIC);
        // Set using attach
        checkOrigin("HeapDumpPath", Origin.ATTACH_ON_DEMAND);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:67,代码来源:CheckOrigin.java

示例12: main

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    mbean =
        ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);

    VMOption option = findHeapDumpOnOomOption();
    if (!option.getValue().equalsIgnoreCase(EXPECTED_VALUE)) {
        throw new RuntimeException("Unexpected value: " +
            option.getValue() + " expected: " + EXPECTED_VALUE);
    }
    if (option.getOrigin() != Origin.VM_CREATION) {
        throw new RuntimeException("Unexpected origin: " +
            option.getOrigin() + " expected: VM_CREATION");
    }
    if (!option.isWriteable()) {
        throw new RuntimeException("Expected " + HEAP_DUMP_ON_OOM +
            " to be writeable");
    }

    // set VM option to a new value
    mbean.setVMOption(HEAP_DUMP_ON_OOM, NEW_VALUE);

    option = findHeapDumpOnOomOption();
    if (!option.getValue().equalsIgnoreCase(NEW_VALUE)) {
        throw new RuntimeException("Unexpected value: " +
            option.getValue() + " expected: " + NEW_VALUE);
    }
    if (option.getOrigin() != Origin.MANAGEMENT) {
        throw new RuntimeException("Unexpected origin: " +
            option.getOrigin() + " expected: MANAGEMENT");
    }
    VMOption o = mbean.getVMOption(HEAP_DUMP_ON_OOM);
    if (!option.getValue().equals(o.getValue())) {
        throw new RuntimeException("Unmatched value: " +
            option.getValue() + " expected: " + o.getValue());
    }
    if (!option.getValue().equals(o.getValue())) {
        throw new RuntimeException("Unmatched value: " +
            option.getValue() + " expected: " + o.getValue());
    }
    if (option.getOrigin() != o.getOrigin()) {
        throw new RuntimeException("Unmatched origin: " +
            option.getOrigin() + " expected: " + o.getOrigin());
    }
    if (option.isWriteable() != o.isWriteable()) {
        throw new RuntimeException("Unmatched writeable: " +
            option.isWriteable() + " expected: " + o.isWriteable());
    }

    // check if ManagementServer is not writeable
    List<VMOption> options = mbean.getDiagnosticOptions();
    VMOption mgmtServerOption = null;
    for (VMOption o1 : options) {
        if (o1.getName().equals(MANAGEMENT_SERVER)) {
             mgmtServerOption = o1;
             break;
        }
    }
    if (mgmtServerOption != null) {
        throw new RuntimeException(MANAGEMENT_SERVER +
            " is not expected to be writeable");
    }
    mgmtServerOption = mbean.getVMOption(MANAGEMENT_SERVER);
    if (mgmtServerOption == null) {
        throw new RuntimeException(MANAGEMENT_SERVER +
            " should exist.");
    }
    if (mgmtServerOption.getOrigin() != Origin.DEFAULT) {
        throw new RuntimeException(MANAGEMENT_SERVER +
            " should have the default value.");
    }
    if (mgmtServerOption.isWriteable()) {
        throw new RuntimeException(MANAGEMENT_SERVER +
            " is not expected to be writeable");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:76,代码来源:SetVMOption.java

示例13: HeapDumpCreator

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
HeapDumpCreator(final Configuration configuration, final CommandExecutor commandExecutor)
    throws Exception {
  this(configuration, initHostName(), ManagementFactory
      .getPlatformMXBean(com.sun.management.HotSpotDiagnosticMXBean.class),
      commandExecutor, Logger.Factory.get(HeapDumpCreator.class));
}
 
开发者ID:SAP,项目名称:java-memory-assistant,代码行数:7,代码来源:HeapDumpCreator.java

示例14: DynamicVMOption

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
/**
 * Creates an instance of DynamicVMOption.
 *
 * @param name the VM option name
 */
public DynamicVMOption(String name) {
    this.name = name;
    mxBean = ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:DynamicVMOption.java


注:本文中的java.lang.management.ManagementFactory.getPlatformMXBean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。