CLOVERšŸ€

That was when it all began.

Eclipse MicroProfile Metrics悒試恙

恓悌ćÆ态ćŖć«ć‚’ć—ćŸćć¦ę›øć„ćŸć‚‚ć®ļ¼Ÿ

꜀čæ‘恓恔悉恮ć‚Øćƒ³ćƒˆćƒŖ悒ę›øć„ćŸć®ć§ć™ćŒć€ć“ć®ę™‚ćÆMicroProfile Metricsć‚’ć¾ć£ćŸćēŸ„ć‚Šć¾ć›ć‚“ć§ć—ćŸć€‚

WildFlyのMetricsサブシステム、MicroProfile Metricsサブシステムを試してみる - CLOVER🍀

ć›ć£ć‹ćć®ę©Ÿä¼šćŖ恮恧态MicroProfile Metrics悂試恗恦ćæ悈恆恋ćŖćØ怂

Eclipse MicroProfile Metrics

Eclipse MicroProfile MetricsćØć„ć†ć®ćŒę­£ć—ć„åē§°ćæ恟恄恧恙恭怂

Project - MicroProfile

GitHub - eclipse/microprofile-metrics: microprofile-metrics

Eclipse MicroProfile恫ęŗ–ę‹ ć™ć‚‹ć€å„ćƒ—ćƒ­ć‚»ć‚¹ć®ćƒ”惈ćƒŖć‚Æć‚¹ć‚Øćƒ³ćƒ‰ćƒć‚¤ćƒ³ćƒˆćŠć‚ˆć³ćƒ”ćƒˆćƒŖć‚Æć‚¹ć®čæ½åŠ ć‚’č”Œć†ę©Ÿčƒ½ć§ć™ć€‚
ē¾åœØć®ćƒćƒ¼ć‚øćƒ§ćƒ³ćÆ3.0恧恙怂

ä»•ę§˜ę›øćÆGitHubć‹ć‚‰ćƒ€ć‚¦ćƒ³ćƒ­ćƒ¼ćƒ‰ć—ć¦ć‚‚ć„ć„ć®ć§ć™ćŒ

Release MicroProfile Metrics 3.0 · eclipse/microprofile-metrics · GitHub

ć“ć”ć‚‰ć‹ć‚‰ćƒ€ć‚¦ćƒ³ćƒ­ćƒ¼ćƒ‰ć—ć¦ć‚‚ć„ć„ć§ć—ć‚‡ć†ć€‚

https://download.eclipse.org/microprofile/microprofile-metrics-3.0/

JavadocćÆ恓恔悉恧恙怂

MicroProfile Metrics API

恔ćŖćæć«ć§ć™ćŒć€‚Eclipse MicroProfile Metrics 4.x恧ćÆMicrometer悒čŖæęŸ»ć—ćŸēµęžœćØć—ć¦ć€å¤‰ę›“ćŒč”Œć‚ć‚Œć‚‹ć‚ˆć†ć§ć™ć€‚
4.x恧3.0ć‹ć‚‰ć©ć®ćć‚‰ć„äŗ’ę›ę€§ćŒē¶­ęŒć•ć‚Œć‚‹ć‹ćÆęœŖå®šć®ć‚ˆć†ć§ć™ć€‚

Future Direction

ć¾ć‚ć€ćć‚ŒćÆ恝悌ćØć—ć¦ä»Šå›žćÆę‰±ć£ć¦ćæć¾ć™ć€‚

Eclipse MicroProfile Metricsć®å®Ÿč£…ćÆ态恓恔悉恫äø€č¦§ćŒć‚ć‚Šć¾ć™ć€‚

MicroProfile/Implementation / MP Metrics implementations

  • OpenLiberty
  • WebSphere Liberty
  • SmallRye Metrics
  • Payara Serverļ¼Payara Micro
  • Helidon
  • Geronimo Metrics
  • KumuluzEE Metrics

ć‚ćŸć‚Šć§ć™ć­ć€‚ć‚‚ć£ćØ悂3.0ć¾ć§å®Ÿč£…ć—ć¦ć„ć‚‹ć®ćÆ态恋ćŖć‚Šé™ć‚‰ć‚Œć¦ć„ć¾ć™ćŒć€‚

ć‚‚ć†å°‘ć—č©³ē“°ć‚’

Eclipse MicroProfile MetricsćŒć©ć†ć„ć†ć‚‚ć®ć‹ć‚’ć€ć‚‚ć†å°‘ć—č¦‹ć¦ćæć¾ć—ć‚‡ć†ć€‚

Metrics for Eclipse MicroProfile / Architecture

惔惈ćƒŖć‚Æć‚¹ćØ恗恦态ꬔ恮3ēØ®é”žć®ć‚µćƒ–ćƒŖć‚½ćƒ¼ć‚¹ļ¼ˆć‚¹ć‚³ćƒ¼ćƒ—ļ¼‰ćŒå®šē¾©ć•ć‚Œć¦ć„ć¾ć™ć€‚

  • Base metrics ā€¦ ć™ć¹ć¦ć®MicroProfileć®ćƒ™ćƒ³ćƒ€ćƒ¼ćŒęä¾›ć™ć¹ććƒ”ćƒˆćƒŖć‚Æć‚¹
  • Vendor specific metrics ā€¦ ćƒ™ćƒ³ćƒ€ćƒ¼å›ŗęœ‰ć®ćƒ”ćƒˆćƒŖć‚Æć‚¹
  • Application metrics ā€¦ ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³å›ŗęœ‰ć®ćƒ”ćƒˆćƒŖć‚Æć‚¹

恓悌悉ćÆ态RESTć‚Øćƒ³ćƒ‰ćƒć‚¤ćƒ³ćƒˆć§å…¬é–‹ć•ć‚Œć¾ć™ć€‚ćƒ•ć‚©ćƒ¼ćƒžćƒƒćƒˆćÆJSONć¾ćŸćÆOpenMetrics恧恙怂

Base metricsćÆ/metrics/basećØć„ć†ćƒ‘ć‚¹ć§å…¬é–‹ć•ć‚Œć€ć“ć”ć‚‰ć«ćƒŖć‚¹ćƒˆćŒć‚ć‚Šć¾ć™ć€‚

Required Metrics

ćƒ’ćƒ¼ćƒ—ć‚„ć‚¹ćƒ¬ćƒƒćƒ‰ć€OSć®ęƒ…å ±ćŖ恩JavaVMć«é–¢ć™ć‚‹ć‚‚ć®ćŒäø¦ć‚“ć§ć„ć¾ć™ć€‚ć‚Ŗćƒ—ć‚·ćƒ§ćƒ³ćØć—ć¦ę‰±ć‚ć‚Œć¦ć„ć‚‹ć‚‚ć®ć‚‚ć‚ć‚Šć¾ć™ć­ć€‚
ē•°ćŖ悋Eclipse MicroProfile Metricså®Ÿč£…ć§ē§»ę¤åÆčƒ½ć§ć‚ć‚‹ć“ćØ悒ē›®ēš„ć«ć—ćŸć‚¹ć‚³ćƒ¼ćƒ—ć§ć™ć­ć€‚

Vendor specific metricsćÆ/metrics/vendorćØć„ć†ćƒ‘ć‚¹ć§å…¬é–‹ć•ć‚Œć€ćƒ™ćƒ³ćƒ€ćƒ¼ćŒå›ŗęœ‰ć®ćƒ”ćƒˆćƒŖć‚Æć‚¹ć‚’ęä¾›ć—ć¾ć™ć€‚
ē•°ćŖ悋Eclipse MicroProfile Metricså®Ÿč£…ć®é–“ć§ē§»ę¤åÆčƒ½ć§ć‚ć‚‹ć“ćØćÆęƒ³å®šć•ć‚Œć¦ć„ć¾ć›ć‚“ć€‚

Application metricsćÆ/metrics/applicationćØć„ć†ćƒ‘ć‚¹ć§å…¬é–‹ć•ć‚Œć€Eclipse MicroProfile Metrics恮API悒ä½æć£ć¦ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ćŒ
å®Ÿč£…ć—ć¾ć™ć€‚

Application Metrics Programming Model

ć“ć®ć‚¹ć‚³ćƒ¼ćƒ—ć®ćƒ”ćƒˆćƒŖć‚Æć‚¹ćÆ态Eclipse MicroProfile Metricsä»•ę§˜ć«å‰‡ć£ć¦ä½œęˆć—ć¦ć„ć‚Œć°ć€ē•°ćŖć‚‹ćƒ™ćƒ³ćƒ€ćƒ¼ļ¼ˆć‚µćƒ¼ćƒćƒ¼ļ¼‰ć«
ē§»ć—ć¦ć‚‚åŒć˜ćƒ”惈ćƒŖć‚Æć‚¹ć‚’å…¬é–‹ć§ćć¾ć™ć€‚

惔惈ćƒŖć‚Æć‚¹ć«ćÆ态ć‚æ悰ćØ惔ć‚æćƒ‡ćƒ¼ć‚æćŒć‚ć‚Šć¾ć™ć€‚

ć‚æ悰ćÆć€ćƒ©ćƒ™ćƒ«ćØ悂čØ€ć„ć€ćƒ”ćƒˆćƒŖć‚Æć‚¹ć«ä»˜äøŽć•ć‚Œć¾ć™ć€‚

