Collect metrics with the Micronaut framework and monitor them on Amazon Cloudwatch

Learn how to collect standard and custom metrics with the Micronaut framework and monitor them on Amazon Cloudwatch.

Authors: Nemanja Mikic, Burt Beckwith

Micronaut Version: 3.8.2

1. Getting Started

In this guide, we will create a Micronaut application written in Groovy.

We’ll use Micronaut Micrometer to expose application metric data with Micrometer.

2. What you will need

To complete this guide, you will need the following:

  • Some time on your hands

  • A decent text editor or IDE

  • JDK 1.8 or greater installed with JAVA_HOME configured appropriately

3. Amazon Web Services (AWS)

If you don’t have one already, create an AWS Account.

3.1. AWS CLI

Follow the AWS documentation for installing or updating the latest version of the AWS CLI.

3.2. Administrator IAM user

Instead of using your AWS root account, it is recommended that you use an IAM administrative user. If you don’t have one already, follow the steps below to create one:

aws iam create-group --group-name Administrators
aws iam create-user --user-name Administrator
aws iam add-user-to-group --user-name Administrator --group-name Administrators
aws iam attach-group-policy --group-name Administrators --policy-arn $(aws iam list-policies --query 'Policies[?PolicyName==`AdministratorAccess`].{ARN:Arn}' --output text)
aws iam create-access-key --user-name Administrator

Then, run aws configure to configure your AWS CLI to use the Administrator IAM user just created.

4. The Application

Download the complete solution of the Collect Metrics with Micronaut guide. You will use the sample application as a starting point.

5. Monitor metrics on Amazon CloudWatch

To publish metrics to Amazon CloudWatch, you have to adjust your application configuration slightly, and then you will be able to create queries and monitor your metrics on Cloudwatch.

src/main/resources/application.yml
micronaut:
  metrics:
    enabled: true (1)
    binders: (2)
      files:
        enabled: true
      jdbc:
        enabled: true
      jvm:
        enabled: true
      logback:
        enabled: true
      processor:
        enabled: true
      uptime:
        enabled: true
      web:
        enabled: true
    export:
      cloudwatch:
        enabled: true
        namespace: micronautguide (3)
1 Change to false to disable all metrics, e.g., per-environment
2 These default to true and are only here for convenience, to be able to disable a subset of metrics
3 Change the namespace to something meaningful, for example, the app’s name. In this guide, we are using micronautguide

5.1. Visit the Amazon CloudWatch Metrics.

In the Metrics panel, select the namespace that you chose earlier. We select micronautguide.


cloudwatch metrics


Here you can browse different metrics and explore their values. In this example, we want to check the price of Bitcoin. Select Metrics with no dimensions.


cloudwatch metrics browse


In this panel, you can see our custom metrics about Bitcoin. Select (#2) bitcoin.price.latest.value to see on (#1) the graph how the price of Bitcoin changed over time.


cloudwatch bitcoin metric


6. Next steps

Explore more features with Micronaut Guides.

Read about Amazon Cloudwatch

7. Help with the Micronaut Framework

The Micronaut Foundation sponsored the creation of this Guide. A variety of consulting and support services are available.