Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Quick links: redhat.com, Customer Portal, Red Hat's developer site, Red Hat's partner site.

  • You are here

    Red Hat

    Learn about our open source products, services, and company.

  • You are here

    Red Hat Customer Portal

    Get product support and knowledge from the open source experts.

  • You are here

    Red Hat Developer

    Read developer tutorials and download Red Hat software for cloud application development.

  • You are here

    Red Hat Partner Connect

    Get training, subscriptions, certifications, and more for partners to build, sell, and support customer solutions.

Products & tools

  • Ansible.com

    Learn about and try our IT automation product.
  • Red Hat Ecosystem Catalog

    Find hardware, software, and cloud providers―and download container images―certified to perform with Red Hat technologies.

Try, buy, & sell

  • Red Hat Hybrid Cloud Console

    Access technical how-tos, tutorials, and learning paths focused on Red Hat’s hybrid cloud managed services.
  • Red Hat Store

    Buy select Red Hat products and services online.
  • Red Hat Marketplace

    Try, buy, sell, and manage certified enterprise software for container-based environments.

Events

  • Red Hat Summit and AnsibleFest

    Register for and learn about our annual open source IT industry event.

The Monitoring aspects of Eclipse MicroProfile 1.2

October 17, 2017
Heiko Rupp
Related topics:
JavaMicroservices

Share:

Share on twitter Share on facebook Share on linkedin Share with email
  • Health Checks
  • Telemetry aka MicroProfile Metrics
  • Contributing
  • References

Eclipse MicroProfile (MP) aims at bringing Microservices to Enterprise Java by developing common standards that MP-compliant vendors then implement [1]. This not only applies for developer APIs but also to interfaces for running, configuring, and managing the servers.

The more classical specifications have often left out many details as vendor-specific - especially in the area of setting up and running of the applications and servers. For the Java Enterprise Edition, there are standards like JMX and JSR-77, but those were most of the time not used or access from management stations was not specified. This made it harder in practice to monitor the health of an application or to port the application from one application server vendor than needed.

The MicroProfile community has decided that aspects of running the applications like telemetry and health checks should not be vendor specific but be part of the base specifications.

I will now show two aspects of Monitoring in MicroProfile, that are included in the MicroProfile 1.2 release. Further aspects like distributed tracing may follow in subsequent releases.

Health Checks

Health Checks