惔ć‚æćƒ‡ćƒ¼ć‚æćÆć€ćƒ”ćƒˆćƒŖć‚Æć‚¹ć®åå‰ć‚„å˜ä½ć€ēخ锞ļ¼ˆCounter态Gauge态Meter态Histogram态TimerćŖ恩ļ¼‰ć€čŖ¬ę˜ŽćŖ恩恧恙怂

惔惈ćƒŖć‚Æć‚¹ć‚„ćƒ”ć‚æćƒ‡ćƒ¼ć‚æć®ęƒ…å ±ćÆMetricRegistry恫äæå­˜ć•ć‚Œć€å„ć‚¹ć‚³ćƒ¼ćƒ—ć”ćØć«ć²ćØ恤恮MetricRegistryć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ćŒ
ć‚ć‚Šć¾ć™ć€‚

Metric Registry

惔惈ćƒŖć‚Æć‚¹ćŒå…¬é–‹ć•ć‚Œć‚‹RESTć‚Øćƒ³ćƒ‰ćƒć‚¤ćƒ³ćƒˆé–¢ć™ć‚‹ęƒ…å ±ćÆ态恓恔悉恧恙怂

Exposing metrics via REST API

ćØ态ꦂ要ćÆć“ć‚Œćć‚‰ć„ć«ć—ć¦ć€å®Ÿéš›ć«Eclipse MicroProfile Metrics悒ä½æć£ć¦ćæ恟恄ćØę€ć„ć¾ć™ć€‚

SmallRye Metrics

今回ćÆEclipse MicroProfile Metricsć®å®Ÿč£…ćØ恗恦态SmallRye Metrics悒ä½æć„ć¾ć™ć€‚

SmallRye

GitHub - smallrye/smallrye-metrics

ćƒ‰ć‚­ćƒ„ćƒ”ćƒ³ćƒˆćÆ态恓恔悉怂

SmallRye Metrics Documentation :: SmallRye documentation

SmallRye Metrics 3.0ćÆ态Eclipse MicroProfile Metrics 3.0ć®å®Ÿč£…ć®ć‚ˆć†ć§ć™ć€‚
Quarkus悄WildFly恫ēµ„ćæč¾¼ć¾ć‚Œć¦ć„ć¾ć™ć€‚

ćØć„ć†ć‚ć‘ć§ć€ä»Šå›žćÆWildFly恧SmalleRye Metrics悒ä½æć£ć¦ćæć¾ć—ć‚‡ć†ć€‚

ć„ćć¤ć‹ę‹”å¼µę©Ÿčƒ½ć‚„å›ŗęœ‰ć®ęƒ…å ±ćŒć‚ć‚‹ć®ć§ć™ćŒć€‚

JAX-RSć«é–¢ć™ć‚‹ćƒ”ćƒˆćƒŖć‚Æć‚¹ć®č©±ćÆć€ä»Šå›žćÆč«¦ć‚ć¾ć—ćŸā€¦ć€‚

ē’°å¢ƒ

ä»Šå›žć®ē’°å¢ƒćÆ态恓恔悉恧恙怂

$ java --version
openjdk 11.0.11 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)


$ mvn --version
Apache Maven 3.8.2 (ea98e05a04480131370aa0c110b8c54cf726c06f)
Maven home: $HOME/.sdkman/candidates/maven/current
Java version: 11.0.11, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: ja_JP, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-81-generic", arch: "amd64", family: "unix"

WildFlyćÆ态24.0.1.Final悒ä½æć„ć¾ć™ć€‚

ęŗ–å‚™

Mavenć§ć®ćƒ—ćƒ­ć‚ø悧ć‚Æćƒˆå®šē¾©ćÆ态恓悓ćŖę„Ÿć˜ć«ć—ć¾ć—ćŸć€‚

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.littlewings</groupId>
    <artifactId>microprofile-metrics-example</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </properties>

    <dependencies>
        <dependency>
            <groupId>jakarta.platform</groupId>
            <artifactId>jakarta.jakartaee-web-api</artifactId>
            <version>8.0.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.eclipse.microprofile.metrics</groupId>
            <artifactId>microprofile-metrics-api</artifactId>
            <version>3.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>${project.artifactId}</finalName>
    </build>
</project>

Eclipse MicroProfile Metrics恮API悒ä½æ恆恫ćÆ态microprofile-metrics-apić‚’ä¾å­˜é–¢äæ‚恫čæ½åŠ ć—ć¾ć™ć€‚

        <dependency>
            <groupId>org.eclipse.microprofile.metrics</groupId>
            <artifactId>microprofile-metrics-api</artifactId>
            <version>3.0</version>
            <scope>provided</scope>
        </dependency>

WARćƒ•ć‚”ć‚¤ćƒ«ć®åå‰ćÆ态microprofile-metrics-example.warćØć—ć¾ć™ć€‚

ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ćÆ态JAX-RS悒ä½æć£ć¦ę›ø恏恓ćØć«ć—ć¾ć—ć‚‡ć†ć€‚JAX-RSęœ‰åŠ¹åŒ–ć®ć‚Æćƒ©ć‚¹ć‚’ä½œęˆć—ć¦ćŠćć¾ć™ć€‚

src/main/java/org/littlewings/microprofile/metrics/JaxrsActivator.java

package org.littlewings.microprofile.metrics;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("")
public class JaxrsActivator extends Application {
}

WildFlyć®ćƒ€ć‚¦ćƒ³ćƒ­ćƒ¼ćƒ‰ć€‚

$ curl -OL https://download.jboss.org/wildfly/24.0.1.Final/wildfly-24.0.1.Final.zip
$ unzip wildfly-24.0.1.Final.zip
$ cd wildfly-24.0.1.Final

Eclipse MicroProfile悒ä½æ恆恮恧态čØ­å®šćƒ•ć‚”ć‚¤ćƒ«ćÆstandalone-microprofile.xmlć‚’ęŒ‡å®šć—ć¦čµ·å‹•ć—ć¾ć™ć€‚

$ bin/standalone.sh -c standalone-microprofile.xml -Dwildfly.statistics-enabled=true

WildFlyč‡Ŗčŗ«ć®ćƒ”惈ćƒŖć‚Æć‚¹ć‚‚å–å¾—ć§ćć‚‹ć‚ˆć†ć«ć€-Dwildfly.statistics-enabled=trueć‚‚ęŒ‡å®šć—ć¦ćŠćć¾ć—ć‚‡ć†ć€‚

ē®”ē†CLIć‚‚čµ·å‹•ć—ć¦ćŠćć¾ć™ć€‚

$ bin/jboss-cli.sh -c
[standalone@localhost:9990 /] 

RESTć‚Øćƒ³ćƒ‰ćƒć‚¤ćƒ³ćƒˆć§ć€WildFly恮惔惈ćƒŖć‚Æć‚¹ć‚’å–å¾—ć—ć¦ćæ悋

čµ·å‹•ć—ćŸēŠ¶ę…‹ć®WildFly恮惔惈ćƒŖć‚Æć‚¹ć‚’å–å¾—ć—ć¦ćæć¾ć—ć‚‡ć†ć€‚

Exposing metrics via REST API

WildFlyć®å “åˆć€9990ćƒćƒ¼ćƒˆć§ć‚¢ć‚Æć‚»ć‚¹ć—ć¾ć™ć€‚

/metrics恧态å…Øć‚¹ć‚³ćƒ¼ćƒ—ć®ćƒ”ćƒˆćƒŖć‚Æć‚¹ć‚’å–å¾—ć§ćć¾ć™ć€‚

$ curl -s localhost:9990/metrics | grep -v '^#' | perl -wp -e 's!^(.+?_.+?)_.+!$1!' | sort | uniq -c 
      3 base_classloader
      4 base_cpu
      4 base_gc
      1 base_jvm
      6 base_memory
      3 base_thread
      2 vendor_BufferPool
     16 vendor_memoryPool
     60 wildfly_datasources
     14 wildfly_ee
      7 wildfly_io
     17 wildfly_jca
     12 wildfly_messaging
      1 wildfly_request
     11 wildfly_transactions
     12 wildfly_undertow

/metrics/basećØ恙悋恓ćØ恧态Base metrics恫ēµžć‚‹ć“ćØćŒć§ćć¾ć™ć€‚

$ curl -s localhost:9990/metrics/base | grep -v '^#' | perl -wp -e 's!^(.+?_.+?)_.+!$1!' | sort | uniq -c 
      3 base_classloader
      4 base_cpu
      4 base_gc
      1 base_jvm
      6 base_memory
      3 base_thread

/metrics/vendor恧态Vendor specific metrics恧恙怂

$ curl -s localhost:9990/metrics/vendor | grep -v '^#' | perl -wp -e 's!^(.+?_.+?)_.+!$1!' | sort | uniq -c 
      2 vendor_BufferPool
     16 vendor_memoryPool
     60 wildfly_datasources
     14 wildfly_ee
      7 wildfly_io
     17 wildfly_jca
     12 wildfly_messaging
      1 wildfly_request
     11 wildfly_transactions
     12 wildfly_undertow

Application metricsćÆć€ć¾ć ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ćŒē™»éŒ²ć•ć‚Œć¦ć„ćŖć„ć®ć§å­˜åœØć—ć¾ć›ć‚“ć€‚

$ curl -s localhost:9990/metrics/application | grep -v '^#' | perl -wp -e 's!^(.+?_.+?)_.+!$1!' | sort | uniq -c 

恓悓ćŖꄟ恘恧态/metrics/[ć‚¹ć‚³ćƒ¼ćƒ—]ć§å–å¾—ć™ć‚‹ćƒ”ćƒˆćƒŖć‚Æć‚¹ć®ć‚¹ć‚³ćƒ¼ćƒ—ć‚’ēµžć‚‹ć“ćØćŒć§ćć¾ć™ć€‚

恕悉恫/metrics/[ć‚¹ć‚³ćƒ¼ćƒ—]/[惔惈ćƒŖć‚Æć‚¹å]恧惔惈ćƒŖć‚Æć‚¹ć‚’ēµžć£ć¦å–å¾—ć™ć‚‹ć“ćØć‚‚ć§ćć¾ć™ć€‚

$ curl localhost:9990/metrics/vendor/wildfly_io_io_thread_count
# HELP wildfly_io_io_thread_count I/O thread count
# TYPE wildfly_io_io_thread_count gauge
wildfly_io_io_thread_count{worker="default",microprofile_scope="vendor"} 16.0

惔惈ćƒŖć‚Æć‚¹ć®ēخ锞

ćƒ—ćƒ­ć‚°ćƒ©ćƒ ć‚’ę›øćå‰ć«ć€å…ˆć«ćƒ”ćƒˆćƒŖć‚Æć‚¹ć®ēØ®é”žć‚’č¦‹ć¦ćŠć„ćŸę–¹ćŒč‰Æ恕恝恆恧恙怂

ćØ恄恆恋态恄恍ćŖ悊ę›øćå§‹ć‚ć¦é€²ć‚ć¦ćæ恟悉态č‡Ŗåˆ†ćŒå›°ć‚Šć¾ć—ćŸā€¦ć€‚

  • Counter ā€¦ 単čŖæć«å¢—åŠ ć™ć‚‹ę•°å€¤ļ¼ˆlongļ¼‰
  • ConcurrentGause ā€¦ 増ęø›ć™ć‚‹ę•°å€¤ļ¼ˆlongļ¼‰ć€‚ē¾åœØć®ć‚«ć‚¦ćƒ³ćƒˆć€å‰ć«å®Œäŗ†ć—ćŸ1åˆ†ć®é–“ć®ęœ€å¤§å€¤ć€ęœ€å°å€¤ć®3ć¤ć®å€¤ćŒå…¬é–‹ć•ć‚Œć‚‹
  • Gauge ā€¦ CPU恮ęø©åŗ¦ć‚„ćƒ‡ć‚£ć‚¹ć‚Æä½æē”ØēŽ‡ćŖć©ć€ć‚µćƒ³ćƒ—ćƒŖćƒ³ć‚°ć•ć‚Œć‚‹ćƒ”ćƒˆćƒŖć‚Æć‚¹
    • Gauge恫恤恄恦ćÆć€ćƒ”ćƒˆćƒŖć‚Æć‚¹å–å¾—ę™‚ć«Gauge#getValueć®å‘¼ć³å‡ŗć—ćŒč”Œć‚ć‚Œć‚‹
    • Gauge JSON Format
  • Meter ā€¦ å¹³å‡ć‚¹ćƒ«ćƒ¼ćƒ—ćƒƒćƒˆć€1åˆ†ć€5åˆ†ć€15åˆ†ć®ęŒ‡ę•°åŠ é‡ē§»å‹•å¹³å‡ć‚¹ćƒ«ćƒ¼ćƒ—ćƒƒćƒˆć‚’čæ½č·”恙悋
  • Histogram ā€¦ 値ļ¼ˆlongļ¼‰ć®åˆ†åøƒć‚’č؈ē®—恙悋
  • Timer ā€¦ Ꙃ間悒集čØˆć—ć€ęœŸé–“ć®ēµ±č؈ćØć‚¹ćƒ«ćƒ¼ćƒ—ćƒƒćƒˆć®ēµ±čØˆć‚’ęä¾›ć™ć‚‹
    • Duration悄Callable态Runnable态Context恧čؘ録
  • SimpleTimer ā€¦ Timerć®č»½é‡ē‰ˆ
    • ēµŒéŽę™‚é–“ć€å‘¼ć³å‡ŗć—ć‚«ć‚¦ćƒ³ćƒˆć€å‰ć«å®Œäŗ†ć—ćŸ1åˆ†é–“ć®ęœ€å¤§ć€ęœ€å°ć‚’čؘ録
    • Prometheus恧ä½æć†å “åˆć€Timer悒ä½æć†ę–¹ćŒč‰Æ恄

恩悓ćŖ惔惈ćƒŖć‚Æć‚¹ć«ćŖ悋恮恋ćÆ态RESTć‚Øćƒ³ćƒ‰ćƒć‚¤ćƒ³ćƒˆć®å„ćƒ”ćƒˆćƒŖć‚Æć‚¹ć®čØ˜č¼‰ć‚’č¦‹ćŸę–¹ćŒć‚ć‹ć‚Šć‚„ć™ć„ć§ć—ć‚‡ć†ć­ć€‚

Exposing metrics via REST API

ć¾ćŸć€Histgramä»„å¤–ć®ćƒ”ćƒˆćƒŖć‚Æć‚¹ćÆć€ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć§ć®čØ˜éŒ²ćŒåÆčƒ½ć§ć™ć€‚

Annotations

ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć§ćƒ”ćƒˆćƒŖć‚Æć‚¹ć‚’čØ˜éŒ²ć™ć‚‹

恧ćÆć€ć¾ćšćÆć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’ä½æć£ć¦ćƒ”ćƒˆćƒŖć‚Æć‚¹ć‚’čØ˜éŒ²ć—ć¦ćæć¾ć—ć‚‡ć†ć€‚

恓恔悉悒見ćŖćŒć‚‰ä½œęˆć—ć¦ć„ćć¾ć™ć€‚

Annotations

雛形ćØćŖ悋JAX-RSćƒŖć‚½ćƒ¼ć‚¹ć‚Æćƒ©ć‚¹ć‚’ē”Øꄏ怂

src/main/java/org/littlewings/microprofile/metrics/SimpleAnnotatedResource.java

package org.littlewings.microprofile.metrics;

import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.eclipse.microprofile.metrics.annotation.ConcurrentGauge;
import org.eclipse.microprofile.metrics.annotation.Counted;
import org.eclipse.microprofile.metrics.annotation.SimplyTimed;
import org.eclipse.microprofile.metrics.annotation.Timed;

@Path("annotated")
public class SimpleAnnotatedResource {

    // ć“ć“ć«ć€ćƒ”ćƒˆćƒŖć‚Æć‚¹ć‚’čØ˜éŒ²ć™ć‚‹ć‚³ćƒ¼ćƒ‰ć‚’ę›ø恏

}

ć“ć”ć‚‰ć«ć€ćƒ”ćƒˆćƒŖć‚Æć‚¹ć‚’čØ˜éŒ²ć™ć‚‹ć‚³ćƒ¼ćƒ‰ć‚’åŸ‹ć‚č¾¼ć‚“ć§ć„ćć¾ć™ć€‚

Counter metrics悒čØ˜éŒ²ć™ć‚‹ć€@Countedć€‚å±žę€§ćÆnameć ć‘ć‚’ęŒ‡å®šć—ć¦ćæć¾ć—ćŸć€‚

    @GET
    @Path("count-hello-world")
    @Produces(MediaType.TEXT_PLAIN)
    @Counted(name = "hello_world_call_count")
    public String countHelloWorld() {
        return "Hello World!!";
    }

恓恔悉恧恙恭怂

    @Counted(name = "hello_world_call_count")

ć“ć‚Œć§ć€ć“ć®ćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ć®å‘¼ć³å‡ŗć—å›žę•°ćŒćƒ”ćƒˆćƒŖć‚Æć‚¹ćØ恗恦čØ˜éŒ²ć•ć‚Œć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć™ć€‚

ćƒ‘ćƒƒć‚±ćƒ¼ć‚øćƒ³ć‚°ć—ć¦

$ mvn package

惇惗惭悤怂

[standalone@localhost:9990 /] deploy /path/to/target/microprofile-metrics-example.war

仄降ćÆć€ć“ć®ę“ä½œć‚’ēœē•„ć—ć¾ć™ļ¼ˆčØ˜č¼‰ć—ćŸć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰ćŒå«ć¾ć‚ŒćŸWebć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ćŒćƒ‡ćƒ—ćƒ­ć‚¤ć•ć‚ŒćŸć‚‚ć®ćØ恗恦
č©±ć‚’é€²ć‚ć¾ć™ļ¼‰ć€‚

恓恮Ꙃē‚¹ć§ć€å®ŸćÆ惔惈ćƒŖć‚Æć‚¹ćÆč¦‹ć‚‰ć‚Œć‚‹ć‚ˆć†ć«ćŖć£ć¦ć„ć¾ć™ć€‚

$ curl localhost:9990/metrics/application
# TYPE application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_hello_world_call_count_total counter
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_hello_world_call_count_total 0.0

ć‚¢ć‚Æć‚»ć‚¹ć—ć¦ćæć¾ć—ć‚‡ć†ć€‚

$ curl localhost:8080/microprofile-metrics-example/annotated/count-hello-world
Hello World!!


