MicroProfile: @Counted vs. @Gauge

MicroProfile Metrics comes with @Counted and @Gauge annotations:


@Path("ping")
public class PingResource {

    @GET
    @Counted(monotonic = true)
    public String ping() {
        return "Enjoy MicroProfile and Java EE 8";
    }

    @Gauge(unit = "correctness")
    public int answer() {
        return 42;
    }
}


According to the microprofile specification, the @Counted annotation:

"Denotes a counter, which counts the invocations of the annotated object."
with default unit: MetricUnits.NONE

In contrary, the @Gauge annotation:

"Denotes a gauge, which samples the value of the annotated object."
no default, must be supplied by the user.

Typical output (curl -H"Accept: application/json" http://localhost:9080/metrics/application):


    {
        "com.airhacks.ping.boundary.PingResource.answer":42,
        "com.airhacks.ping.boundary.PingResource.ping":1
}  

The @Counted annotation automatically counts the total invocations of the annotation method (monotonic=true), or the amount of parallel invoked methods at any time: (monotonic=false) (ConcurrentGauge will probably replace: (monotonic=false)).

On the other hand, the @Gauge exposes the return value of the annotated method as a metric.

@Gauge annotations are used to expose metrics with dedicated methods. The values have to be provided by the developer (e.g. number of orders in the DB) and the method is going to be invoked by the metrics infrastructure.

Business methods can be additionally annotated with: @Counted and their invocation count is going to be exposed as a metric.

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: airhacks.io.


NEW: Online Workhop Effective WebApps without Frameworks is also coming to: MUC Airport.

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

JAX-RS, CDI: native executable vs. JVM with quarkus.io

Creating a native, executable app from CDI / JAX-RS application with quarkus.io and hot-reload features. The native executable is compared with the fooprint and startup time of the SkimmedJAR:

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: airhacks.io.


NEW: Online Workhop Effective WebApps without Frameworks is also coming to: MUC Airport.

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

Supersonic, Subatomic Java (EE) -- SkimmedJARs with quarkus.io

Setting up a https://quarkus.io project from scratch, injecting a CDI bean, building a SkimmedJARs and running the server:

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: airhacks.io.


NEW: Online Workhop Effective WebApps without Frameworks is also coming to: MUC Airport.

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

Jakarta EE / MicroProfile in the Clouds: Runtimes not Servers--airhacks.fm podcast

Subscribe to airhacks.fm podcast via: RSS iTunes

An airhacks.fm conversation / 29th episode with Bruno Borges about:

sudden death of remote EJBs caused by Java EE 5 and Web, servers as cloud, shared deployments in E10k , separation between infrastructure and business is boring, no rocket science, application servers and immutable infrastructure, frozen application servers in Docker layers, Docker modernized deployment model without modernizing Java EE, FatJar and UeberJars are useful outside containers, Azure AppService, the actual idea of application servers is pointless, cloud hooks for building ThinWARs, extending application servers with cloud-specific features, what is actually the definition of serverless?, serverless Java EE and the events are missing, JAX-RS endpoints as event listeners, servlerless platforms and lock-in to serverless environment, shipping functions as Docker images, openfaas, killer use cases for serverless functions, the legacy perception of Java EE, MicroProfile solves the marketing problem, cloud native deployments with MicroProfile, what is the difference between servers and runtimes, lets talk about runtimes, not servers, moving away from servers to runtimes, opinionated runtimes for developer experience, Convention over Configuration was borrowed from Ruby on Rails, Don't Make Me Think, Java EE / microprofile is an interesting programming model for the cloud, there is no such a thing as standards, everything should be an event, CloudEvents is an interesting standard, MicroProfile could implement binding for CloudEvents, wrapping proprietary cloud bootstraping logic with CDI, improving developer's experience by injection proprietary cloud services, MicroProfile Azure Key Vault
Bruno can be contacted via: bruno.borges@microsoft.com (please no spam), Bruno at LinkedIn and twitter: @brunoborges

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: airhacks.io.


NEW: Online Workhop Effective WebApps without Frameworks is also coming to: MUC Airport.

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

Running Java without javac

Running Java without javac and class files:

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: airhacks.io.


NEW: Online Workhop Effective WebApps without Frameworks is also coming to: MUC Airport.

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

DB Load Balancing, Java EE Authentication, Unikernels, Lazy Entity Serialization, Quarkus, MIcroProfile--60th airhacks.tv

5th anniversary, 60th airhacks.tv, ~30 questions and topics (http://adambien.blog/roller/abien/entry/db_loadbalancing_java_ee_authentication) ...in 1h:15mins:

"DB LoadBalancing, Java EE Authentication, Unikernels, Hexagons, Lazy Serialization, High Performance JDBC, quarkus.io, popularity of MicroProfile (...)"

Any questions left? Ask now: https://gist.github.com/AdamBien/606e7a0c27ebd6457515741320ff037f and get the answers at the next airhacks.tv.

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: airhacks.io.


NEW: Online Workhop Effective WebApps without Frameworks is also coming to: MUC Airport.

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

DB LoadBalancing, Java EE Authentication, Unikernels, Hexagons, Lazy Serialization, High Performance JDBC--60th airhacks.tv

Topics excerpts (https://gist.github.com/AdamBien/a26694037cad257f3828bd9d23c85b25) for the 60th (!!) airhacks.tv:

  1. Additional thoughts on Hexagonal Architectures
  2. Databases load balancing
  3. Dealing with ThinWARs and useful 3rd party dependencies
  4. Persistent timers in cluster
  5. EJB local, remote etc. or learning Java EE with or without history
  6. Shopping cart and microservices
  7. The who is first probem and JMS.
  8. Unikernel architectures and Java EE
  9. Microservice best practices with Java EE
  10. Serialization of lazy JPA entities
  11. WebStandards SPA and form authentication / authorization per page
  12. Difference between: @Gauge and @Counted
  13. Are WebSockets reasonable for a implementation of a Chat?
  14. Checking connection leaks with JDBC
  15. In what order should the following be closed. Connection, PreparedStatement, ResultSet?
  16. What are the most effective ways/ APIS, Libraries to test for connection/ connection pool leakages in java code?
  17. Does a high number of sleeping connections have a negative impact on Database/system performance?
  18. JMS with WebSockets in cluster / OpenShift
  19. Opinions on Wildfly & Galleon?
  20. Usecases for ThornTail
  21. Java EE Security (Java EE 8) best practices
  22. How to handle authentication and authorization (the Java EE way) in a module
  23. Which interfaces to implement? How does this work with EJBs, should any of the implementing classes be EJBs?
  24. The future of Jersey
  25. WebStandards and productivity
  26. Thoughts on quarkus.io
  27. Balance between SpringBoot and Java EE
  28. Java SE low latency/real time
  29. Jira+Confluence vs. git+asciidoc

Ask questions during the show via twitter mentioning me: http://twitter.com/AdamBien (@AdamBien) or using the hashtag: #airhacks. You can join the Q&A session live each first Monday of month, 6 P.M at airhacks.tv or http://www.ustream.tv/channel/adambien

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: airhacks.io.


NEW: Online Workhop Effective WebApps without Frameworks is also coming to: MUC Airport.

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

More Conventions with Maven.next--airhacks.fm podcast

Subscribe to airhacks.fm podcast via: RSS iTunes

An airhacks.fm conversation with Robert Scholte (@rfscholte) and Sebastian Daschner (@DaschnerS) about:

"Convention over Configuration and Maven, strategies for the "default", dependency versions to "apache" maven plugins, maven default behaviours, configuration hierarchies, Maven and CI/CD like Jenkins, command line options, pom elements, pom properties, the Java EE-stic approach to Maven, upgrading or downgrading, Maven and Java 11+, Maven.next features, effective POMs, accessing default versions of the plugins, making Maven configuration as lean as Java EE, Configuration by Exception, listing the current default plugin versions, specifying the versions in POM and overriding them with CLI and system properties."

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: airhacks.io.


NEW: Online Workhop Effective WebApps without Frameworks is also coming to: MUC Airport.

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

Full-text Search in Generated JavaDoc

Java 9+ (JEP-225) comes with full text search in generated JavaDoc:

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: airhacks.io.


NEW: Online Workhop Effective WebApps without Frameworks is also coming to: MUC Airport.

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

MicroProfile: @Metered vs. @Timed

MicroProfile Metrics comes with @Metered:


@Path("metered")
public class MeteredResource {

    @GET
    @Metered(name = "ping_metered")
    public String ping() {
        return "metered " + System.currentTimeMillis();
    }    
}

and @Timed:

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import org.eclipse.microprofile.metrics.annotation.Timed;

@Path("timed")
public class TimedResource {

    @GET
    @Timed(name = "ping_timed")
    public String ping() {
        return "timed " + System.currentTimeMillis();
    }    
}

annotations.

According to the microprofile specification, the @Metered annotation:

"Denotes a meter, which tracks the frequency of invocations of the annotated object."
with default unit: "per second"

In contrary, the @Timed annotation:

"Denotes a timer, which tracks duration of the annotated object."
with default unit: nanoseconds.

The output after a brief stress test:


{
    "com.airhacks.metrics.boundary.MeteredResource.ping_metered": {
        "count": 10,
        "fiveMinRate": 2.0,
        "oneMinRate": 2.0,
        "fifteenMinRate": 2.0,
        "meanRate": 1.1044614253525735
    },
    "com.airhacks.metrics.boundary.TimedResource.ping_timed": {
        "fiveMinRate": 1.9355159413581935,
        "max": 202722,
        "count": 20,
        "p50": 7658.0,
        "p95": 202722.0,
        "p98": 202722.0,
        "p75": 8228.0,
        "p99": 202722.0,
        "min": 5852,
        "fifteenMinRate": 1.9780232116334415,
        "meanRate": 0.9988264886468711,
        "mean": 23041.21494920979,
        "p999": 202722.0,
        "oneMinRate": 1.7175127368841634,
        "stddev": 47095.42163982647
    }
}    

The @Timed is useful to track the time spent in methods. Particularly the max attribute is useful to track possible performance problems.

On the other hand, the @Metered annotation exposes frequency / throughput, which can be directly used in stress tests / torture tests as thresholds.

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: airhacks.io.


NEW: Online Workhop Effective WebApps without Frameworks is also coming to: MUC Airport.

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

Online Workshops
realworldpatterns.com
...the last 150 posts
...the last 10 comments
License