Health Checks answer the binary question "is my application running well or should it be restarted?" This has always been an important question for operations and it was pretty common to just restart an application that had memory leaks.  Health Checks became a lot more relevant in recent days with schedulers like Kubernetes, where health checks are a core concept. Kubernetes and thus OpenShift regularly check the health of a running container. If the container reports being unhealthy (or doesn't answer at all), Kubernetes will kill the container and start a new instance.

Describing the health state via a Java API

Health checks have two access points, the http side, and the Java API side. Let’s first have a look at the Java side to expose the system health:

@Health
@ApplicationScoped
public class HealthDemo implements HealthCheck {
    @Override
    public HealthCheckResponse call() {
        HealthCheckResponseBuilder alive = HealthCheckResponse.named("alive");
        // add other info
        return alive.up().build();
    }
}
Copy snippet

To expose the data, you have to implement the HealthCheck interface. Within the implemented call() method one then retrieves a HealthCheckResponseBuilder with a name for the check and supplies the status (up/down). It is also possible to supply more parameters to the HealthCheckResponseBuilder. Those are then exposed on the rest interface.

It is possible to provide more than one such health check provider. The results of all those checks will then aggregated to form the final outcome.

Fetching the health state via http

Systems can query health data via http GET operation on the /health endpoint. Kubernetes will consider the application as healthy if the response code is in the range of 200-399.

Thus to report a healthy system state, MP-Health implementations will respond with “200 OK”, and a payload that specifies the outcome as UP and the list of checks executed. The checks array will be empty unless specific health checks have been installed.

$ curl http://localhost:8080/health
{
"outcome": "UP",
"checks": [
    {
        "name": "alive",
        "state": "UP"
    }
  ]
}
Copy snippet

The individual checks provide their status within the checks section. This is helpful when more than one check is configured and the overall outcome is DOWN. The individual checks then help to pinpoint the cause of unhealthiness. Additional information given to the HealthCheckResponseBuilder in the Java code is passed on to the individual check result.

Telemetry aka MicroProfile Metrics

Telemetry aka MicroProfile Metrics

Telemetry exposes metrics of the running server like CPU and Memory usage, thread count and others. Those are then often fed into charting systems to visualize the metrics over time or serve for capacity planning purposes.

The Java Virtual machine has a way to expose data for a long time via MBeans and the MBeanServer. Since Java SE 6, there is even an (RMI based) remote protocol defined for all VMs on how to access the MBean Server from remote processes.

Dealing with this protocol is difficult and does not fit in today’s http-based interactions. The other pain point is that many of the existing servers have different properties exposed under different names. It is thus not easy to set up monitoring of different kinds of servers.

MicroProfile has created a monitoring specification that addresses the above two points via a http-based API for access by monitoring agents and a Java API that allows exporting application-specific metrics.

There are three scopes for metrics within the specification:

  • Base: those are metrics, mostly JVM statistics, that every compliant vendor has to support.
  • Vendor: optional vendor-specific metrics that are not portable.
  • Application: optional metrics from deployed applications. I will present the Java-API for those below.

Retrieve telemetry data via http

Let’s have a look at the way monitoring agents can retrieve data from the server.

MicroProfile Metrics exposes data in two formats by default. The Prometheus text format is used if no format is requested explicitly. The specification also defines a JSON encoding, which can be requested by passing the media-type of 'application/json'.

$ curl -Haccept:application/json http://localhost:8080/metrics/base
{
  "classloader.totalLoadedClass.count" : 12304,
  "cpu.systemLoadAverage" : 2.029296875,
  "thread.count" : 53,
  "classloader.currentLoadedClass.count" : 12262,
  "jvm.uptime" : 6878170,
  "gc.PS MarkSweep.count" : 3,
  "memory.committedHeap" : 1095237632,
  "thread.max.count" : 66,
  "gc.PS Scavenge.count" : 11,
  "cpu.availableProcessors" : 4,
  "thread.daemon.count" : 11,
  "classloader.totalUnloadedClass.count" : 42,
  "memory.maxHeap" : 3817865216,
  "memory.usedHeap" : 427363088,
  "gc.PS MarkSweep.time" : 322,
  "gc.PS Scavenge.time" : 244
}
Copy snippet

In the previous example, we are only retrieving the metrics in the base scope in the JSON format. Next, we are exposing metrics from all scopes in the Prometheus format. I have trimmed the output to only show one metrics of each scope.

$curl http://localhost:8080/metrics
# TYPE application:de_bsd_swarmdemo_rest_hello_world_endpoint_a_counter counter
application:de_bsd_swarmdemo_rest_hello_world_endpoint_a_counter{tier="integration"} 52.0
# TYPE base:classloader_total_loaded_class_count counter
base:classloader_total_loaded_class_count{tier="integration"} 12304.0
# TYPE vendor:memory_pool_metaspace_usage_max gauge
vendor:memory_pool_metaspace_usage_max_bytes{tier="integration"} 6.47796E7
Copy snippet

Java API

Let’s now have a look at the Java-API. I am using a single JAX-RS endpoint for this illustration. Users of DropWizard Metrics may find some of the following familiar. The API is on purpose modeled after DropWizard Metrics. It has been enhanced to be usable with the help of CDI to do the heavy lifting.

@ApplicationScoped
@Path("/hello")
public class HelloWorldEndpoint {

    @Inject
    Counter aCounter;

    @GET
    @Produces("text/plain")
    @Counted(description = "Counting of the Hello call", absolute = true)
    @Timed(name="helloTime", description = "Timing of the Hello call", absolute = true)
    @Metered(absolute = true, name = "helloMeter")
    public Response doGet() {
        aCounter.inc();
        return Response.ok("Hello from WildFly Swarm! " 
                               + aCounter.getCount())
               .build();
    }
}
Copy snippet

Using and exposing the metrics happens via the magic of CDI. In most cases, it is enough to just provide one of the annotation @Counted, @Timed and so on from the package org.eclipse.microprofile.metrics.annotation on the method or field you want to expose and the implementation will do the rest for you.

There is one counter (aCounter) in the example that is merely defined for exposition with the help of @Inject (Line 6).

The counter is explicitly increased in line 14. Its value is retrieved in line 16 and included in the REST response of our JAX-RS endpoint.

If you look at the annotations, you can see that additional metadata can be provided as the description above. Supplying metadata is strongly encouraged to make it easier for operators to understand what a certain metric means.

If you do not provide an explicit name on the annotation then the implementation computes a base name from the annotated item. In case of the @Counted inline 10, the resulting metric name is doGet which is the method name. The fully qualified class name is not prepended because the parameter absolute is true.

Contributing

Contributing

MicroProfile specifications follow an agile good enough approach with feedback cycles. Once a specification has been released, it will be included in a subsequent MicroProfile umbrella release. It is possible that a newer version of a specification breaks compatibility with previous versions.

If you are interested in contributing to future versions of the specification, you can join the MicroProfile Google Group.

References

References

Prometheus text format https://prometheus.io/docs/instrumenting/exposition_formats/#text-format-details

MicroProfile Health Specification repository https://github.com/eclipse/microprofile-health

MicroProfile Metrics Specification repository https://github.com/eclipse/microprofile-metrics

[1] https://developers.redhat.com/blog/2016/06/27/microprofile-collaborating-to-bring-microservices-to-enterprise-java/


Take advantage of your Red Hat Developers membership and download RHEL today at no cost.

Last updated: October 16, 2017

Recent Posts

  • Improve GPU utilization with Kueue in OpenShift AI

  • Integration Powers AI: Apache Camel at Devoxx UK 2025

  • How to use RHEL 10 as a WSL Podman machine

  • MINC: Fast, local Kubernetes with Podman Desktop & MicroShift

  • How to stay informed with Red Hat status notifications

Red Hat Developers logo LinkedIn YouTube Twitter Facebook

Products

  • Red Hat Enterprise Linux
  • Red Hat OpenShift
  • Red Hat Ansible Automation Platform

Build

  • Developer Sandbox
  • Developer Tools
  • Interactive Tutorials
  • API Catalog

Quicklinks

  • Learning Resources
  • E-books
  • Cheat Sheets
  • Blog
  • Events
  • Newsletter

Communicate

  • About us
  • Contact sales
  • Find a partner
  • Report a website issue
  • Site Status Dashboard
  • Report a security problem

RED HAT DEVELOPER

Build here. Go anywhere.

We serve the builders. The problem solvers who create careers with code.

Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

Sign me up

Red Hat legal and privacy links

  • About Red Hat
  • Jobs
  • Events
  • Locations
  • Contact Red Hat
  • Red Hat Blog
  • Inclusion at Red Hat
  • Cool Stuff Store
  • Red Hat Summit

Red Hat legal and privacy links

  • Privacy statement
  • Terms of use
  • All policies and guidelines
  • Digital accessibility

Report a website issue