$ curl localhost:8080/microprofile-metrics-example/annotated/count-hello-world
Hello World!!

恓悓ćŖę„Ÿć˜ć§ć‚«ć‚¦ćƒ³ćƒˆć‚¢ćƒƒćƒ—ć•ć‚Œć¦ć„ćć¾ć™ć€‚

$ curl -s localhost:9990/metrics/application
# TYPE application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_hello_world_call_count_total counter
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_hello_world_call_count_total 2.0

ꬔćÆć€ć‚‚ć†å°‘ć—å±žę€§ć‚’ęŒ‡å®šć—ć¦ćæć¾ć—ć‚‡ć†ć€‚å±žę€§ć‚’ęŒ‡å®šć™ć‚‹ćØ恄恆恓ćØćÆć€ćƒ”ć‚æćƒ‡ćƒ¼ć‚æć‚’ęŒ‡å®šć™ć‚‹ć“ćØ恫ćŖć‚Šć¾ć™ć€‚

Metadata

    @GET
    @Path("count-yeah")
    @Produces(MediaType.TEXT_PLAIN)
    @Counted(name = "yeah_call_count", absolute = true, displayName = "yeah call count metrics", description = "yeah call count description")
    public String countYeah() {
        return "Yeah!!";
    }

ć‚¢ć‚Æć‚»ć‚¹ć—ć¦ćæć¾ć™ć€‚

$ curl localhost:8080/microprofile-metrics-example/annotated/count-yeah
Yeah!!


$ curl localhost:8080/microprofile-metrics-example/annotated/count-yeah
Yeah!!

惔惈ćƒŖć‚Æć‚¹ćÆ态恓悓ćŖę„Ÿć˜ć«ćŖć‚Šć¾ć™ć€‚

# HELP application_yeah_call_count_total yeah call count description
# TYPE application_yeah_call_count_total counter
application_yeah_call_count_total 2.0

descriptionćÆ态HELP恫ä½æć‚ć‚Œć¦ć„ć‚‹ć“ćØ恌ē¢ŗčŖć§ćć¾ć™ć€‚

å…ˆć»ć©ćØęÆ”ć¹ć‚‹ćØć€ćƒ”ćƒˆćƒŖć‚Æć‚¹ć®åå‰ćŒć‚„ćŸć‚‰ēŸ­ć„ć§ć™ć­ć€‚ć“ć‚ŒćÆabsolute悒truećØ恗恟恋悉恧恙怂

absolute悒falseļ¼ˆćƒ‡ćƒ•ć‚©ćƒ«ćƒˆļ¼‰ćØ恙悋ćØ态ć‚Æćƒ©ć‚¹ć®FQCNćŒćƒ”ćƒˆćƒŖć‚Æć‚¹ć®åå‰ć«å«ć¾ć‚Œć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć™ć€‚

ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’ä½æć£ć¦ćƒ”ćƒˆćƒŖć‚Æć‚¹ć‚’čØ˜éŒ²ć™ć‚‹å “åˆć®ć€ćƒ”ćƒˆćƒŖć‚Æć‚¹åć«é–¢ć™ć‚‹č¦å‰‡ćÆ恓恔悉恫čØ˜č¼‰ć•ć‚Œć¦ć„ć¾ć™ć€‚

Annotated Naming Convention

惔惈ćƒŖć‚Æć‚¹åć«ćÆć‚¹ć‚³ćƒ¼ćƒ—ćŠć‚ˆć³ćƒ”ćƒˆćƒŖć‚Æć‚¹ć«ć‚ˆć£ć¦ćÆć‚µćƒ•ć‚£ćƒƒć‚Æć‚¹ćŒä»˜äøŽć•ć‚Œć‚‹ć®ć§ć€ćć‚Œćžć‚Œć®ćƒ”惈ćƒŖć‚Æć‚¹ć®
ęƒ…å ±ć‚’å‚ē…§ć—ć¾ć—ć‚‡ć†ć€‚

ćØ恓悍恧态displayNameć®ęƒ…å ±ćÆć©ć“ć«ć„ć£ćŸć®ć§ć—ć‚‡ć†ć‹ļ¼Ÿć“ć‚ŒćÆ态OPTIONS恧ē¢ŗčŖć§ćć¾ć™ć€‚

$ curl -XOPTIONS -H 'Accept: application/json' localhost:9990/metrics/application

{
    "org.littlewings.microprofile.metrics.SimpleAnnotatedResource.hello_world_call_count": {
        "unit": "none",
        "type": "counter",
        "displayName": "org.littlewings.microprofile.metrics.SimpleAnnotatedResource.hello_world_call_count",
        "tags": [
            [
            ]
        ]
    },
    "yeah_call_count": {
        "unit": "none",
        "type": "counter",
        "description": "yeah call count description",
        "displayName": "yeah call count metrics",
        "tags": [
            [
            ]
        ]
    }
}

ć‚­ćƒ¼ćŒćƒ”ćƒˆćƒŖć‚Æć‚¹åć«ćŖć£ć¦ć„ć‚‹ć“ćØ恫ę³Øę„ć—ć¾ć—ć‚‡ć†ć€‚

ć¤ć¾ć‚Šć€č‡Ŗåˆ†ćŒä½œć£ć¦ć„ć‚‹ä»Šå›žć®ä¾‹ć ćØ
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_hello_world_call_count_totalćØ恄恆
č¦‹ćŸē›®ć®ćƒ”惈ćƒŖć‚Æć‚¹ćÆ态org.littlewings.microprofile.metrics.SimpleAnnotatedResource.hello_world_call_countćØ恄恆
åå‰ć§ć‚¢ć‚Æć‚»ć‚¹ć§ćć‚‹ć“ćØ恫ćŖć‚Šć¾ć™ć€‚

$ curl -s localhost:9990/metrics/application/org.littlewings.microprofile.metrics.SimpleAnnotatedResource.hello_world_call_count
# TYPE application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_hello_world_call_count_total counter
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_hello_world_call_count_total 2.0

ć”ć‚‡ć£ćØć‚ć‹ć‚Šć«ćć„ć®ć§ć€å›°ć£ćŸć‚‰OPTIONS恧惔惈ćƒŖć‚Æć‚¹ć®ćƒ”ć‚æćƒ‡ćƒ¼ć‚æ悒見恦ćæć¾ć—ć‚‡ć†ć€‚
惔惈ćƒŖć‚Æć‚¹å˜ä½ć§å–å¾—ć—ćŸć„å “åˆćŖć©ć«ć€ć“ć®ęƒ…å ±ćÆå½¹ē«‹ć¤ć§ć—悇恆怂

č©±ć‚’ęˆ»ć—ć¦ć€‚

åŒć˜ćƒ”ćƒˆćƒŖć‚Æć‚¹ć‚’åˆ„ć®ćƒ”ć‚½ćƒƒćƒ‰ć§ć‚‚čØ˜éŒ²ć™ć‚‹ć“ćØćŒć§ćć¾ć™ć€‚ć‚‚ć†ć²ćØ恤态JAX-RSćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ć‚’čæ½åŠ ć€‚

    @GET
    @Path("count-yeah2")
    @Produces(MediaType.TEXT_PLAIN)
    @Counted(name = "yeah_call_count", absolute = true, displayName = "yeah call count metrics", description = "yeah call count description")
    public String countYeah2() {
        return "Yeah2!!";
    }

恓恔悉恫čØ˜č¼‰ć®ć‚ć‚‹ć‚ˆć†ć«ć€ćƒ”ćƒˆćƒŖć‚Æć‚¹ćÆ惔ć‚æćƒ‡ćƒ¼ć‚æć•ćˆåŒć˜ć§ć‚ć‚Œć°č¤‡ę•°ć®ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć§åŒć˜ćƒ”ćƒˆćƒŖć‚Æć‚¹ć‚’
参ē…§ć™ć‚‹ć“ćØćŒć§ćć¾ć™ć€‚

Reusing Metrics

åŒć˜åå‰ć®ćƒ”ćƒˆćƒŖć‚Æć‚¹ć§ć€ē•°ćŖć‚‹ćƒ”ć‚æćƒ‡ćƒ¼ć‚æć®ć‚‚ć®ć‚’å®šē¾©ć—ćŸå “合ćÆ态IllegalArgumentExceptionćŒć‚¹ćƒ­ćƒ¼ć•ć‚Œć¾ć™ćŒć€‚
恂ćØ态GaugećÆć“ć®ćƒ«ćƒ¼ćƒ«ć®åÆ¾č±”å¤–ć«ćŖć‚Šć¾ć™ć€‚

å‘¼ć³å‡ŗ恗怂

$ curl localhost:8080/microprofile-metrics-example/annotated/count-yeah2
Yeah2!!


$ curl localhost:8080/microprofile-metrics-example/annotated/count-yeah2
Yeah2!!

恓悌恧态2恤恮JAX-RSćƒŖć‚½ćƒ¼ć‚¹ćƒ”ć‚½ćƒƒćƒ‰ć®ć©ć”ć‚‰ć‚’å‘¼ć³å‡ŗć—ć¦ć‚‚ć€åŒć˜Counter惔惈ćƒŖć‚Æć‚¹ćŒę›“ę–°ć•ć‚Œć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚

$ curl localhost:9990/metrics/application/yeah_call_count
# HELP application_yeah_call_count_total yeah call count description
# TYPE application_yeah_call_count_total counter
application_yeah_call_count_total 4.0

