Creating Domain-Specific Metrics On-The-Fly with MicroProfile

Domain-specific counters can be created on-the-fly by injecting the MetricRegistry:

import javax.inject.Inject;
import org.eclipse.microprofile.metrics.MetricRegistry;
import org.eclipse.microprofile.metrics.annotation.RegistryType;    

public class PingResource {
    @RegistryType(type = MetricRegistry.Type.APPLICATION)
    MetricRegistry registry;

    public String ping() {
        return "Enjoy Java EE 8 with MicroProfile ThinWARs!";

curl http://localhost:9080/metrics/application yields:

# TYPE application:ping_count counter
application:ping_count 1    
and curl -H"Accept: application/json" http://localhost:9080/metrics/application returns


The size of the WAR is 4kB. Initial build time: 3292 ms, subsequent build times: < 3s. Deploy time: 0.233 seconds.

Built and deployed with WAD and tested with openliberty (the largest possible installation with all Java EE 8 + MicroProfile features enabled).

See you at Web, MicroProfile and Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home:


Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments