public void register()

in geronimo-metrics-common/src/main/java/org/apache/geronimo/microprofile/metrics/common/BaseMetrics.java [48:176]


    public void register() {
        final RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
        registry.register(Metadata.builder()
                .withName("jvm.uptime")
                .withDisplayName("JVM Uptime")
                .withDescription("Displays the start time of the Java virtual machine in milliseconds." +
                        "This attribute displays the approximate time when the Java virtual machine started.")
                .withType(MetricType.GAUGE)
                .withUnit(MetricUnits.MILLISECONDS)
                .build(), gauge(runtimeMXBean::getUptime));

        final OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
        registry.register(Metadata.builder()
                .withName("cpu.availableProcessors")
                .withDisplayName("Available Processors")
                .withDescription("Displays the number of processors available to the Java virtual machine. " +
                        "This value may change during a particular invocation of the virtual machine.")
                .withType(MetricType.GAUGE).withUnit(MetricUnits.NONE).build(), gauge(operatingSystemMXBean::getAvailableProcessors));

        final ClassLoadingMXBean classLoadingMXBean = ManagementFactory.getClassLoadingMXBean();
        registry.register(Metadata.builder()
                .withName("classloader.unloadedClasses.count")
                .withDisplayName("Current Loaded Class Count")
                .withDescription("Displays the number of classes that are currently loaded in the Java virtual machine.")
                .withType(MetricType.GAUGE)
                .withUnit(MetricUnits.NONE)
                .build(),
                gauge(classLoadingMXBean::getUnloadedClassCount));
        registry.register(Metadata.builder()
                .withName("classloader.unloadedClasses.total")
                .withDisplayName("Current Loaded Class Total")
                .withDescription("Displays the number of classes that are currently loaded in the Java virtual machine.")
                .withType(MetricType.COUNTER)
                .withUnit(MetricUnits.NONE)
                .build(),
                counter(classLoadingMXBean::getUnloadedClassCount));
        registry.register(Metadata.builder()
                .withName("classloader.loadedClasses.count")
                .withDisplayName("Total Loaded Class Count")
                .withDescription("Displays the total number of classes that have been loaded since the Java virtual machine has started execution.")
                .withType(MetricType.GAUGE)
                .withUnit(MetricUnits.NONE)
                .build(),
                gauge(classLoadingMXBean::getTotalLoadedClassCount));
        registry.register(Metadata.builder()
                .withName("classloader.loadedClasses.total")
                .withDisplayName("Total Loaded Class Count")
                .withDescription("Displays the total number of classes that have been loaded since the Java virtual machine has started execution.")
                .withType(MetricType.COUNTER)
                .withUnit(MetricUnits.NONE)
                .build(),
                counter(classLoadingMXBean::getTotalLoadedClassCount));

        final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
        registry.register(Metadata.builder()
                .withName("thread.count")
                .withDisplayName("Thread Count")
                .withDescription("Displays the current number of live threads including both daemon and non-daemon threads")
                .withType(MetricType.GAUGE)
                .withUnit(MetricUnits.NONE)
                .build(),
                gauge(threadMXBean::getThreadCount));
        registry.register(Metadata.builder()
                .withName("thread.daemon.count")
                .withDisplayName("Daemon Thread Count")
                .withDescription("Displays the current number of live daemon threads.")
                .withType(MetricType.GAUGE)
                .withUnit(MetricUnits.NONE)
                .build(),
                gauge(threadMXBean::getDaemonThreadCount));
        registry.register(Metadata.builder()
                .withName("thread.max.count")
                .withDisplayName("Peak Thread Count")
                .withDescription("Displays the peak live thread count since the Java virtual machine started or peak was reset." +
                        "This includes daemon and non-daemon threads.")
                .withType(MetricType.GAUGE)
                .withUnit(MetricUnits.NONE)
                .build(),
                gauge(threadMXBean::getPeakThreadCount));

        final MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
        registry.register(Metadata.builder()
                .withName("memory.usedHeap")
                .withDisplayName("Used Heap Memory")
                .withDescription("Displays the amount of used heap memory in bytes.")
                .withType(MetricType.GAUGE).withUnit(MetricUnits.BYTES).build(), gauge(memoryMXBean.getHeapMemoryUsage()::getUsed));
        registry.register(Metadata.builder()
                .withName("memory.committedHeap")
                .withDisplayName("Committed Heap Memory")
                .withDescription("Displays the amount of memory in bytes that is committed for the Java virtual machine to use. " +
                        "This amount of memory is guaranteed for the Java virtual machine to use.")
                .withType(MetricType.GAUGE).withUnit(MetricUnits.BYTES).build(), gauge(memoryMXBean.getHeapMemoryUsage()::getCommitted));
        registry.register(Metadata.builder()
                .withName("memory.maxHeap")
                .withDisplayName("Max Heap Memory")
                .withDescription("Displays the maximum amount of heap memory in bytes that can be used for memory management. " +
                        "This attribute displays -1 if the maximum heap memory size is undefined. " +
                        "This amount of memory is not guaranteed to be available for memory management if it is greater than " +
                        "the amount of committed memory. The Java virtual machine may fail to allocate memory even " +
                        "if the amount of used memory does not exceed this maximum size.")
                .withType(MetricType.GAUGE).withUnit(MetricUnits.BYTES).build(), gauge(memoryMXBean.getHeapMemoryUsage()::getMax));

        final List<GarbageCollectorMXBean> garbageCollectorMXBeans = ManagementFactory.getGarbageCollectorMXBeans();
        garbageCollectorMXBeans.forEach(garbageCollectorMXBean -> {
            registry.register(Metadata.builder()
                    .withName("gc.total")
                    .withDisplayName("Garbage Collection Count")
                    .withDescription("Displays the total number of collections that have occurred." +
                            "This attribute lists -1 if the collection count is undefined for this collector.")
                    .withType(MetricType.COUNTER)
                    .withUnit(MetricUnits.NONE)
                    .build(),
                    counter(garbageCollectorMXBean::getCollectionCount),
                    new Tag("name", garbageCollectorMXBean.getName()));
            registry.register(Metadata.builder()
                    .withName("gc.time")
                    .withDisplayName("Garbage Collection Time")
                    .withDescription("Displays the approximate accumulated collection elapsed time in milliseconds." +
                            "This attribute displays -1 if the collection elapsed time is undefined for this collector." +
                            "The Java virtual machine implementation may use a high resolution timer to measure the elapsed time." +
                            "This attribute may display the same value even if the collection count has been incremented if" +
                            "the collection elapsed time is very short.")
                    .withType(MetricType.GAUGE)
                    .withUnit(MetricUnits.MILLISECONDS)
                    .build(),
                    gauge(garbageCollectorMXBean::getCollectionTime),
                    new Tag("name", garbageCollectorMXBean.getName()));
        });
    }