ꬔ恫态Concurrent Gauge悒ä½æć£ć¦ćæć¾ć—ć‚‡ć†ć€‚

ćƒ©ćƒ³ćƒ€ćƒ ćŖē§’ę•°ć‚’ć‚¹ćƒŖćƒ¼ćƒ—ć™ć‚‹ć‚ˆć†ć«ä»•č¾¼ć‚“ć§ć€ć™ćć«ćÆēµ‚äŗ†ć—ćŖć„ć‚ˆć†ć«ć—ć¾ć™ć€‚

    @GET
    @Path("concurrent-gause")
    @Produces(MediaType.TEXT_PLAIN)
    @ConcurrentGauge(name = "my_concurrent_gause")
    public String concurrentGause() throws InterruptedException {
        long sleepSeconds = randomService.randomInt(5);
        TimeUnit.SECONDS.sleep(sleepSeconds);

        return String.format("sleeped %d sec", sleepSeconds);
    }

ć“ć®ę™‚ć€ćƒ©ćƒ³ćƒ€ćƒ ćŖę•“ę•°ć‚’å–å¾—ć™ć‚‹å‡¦ē†ćÆCDIē®”ē†BeanćØ恗态恓恔悉悂Count惔惈ćƒŖć‚Æć‚¹ć‚’å–å¾—ć™ć‚‹ć‚ˆć†ć«ć—ć¾ć—ć‚‡ć†ć€‚

src/main/java/org/littlewings/microprofile/metrics/RandomService.java

package org.littlewings.microprofile.metrics;

import java.util.Random;
import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;

import org.eclipse.microprofile.metrics.annotation.Counted;

@ApplicationScoped
public class RandomService {
    Random random;

    @PostConstruct
    public void init() {
        random = new Random();
        random.nextInt();
    }

    @Counted
    public int randomInt(int bound) {
        return random.nextInt(bound);
    }
}

恓悓ćŖę„Ÿć˜ć§ć‚¢ć‚Æć‚»ć‚¹ć—ć¦ć„ć‚‹é–“ć«

$ curl localhost:8080/microprofile-metrics-example/annotated/concurrent-gause &
$ curl localhost:8080/microprofile-metrics-example/annotated/concurrent-gause &
$ curl localhost:8080/microprofile-metrics-example/annotated/concurrent-gause &
$ curl localhost:8080/microprofile-metrics-example/annotated/concurrent-gause &
$ curl localhost:8080/microprofile-metrics-example/annotated/concurrent-gause &

惔惈ćƒŖć‚Æć‚¹ć‚’č¦‹ć‚‹ćØ态ē¾åœØćƒ”ć‚½ćƒƒćƒ‰å‡¦ē†äø­ć®ę•°ćŒć‚ć‹ć£ćŸć‚Šć—ć¾ć™ć€‚

$ curl localhost:9990/metrics/application/org.littlewings.microprofile.metrics.SimpleAnnotatedResource.my_concurrent_gause
# TYPE application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_concurrent_gause_current gauge
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_concurrent_gause_current 6.0
# TYPE application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_concurrent_gause_max gauge
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_concurrent_gause_max 0.0
# TYPE application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_concurrent_gause_min gauge
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_concurrent_gause_min 0.0

処ē†ćŒå…ØéƒØēµ‚äŗ†ć™ć‚‹ćØ态currentćÆ0恫ćŖć‚Šć¾ć™ć€‚

$ curl localhost:9990/metrics/application/org.littlewings.microprofile.metrics.SimpleAnnotatedResource.my_concurrent_gause
# TYPE application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_concurrent_gause_current gauge
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_concurrent_gause_current 0.0
# TYPE application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_concurrent_gause_max gauge
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_concurrent_gause_max 6.0
# TYPE application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_concurrent_gause_min gauge
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_concurrent_gause_min 0.0

Ꙃ間恌ēµŒć¤ćØ态maxćŖć©ć«åę˜ ć•ć‚Œć¦ć„ćć¾ć™ć€‚

CDIē®”ē†Bean恫付äøŽć—ćŸCounter悂态恓悓ćŖę„Ÿć˜ć«ćŖć‚Šć¾ć—ćŸć€‚

$ curl localhost:9990/metrics/application/org.littlewings.microprofile.metrics.RandomService.randomInt
# TYPE application_org_littlewings_microprofile_metrics_RandomService_randomInt_total counter
application_org_littlewings_microprofile_metrics_RandomService_randomInt_total 5.0

TimerćØSimple Timer悂試恗恦ćæć¾ć—ć‚‡ć†ć€‚ć“ć”ć‚‰ć‚‚ć€ćƒ©ćƒ³ćƒ€ćƒ ć«ć‚¹ćƒŖćƒ¼ćƒ—ć‚’å…„ć‚Œć¾ć™ć€‚

    @GET
    @Path("timer")
    @Produces(MediaType.TEXT_PLAIN)
    @Timed(name = "my_timer")
    public int timer() throws InterruptedException {
        long sleepSeconds = randomService.randomInt(5);
        TimeUnit.SECONDS.sleep(sleepSeconds);

        return (int) sleepSeconds;
    }

    @GET
    @Path("simply-timer")
    @Produces(MediaType.TEXT_PLAIN)
    @SimplyTimed(name = "my_simply_timer")
    public int simplyTimer() throws InterruptedException {
        long sleepSeconds = randomService.randomInt(5);
        TimeUnit.SECONDS.sleep(sleepSeconds);

        return (int) sleepSeconds;
    }

Timer恧čØ˜éŒ²ć™ć‚‹ćƒ”ć‚½ćƒƒćƒ‰ć«ć‚¢ć‚Æć‚»ć‚¹ć—ć¦ćæć¾ć™ć€‚5å›žć»ć©ć€‚

$ curl localhost:8080/microprofile-metrics-example/annotated/timer
4


$ curl localhost:8080/microprofile-metrics-example/annotated/timer
4


$ curl localhost:8080/microprofile-metrics-example/annotated/timer
3


$ curl localhost:8080/microprofile-metrics-example/annotated/timer
2


$ curl localhost:8080/microprofile-metrics-example/annotated/timer
3

Timer恧čØ˜éŒ²ć—ćŸćƒ”ćƒˆćƒŖć‚Æć‚¹ć§ć™ć€‚

$ curl localhost:9990/metrics/application/org.littlewings.microprofile.metrics.SimpleAnnotatedResource.my_timer
# TYPE application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_timer_rate_per_second gauge
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_timer_rate_per_second 0.04659992804288887
# TYPE application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_timer_one_min_rate_per_second gauge
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_timer_one_min_rate_per_second 0.03803114091972095
# TYPE application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_timer_five_min_rate_per_second gauge
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_timer_five_min_rate_per_second 0.014230203582008386
# TYPE application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_timer_fifteen_min_rate_per_second gauge
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_timer_fifteen_min_rate_per_second 0.005270118248321379
# TYPE application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_timer_min_seconds gauge
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_timer_min_seconds 2.000252859
# TYPE application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_timer_max_seconds gauge
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_timer_max_seconds 4.000690081
# TYPE application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_timer_mean_seconds gauge
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_timer_mean_seconds 3.1550887689637688
# TYPE application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_timer_stddev_seconds gauge
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_timer_stddev_seconds 0.7427672463717483
# TYPE application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_timer_seconds summary
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_timer_seconds_count 5.0
# TYPE application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_timer_seconds_sum gauge
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_timer_seconds_sum 16.001751731
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_timer_seconds{quantile="0.5"} 3.000265941
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_timer_seconds{quantile="0.75"} 4.000317245
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_timer_seconds{quantile="0.95"} 4.000690081
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_timer_seconds{quantile="0.98"} 4.000690081
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_timer_seconds{quantile="0.99"} 4.000690081
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_timer_seconds{quantile="0.999"} 4.000690081

ꬔ恫态Simple Timer怂

$ curl localhost:8080/microprofile-metrics-example/annotated/simply-timer
4


$ curl localhost:8080/microprofile-metrics-example/annotated/simply-timer
1


$ curl localhost:8080/microprofile-metrics-example/annotated/simply-timer
0


$ curl localhost:8080/microprofile-metrics-example/annotated/simply-timer
3


$ curl localhost:8080/microprofile-metrics-example/annotated/simply-timer
0

Timer恫ęÆ”ć¹ć‚‹ćØ态čØ˜éŒ²ć•ć‚Œć‚‹ćƒ”ćƒˆćƒŖć‚Æć‚¹ćÆćć£ćØęø›ć‚Šć¾ć™ć€‚

$ curl localhost:9990/metrics/application/org.littlewings.microprofile.metrics.SimpleAnnotatedResource.my_simply_timer
# TYPE application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_simply_timer_total counter
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_simply_timer_total 5.0
# TYPE application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_simply_timer_elapsedTime_seconds gauge
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_simply_timer_elapsedTime_seconds 8.000970078
# TYPE application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_simply_timer_minTimeDuration_seconds gauge
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_simply_timer_minTimeDuration_seconds 6.6287E-5
# TYPE application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_simply_timer_maxTimeDuration_seconds gauge
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_my_simply_timer_maxTimeDuration_seconds 4.000279805
Gause

ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’ä½æć£ćŸć‚µćƒ³ćƒ—ćƒ«ć®ęœ€å¾Œć«ć€Gauge悒試恗恦ćæć¾ć—ć‚‡ć†ć€‚

GaugećÆē‰¹ę®Šć§ć€ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’付äøŽć—恦悂恙恐恫ćÆ惔惈ćƒŖć‚Æć‚¹ć«ē™»éŒ²ć•ć‚Œćšć€å®Ÿéš›ć«ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’付äøŽć—ćŸ
CDIē®”ē†BeanćŒć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹åŒ–ć•ć‚Œć‚‹ć¾ć§é…å»¶ć—ć¾ć™ć€‚

Responsibility of the MicroProfile Metrics implementation

ć¾ćŸć€GaugećÆ複ꕰ恮CDIē®”ē†Bean恫ē“ä»˜ć‘ć‚‰ć‚Œć‚‹ć“ćØ悒čرåÆć—ć¾ć›ć‚“ć€‚

Metrics and CDI scopes

ć“ć®ć‚ćŸć‚ŠćŒę³Øꄏē‚¹ć§ć™ć€‚ 恧态Gauge悒ä½æē”Øć—ćŸć‚µćƒ³ćƒ—ćƒ«ć€‚

src/main/java/org/littlewings/microprofile/metrics/ApplicationScopedAnnotatedResource.java

package org.littlewings.microprofile.metrics;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.eclipse.microprofile.metrics.MetricUnits;
import org.eclipse.microprofile.metrics.annotation.Gauge;

@Path("application-scoped-annotated")
@ApplicationScoped
public class ApplicationScopedAnnotatedResource {
    @Inject
    RandomService randomService;

    @GET
    @Path("gauge")
    @Produces(MediaType.TEXT_PLAIN)
    @Gauge(name = "my_gauge", unit = MetricUnits.BYTES)
    public int gause() {
        Thread.dumpStack();

        return randomService.randomInt(1024);
    }
}

GaugećÆć€ä»–ć®ćƒ”ćƒˆćƒŖć‚Æć‚¹ćØé•ć£ć¦å˜ä½ć‚’ę˜Žē¤ŗēš„ć«ęŒ‡å®šć™ć‚‹åæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚

    @Gauge(name = "my_gauge", unit = MetricUnits.BYTES)

Gauge悒ä½æć£ćŸćƒ”ć‚½ćƒƒćƒ‰ć«ć‚¢ć‚Æć‚»ć‚¹ć—ć¦ćæć¾ć™ć€‚

$ curl localhost:8080/microprofile-metrics-example/application-scoped-annotated/gauge
360


$ curl localhost:8080/microprofile-metrics-example/application-scoped-annotated/gauge
999

ć“ć‚Œć§ć€ćƒ”ćƒˆćƒŖć‚Æć‚¹ćŒčØ˜éŒ²ć•ć‚Œć‚‹ć®ć§ć™ćŒā€¦ć€‚

å®Ÿéš›ć«čØ˜éŒ²ć•ć‚ŒćŸćƒ”ćƒˆćƒŖć‚Æć‚¹ć‚’ē¢ŗčŖć—恦ćæć¾ć™ć€‚

$ curl localhost:9990/metrics/application/org.littlewings.microprofile.metrics.ApplicationScopedAnnotatedResource.my_gauge
# TYPE application_org_littlewings_microprofile_metrics_ApplicationScopedAnnotatedResource_my_gauge_bytes gauge
application_org_littlewings_microprofile_metrics_ApplicationScopedAnnotatedResource_my_gauge_bytes 541.0

ć“ć®ę™‚ć€č£ć§ćÆ@Gaugeć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć‚’ä»˜äøŽć—ćŸćƒ”ć‚½ćƒƒćƒ‰ćŒå‘¼ć³å‡ŗć•ć‚Œć¦ć„ć¾ć™ć€‚

18:23:40,560 ERROR [stderr] (management I/O-1) java.lang.Exception: Stack trace
18:23:40,560 ERROR [stderr] (management I/O-1)  at java.base/java.lang.Thread.dumpStack(Thread.java:1383)
18:23:40,560 ERROR [stderr] (management I/O-1)  at deployment.microprofile-metrics-example.war//org.littlewings.microprofile.metrics.ApplicationScopedAnnotatedResource.gause(ApplicationScopedAnnotatedResource.java:24)
18:23:40,560 ERROR [stderr] (management I/O-1)  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
18:23:40,560 ERROR [stderr] (management I/O-1)  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
18:23:40,560 ERROR [stderr] (management I/O-1)  at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
18:23:40,560 ERROR [stderr] (management I/O-1)  at java.base/java.lang.reflect.Method.invoke(Method.java:566)
18:23:40,560 ERROR [stderr] (management I/O-1)  at io.smallrye.metrics//io.smallrye.metrics.interceptors.GaugeRegistrationInterceptor.invokeMethod(GaugeRegistrationInterceptor.java:88)
18:23:40,560 ERROR [stderr] (management I/O-1)  at io.smallrye.metrics//io.smallrye.metrics.interceptors.GaugeRegistrationInterceptor.access$100(GaugeRegistrationInterceptor.java:46)
18:23:40,560 ERROR [stderr] (management I/O-1)  at io.smallrye.metrics//io.smallrye.metrics.interceptors.GaugeRegistrationInterceptor$ForwardingGauge.getValue(GaugeRegistrationInterceptor.java:108)
18:23:40,560 ERROR [stderr] (management I/O-1)  at io.smallrye.metrics//io.smallrye.metrics.interceptors.GaugeRegistrationInterceptor$ForwardingGauge.getValue(GaugeRegistrationInterceptor.java:94)
18:23:40,560 ERROR [stderr] (management I/O-1)  at io.smallrye.metrics//io.smallrye.metrics.exporters.OpenMetricsExporter.createSimpleValueLine(OpenMetricsExporter.java:513)
18:23:40,560 ERROR [stderr] (management I/O-1)  at io.smallrye.metrics//io.smallrye.metrics.exporters.OpenMetricsExporter.exposeEntries(OpenMetricsExporter.java:200)
18:23:40,560 ERROR [stderr] (management I/O-1)  at io.smallrye.metrics//io.smallrye.metrics.exporters.OpenMetricsExporter.exportMetricsByName(OpenMetricsExporter.java:148)
18:23:40,561 ERROR [stderr] (management I/O-1)  at io.smallrye.metrics//io.smallrye.metrics.MetricsRequestHandler.handleRequest(MetricsRequestHandler.java:139)
18:23:40,561 ERROR [stderr] (management I/O-1)  at io.smallrye.metrics//io.smallrye.metrics.MetricsRequestHandler.handleRequest(MetricsRequestHandler.java:79)

Thread#dumpStackć‚’å…„ć‚Œć¦ć„ćŸć®ćÆć€ć“ć®ćŸć‚ć§ć™ć€‚

    public int gause() {
        Thread.dumpStack();

ä»–ć®ćƒ”ćƒˆćƒŖć‚Æć‚¹ćØē•°ćŖ悊态GaugećÆ惔惈ćƒŖć‚Æć‚¹å–å¾—ę™‚ć«ē“ä»˜ć‘ć‚‰ć‚ŒćŸå‡¦ē†ćŒå‘¼ć³å‡ŗć•ć‚Œć¾ć™ć‚ˆć€ćØć„ć†č©±ć§ć—ćŸć€‚

MetricRegistry悒ä½æ恆

ęœ€å¾Œć«ć€MtricRegistry悒ä½æć£ć¦ćæć¾ć—ć‚‡ć†ć€‚

Metric Registries

Registering metrics dynamically

ć“ć‚Œć¾ć§ćÆć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć§ćƒ”ćƒˆćƒŖć‚Æć‚¹ć‚’å®šē¾©ć—ćŸć‚Šć€å€¤ć‚’čØ˜éŒ²ć—ćŸć‚Šć—ć¦ć„ć¾ć—ćŸćŒć€MetricRegistry悒ä½æ恆恓ćØ恧
惔惈ćƒŖć‚Æć‚¹ć®å®šē¾©ć‚„čØ˜éŒ²ć‚’APIć§č”Œć†ć“ćØćŒć§ćć¾ć™ć€‚

MetricRegistryćÆć‚¹ć‚³ćƒ¼ćƒ—ļ¼ˆBase metrics态Vendor specific metrics态Application metricsļ¼‰ć”ćØć«ć‚·ćƒ³ć‚°ćƒ«ćƒˆćƒ³ć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ćŒ
恂悊态@Injectć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć§å–å¾—ć§ćć¾ć™ć€‚

MetricRegistry悒ä½æć£ćŸć‚³ćƒ¼ćƒ‰ć®é››å½¢ć‚’ć€ć“ć®ć‚ˆć†ć«ē”Øꄏ怂

src/main/java/org/littlewings/microprofile/metrics/MetricRegistryResource.java

package org.littlewings.microprofile.metrics;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.eclipse.microprofile.metrics.Counter;
import org.eclipse.microprofile.metrics.Histogram;
import org.eclipse.microprofile.metrics.Metadata;
import org.eclipse.microprofile.metrics.MetricRegistry;
import org.eclipse.microprofile.metrics.MetricType;
import org.eclipse.microprofile.metrics.MetricUnits;
import org.eclipse.microprofile.metrics.Tag;

@Path("metric-registry")
public class MetricRegistryResource {
    @Inject
    MetricRegistry metricRegistry;

    // 恓恓恫态MetricRegistry悒ä½æć£ćŸć‚³ćƒ¼ćƒ‰ć‚’ę›ø恏ļ¼ļ¼
}

MetricRegistryćÆ恓悓ćŖꄟ恘恧@Inject恧CDIē®”ē†Beanć«ć‚¤ćƒ³ć‚ø悧ć‚Æć‚·ćƒ§ćƒ³ć§ćć¾ć™ćŒć€ć“ć‚Œć§Application metrics恫åƾåæœć™ć‚‹
ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ćŒå–å¾—ć§ćć¾ć™ć€‚

    @Inject
    MetricRegistry metricRegistry;

恓悓ćŖę„Ÿć˜ć«ć™ć‚‹ćØBase metrics悄Vendor specific metrics恫åƾåæœć™ć‚‹ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚‚å–å¾—ć§ćć¾ć™ćŒć€ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć§ćÆ
ä½æ恆恓ćØćÆćŖ恄恧恗悇恆怂

@Inject
@RegistryType(type=MetricRegistry.Type.BASE)
MetricRegistry baseRegistry;


@Inject
@RegistryType(type=MetricRegistry.Type.VENDOR)
MetricRegistry vendorRegistry;

Application metrics悒꘎ē¤ŗć™ć‚‹å “åˆćÆ态恓恆ćŖć‚Šć¾ć™ć€‚

@Inject
@RegistryType(type=MetricRegistry.Type.APPLICATION)
MetricRegistry metricRegistry;

恧ćÆć€é€²ć‚ć¦ć„ćć¾ć™ć€‚

ć¾ćšćÆCounter悒ä½æć£ć¦ćæć¾ć—ć‚‡ć†ć€‚

    @GET
    @Path("simple-counter")
    @Produces(MediaType.TEXT_PLAIN)
    public String simpleCounter() {
        Counter counter = metricRegistry.counter("simple_counter_by_registry");
        counter.inc();
        return "Hello World!!";
    }

MetricRegistryć‹ć‚‰åå‰ć‚’ęŒ‡å®šć—ć¦Counterć‚’å–å¾—ć—ć€Counter#incć§ć‚«ć‚¦ćƒ³ć‚æć‚’å¢—åŠ ć§ćć¾ć™ć€‚

ē¢ŗčŖć€‚

$ curl localhost:8080/microprofile-metrics-example/metric-registry/simple-counter
Hello World!!


$ curl localhost:8080/microprofile-metrics-example/metric-registry/simple-counter
Hello World!!

MetricRegistry悒ä½æć£ć¦å®šē¾©ć—ćŸå “合ćÆć€ćƒ”ćƒˆćƒŖć‚Æć‚¹ć®åå‰ćÆęŒ‡å®šć—ćŸåå‰ćć®ć‚‚ć®ć«ćŖć‚Šć¾ć™ć€‚

$ curl localhost:9990/metrics/application/simple_counter_by_registry
# TYPE application_simple_counter_by_registry_total counter
application_simple_counter_by_registry_total 2.0

MetricRegistry#counterć®ć‚ˆć†ć«ć€å„ēØ®ćƒ”ćƒˆćƒŖć‚Æć‚¹ć«åƾåæœć—ćŸćƒ”ć‚½ćƒƒćƒ‰ćŒć‚ć‚‹ć®ć§ć™ćŒć€ć“ć‚ŒćÆget-or-createćŖ恮恧
MetricIDćŒć™ć§ć«å­˜åœØć—ć¦ć„ć‚Œć°åŒć˜ćƒ”ćƒˆćƒŖć‚Æć‚¹ćŒčæ”ć•ć‚Œć¾ć™ć€‚

List of methods of the MetricRegistry related to registering new metrics

        Counter counter = metricRegistry.counter("simple_counter_by_registry");

MetricIDćØćÆć€ćƒ”ćƒˆćƒŖć‚Æć‚¹ć®åå‰ćØć‚æ悰恮ēµ„ćæåˆć‚ć›ć§ć™ć€‚

MetricID

ꬔćÆć€ćƒ”ć‚æćƒ‡ćƒ¼ć‚æć‚’å®šē¾©ć—恦ćæć¾ć—ć‚‡ć†ć€‚

惔惈ćƒŖć‚Æć‚¹ć®get-or-createę™‚ć«ćƒ”ć‚æćƒ‡ćƒ¼ć‚æć‚’ęŒ‡å®šć™ć‚‹ć“ćØć‚‚ć§ćć‚‹ć®ć§ć™ćŒć€ä»Šå›žćÆęœ€åˆć«ē™»éŒ²ć—ć¦ćŠćć“ćØć«ć—ć¾ć—ć‚‡ć†ć€‚

    @PostConstruct
    public void init() {
        Metadata counterMetadata =
                Metadata
                        .builder()
                        .withName("registered_counter_by_registry")
                        .withDescription("pre registered counter by registry")
                        .withType(MetricType.COUNTER)
                        .withUnit(MetricUnits.NONE)
                        .build();

        metricRegistry.counter(counterMetadata);
    }

ä½æē”Øä¾‹ć€‚ćƒ”ć‚æćƒ‡ćƒ¼ć‚æć§ęŒ‡å®šć—ćŸåå‰ćØć€åŒć˜åå‰ć§MetricRegistryć‹ć‚‰ćƒ”ćƒˆćƒŖć‚Æć‚¹ć‚’å–å¾—ć™ć‚Œć°OK恧恙怂

    @GET
    @Path("pre-registered-counter")
    @Produces(MediaType.TEXT_PLAIN)
    public String preRegisteredCounter() {
        Counter counter = metricRegistry.counter("registered_counter_by_registry");
        counter.inc();
        return "Pre Registered Counter!!";
    }

ć¾ćŸć€ćƒ”ćƒˆćƒŖć‚Æć‚¹ć®ć‚Æćƒ©ć‚¹ć‚’ē›“ꎄä½æē”Øć™ć‚‹å “åˆćÆć€ć“ć®ć‚ˆć†ć«ć‚æć‚°ć‚’ęŒ‡å®šć™ć‚‹ć“ćØć‚‚ć§ćć¾ć™ć€‚
恓恔悉ćÆć€å…ˆć»ć©ćØåŒć˜åå‰ć®Counter悒ä½æē”Øć—ć¦ć„ć¾ć™ć€‚

    @GET
    @Path("pre-registered-counter2")
    @Produces(MediaType.TEXT_PLAIN)
    public String preRegisteredCounter2() {
        Counter counter =
                metricRegistry
                        .counter(
                                "registered_counter_by_registry",
                                new Tag("path", "/metric-registry/pre-registered-counter2"),
                                new Tag("type", "2")
                        );
        counter.inc();

        return "Pre Registered Counter2!!";
    }

ćć‚Œćžć‚Œć«ć‚¢ć‚Æć‚»ć‚¹ć€‚

$ curl localhost:8080/microprofile-metrics-example/metric-registry/pre-registered-counter
Pre Registered Counter!!


$ curl localhost:8080/microprofile-metrics-example/metric-registry/pre-registered-counter
Pre Registered Counter!!


$ curl localhost:8080/microprofile-metrics-example/metric-registry/pre-registered-counter2
Pre Registered Counter2!!


$ curl localhost:8080/microprofile-metrics-example/metric-registry/pre-registered-counter2
Pre Registered Counter2!!

惔惈ćƒŖć‚Æć‚¹ć‚’ē¢ŗčŖć€‚

$ curl localhost:9990/metrics/application/registered_counter_by_registry
# HELP application_registered_counter_by_registry_total pre registered counter by registry
# TYPE application_registered_counter_by_registry_total counter
application_registered_counter_by_registry_total{path="/metric-registry/pre-registered-counter2",type="2"} 2.0
application_registered_counter_by_registry_total 2.0

ć‚æć‚°ć®ęœ‰ē„”恧态ēµęžœćŒåˆ„怅恫ćŖć‚Šć¾ć—ćŸć­ć€‚

恓悌恧态ć‚æ悰恮ē¢ŗčŖć‚‚ć§ćć¾ć—ćŸć€‚

Histgram

ć‚¢ćƒŽćƒ†ćƒ¼ć‚·ćƒ§ćƒ³ć§ćÆ惔惈ćƒŖć‚Æć‚¹ć‚’čØ˜éŒ²ć§ććšć€ćƒ”ćƒˆćƒŖć‚Æć‚¹ć«åƾåæœć™ć‚‹ć‚Æćƒ©ć‚¹ć‚’ē›“ęŽ„ę‰±ć£ć¦čØ˜éŒ²ć™ć‚‹ć‚‚ć®ćØ恗恦Histogram恌
ć‚ć‚Šć¾ć™ć€‚

ęœ€å¾Œć«ć“ć”ć‚‰ć‚’ä½æć£ć¦ćæć¾ć—ć‚‡ć†ć€‚

惔ć‚æćƒ‡ćƒ¼ć‚æćÆCounterćØåŒć˜ć‚ˆć†ć«ē™»éŒ²ć—ć¦ćŠćć¾ć™ć€‚

    @PostConstruct
    public void init() {
        Metadata counterMetadata =
                Metadata
                        .builder()
                        .withName("registered_counter_by_registry")
                        .withDescription("pre registered counter by registry")
                        .withType(MetricType.COUNTER)
                        .withUnit(MetricUnits.NONE)
                        .build();

        metricRegistry.counter(counterMetadata);

        Metadata histogramMetadata =
                Metadata
                        .builder()
                        .withName("my_histogram")
                        .withDescription("my histogram example")
                        .withType(MetricType.HISTOGRAM)
                        .withUnit(MetricUnits.BYTES)
                        .build();

        metricRegistry.histogram(histogramMetadata);
    }

å˜ä½ć‚’č¦‹ćŸć‚‰ć‚ć‹ć‚Šć¾ć™ćŒć€ćƒć‚¤ćƒˆę•°ć‚’ćƒ†ćƒ¼ćƒžć«ć—ć¦ćæć¾ć™ć€‚

Histogram悒ä½æć£ćŸä¾‹ć€‚ć‚æ悰悂ä½æć£ć¦ćæć¾ć™ć€‚

    @GET
    @Path("histogram")
    @Produces(MediaType.TEXT_PLAIN)
    public String histogram() {
        Histogram histogram =
                metricRegistry.histogram(
                        "my_histogram",
                        new Tag("path", "/metric-registry/histogram")
                );

        long randomInt = randomService.randomInt(1024);
        histogram.update(randomInt);

        return String.format("Histogram, random = %d", randomInt);
    }

ćƒ©ćƒ³ćƒ€ćƒ ćŖę•°å­—ć‚’čØ˜éŒ²ć—ć¦ćæć¾ć™ć€‚

ć‚¢ć‚Æć‚»ć‚¹ć—ć¦ćæć¾ć™ć€‚

$ curl localhost:8080/microprofile-metrics-example/metric-registry/histogram
Histogram, random = 171


$ curl localhost:8080/microprofile-metrics-example/metric-registry/histogram
Histogram, random = 86


$ curl localhost:8080/microprofile-metrics-example/metric-registry/histogram
Histogram, random = 819

惔惈ćƒŖć‚Æć‚¹ć‚‚č¦‹ć¦ćæć¾ć™ć€‚

$ curl localhost:9990/metrics/application/my_histogram
# HELP application_my_histogram_bytes my histogram example
# TYPE application_my_histogram_min_bytes gauge
application_my_histogram_min_bytes{path="/metric-registry/histogram"} 86.0
# TYPE application_my_histogram_max_bytes gauge
application_my_histogram_max_bytes{path="/metric-registry/histogram"} 819.0
# TYPE application_my_histogram_mean_bytes gauge
application_my_histogram_mean_bytes{path="/metric-registry/histogram"} 361.91676959746343
# TYPE application_my_histogram_stddev_bytes gauge
application_my_histogram_stddev_bytes{path="/metric-registry/histogram"} 328.6816538560838
# TYPE application_my_histogram_bytes summary
application_my_histogram_bytes_count{path="/metric-registry/histogram"} 3.0
application_my_histogram_bytes_sum{path="/metric-registry/histogram"} 1076.0
application_my_histogram_bytes{path="/metric-registry/histogram",quantile="0.5"} 171.0
application_my_histogram_bytes{path="/metric-registry/histogram",quantile="0.75"} 819.0
application_my_histogram_bytes{path="/metric-registry/histogram",quantile="0.95"} 819.0
application_my_histogram_bytes{path="/metric-registry/histogram",quantile="0.98"} 819.0
application_my_histogram_bytes{path="/metric-registry/histogram",quantile="0.99"} 819.0
application_my_histogram_bytes{path="/metric-registry/histogram",quantile="0.999"} 819.0
application_my_histogram_min_bytes 0.0
application_my_histogram_max_bytes 0.0
application_my_histogram_mean_bytes 0.0
application_my_histogram_stddev_bytes 0.0
application_my_histogram_bytes_count 0.0
application_my_histogram_bytes_sum 0.0
application_my_histogram_bytes{quantile="0.5"} 0.0
application_my_histogram_bytes{quantile="0.75"} 0.0
application_my_histogram_bytes{quantile="0.95"} 0.0
application_my_histogram_bytes{quantile="0.98"} 0.0
application_my_histogram_bytes{quantile="0.99"} 0.0
application_my_histogram_bytes{quantile="0.999"} 0.0

恓悓ćŖꄟ恘恧态恄悍恄悍čØ˜éŒ²ć•ć‚Œć¾ć™ć€‚ć‚æ悰ćŖć—ć®ę–¹ćŒčØ˜éŒ²ć•ć‚Œć¦ć„ćŖ恄恮ćÆć€ć‚¹ćƒ«ćƒ¼ć—ć¾ć—ć‚‡ć†ć€‚

ć‚µćƒ•ć‚£ćƒƒć‚Æć‚¹ćÆć€ćƒ”ćƒˆćƒŖć‚Æć‚¹ć«ęŒ‡å®šć—ćŸå˜ä½ćŒåę˜ ć•ć‚Œć¾ć™ć€‚

Histogram OpenMetrics Text Format

ćØ悊恂恈恚态恓悓ćŖćØ恓悍恧恗悇恆恋怂

ć¾ćØ悁

Eclipse MicroProfile Metrics悒試恗恦ćæć¾ć—ćŸć€‚

ć„ć‚ć„ć‚ę‰±ć£ć¦ćæćŸć®ć§ć™ćŒć€ć‘ć£ć“ć†ēÆ„å›²ćŒåŗƒćć¦ć‚«ćƒćƒ¼ć—ćć‚ŒćŖ恄ćØ恄恆恋态ć‚Øćƒ³ćƒˆćƒŖč‡Ŗä½“ćŒäø­é€”半ē«Æ恫ćŖć£ćŸć‚ˆć†ćŖ
ę°—ćŒć—ć¾ć™ćŒā€¦ć€‚

ć‚‚ć†å°‘ć—ć€ēµžć£ć¦ę›øć„ćŸę–¹ćŒć‚ˆć‹ć£ćŸć‹ć‚‚ć—ć‚Œć¾ć›ć‚“ā€¦ć€‚

SmallRye Metrics恮JAX-RS恮éƒØåˆ†ćŒć†ć¾ćę‰±ćˆćŖć‹ć£ćŸć‚Šć—ćŸć®ć§ć€ć“ć®ć‚ćŸć‚ŠćÆć¾ćŸåˆ„é€”ć‚„ć‚ŠćŸć„ć§ć™ć­ć€‚

ćØć‚Šć‚ćˆćšć€ä»Šå›žćÆ恓悓ćŖćØ恓悍恧怂

ć‚Ŗćƒžć‚±

ä½•å›žć‚‚WildFlyć«ćƒ‡ćƒ—ćƒ­ć‚¤ć—ć¦ē¢ŗčŖć™ć‚‹ć®ćŒé¢å€’ć ć£ćŸć®ć§ć€ć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰ć‚’ę›ø恄恦恄悋ꙂćÆWildFly Bootable JAR恧
å¤‰ę›“ć‚’ćƒŖć‚¢ćƒ«ć‚æć‚¤ćƒ ć«åę˜ ć—ćŖ恌悉ē¢ŗčŖć—ć¦ć„ć¾ć—ćŸć€‚

仄äø‹ć®čØ­å®šć‚’pom.xmlć«å…„ć‚Œć¦

    <profiles>
        <profile>
            <id>bootable</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.wildfly.plugins</groupId>
                        <artifactId>wildfly-jar-maven-plugin</artifactId>
                        <version>5.0.2.Final</version>
                        <configuration>
                            <feature-pack-location>wildfly@maven(org.jboss.universe:community-universe)#24.0.1.Final
                            </feature-pack-location>
                            <layers>
                                <layer>jaxrs-server</layer>
                                <layer>management</layer>
                                <layer>microprofile-metrics</layer>
                            </layers>
                            <plugin-options>
                                <jboss-maven-dist/>
                            </plugin-options>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

仄äø‹ć§ć€ć‚½ćƒ¼ć‚¹ć‚³ćƒ¼ćƒ‰ć®å¤‰ę›“恮åŗ¦ć«åę˜ ć•ć‚Œć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć™ć€‚

$ mvn -P bootable wildfly-jar:dev-watch

ć“ć®å½¢ę…‹ć ćØ态惇惗惭悤恕悌悋WARćƒ•ć‚”ć‚¤ćƒ«ćÆROOT.war恫ćŖć£ć¦ć„ć‚‹ć“ćØ恫ćŖć‚‹ć®ć§ć€ćć®ē‚¹ć ć‘ę³Øꄏ恧恙恭怂

$ curl localhost:8080/annotated/count-hello-world
Hello World!!

惔惈ćƒŖć‚Æć‚¹å–å¾—ć®URLćÆ态Bootable JARć§ć‚‚å¤‰ć‚ć‚Šć¾ć›ć‚“ć€‚

$ curl localhost:9990/metrics/application/org.littlewings.microprofile.metrics.SimpleAnnotatedResource.hello_world_call_count
# TYPE application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_hello_world_call_count_total counter
application_org_littlewings_microprofile_metrics_SimpleAnnotatedResource_hello_world_call_count_total 1.0

ć ć„ćŸć„ć§ććŸć‚‰ć€ęœ€å¾Œć«WildFlyć«ćƒ‡ćƒ—ćƒ­ć‚¤ć—ć¦ē¢ŗčŖć—ć¦ć„ć¾ć—ćŸć€‚