Skip to content

Monitor Java/JMX applications running on Amazon EKS

Note

Since v2.x, Java based applications monitoring on EKS has been merged within the eks-monitoring module to allow visibility both on the cluster and the workloads, #59.

In addition to EKS infrastructure monitoring, the current example provides curated Grafana dashboards, Prometheus alerting and recording rules with multiple configuration options for Java based workloads on EKS.

Setup

1. Add Java metrics, dashboards and alerts

From the previous example's configuration, simply enable the Java pattern's flag.

module "eks_monitoring" {
   ...
   enable_java = true
}

You can further customize the Java pattern by providing java_config options.

2. Grafana API key

Make sure to refresh your temporary Grafana API key

export TF_VAR_managed_grafana_workspace_id=g-xxx
export TF_VAR_grafana_api_key=`aws grafana create-workspace-api-key --key-name "observability-accelerator-$(date +%s)" --key-role ADMIN --seconds-to-live 7200 --workspace-id $TF_VAR_managed_grafana_workspace_id --query key --output text`

Deploy

Simply run this command to deploy.

terraform apply

Note

To see the complete Java example, open the example on the repository

Visualization

1. Grafana dashboards

Go to the Dashboards panel of your Grafana workspace. There will be a folder called Observability Accelerator Dashboards

image

Open the "Java/JMX" dashboard to view its visualization

Grafana Java dashboard

2. Amazon Managed Service for Prometheus rules and alerts

Open the Amazon Managed Service for Prometheus console and view the details of your workspace. Under the Rules management tab, you will find new rules deployed.

image

Note

To setup your alert receiver, with Amazon SNS, follow this documentation

Deploy an example Java application

In this section we will reuse an example from the AWS OpenTelemetry collector repository. For convenience, the steps can be found below.

1. Clone repository

git clone https://github.com/aws-observability/aws-otel-test-framework
cd aws-otel-test-framework/sample-apps/jmx/

2. Authenticate to Amazon ECR

export AWS_ACCOUNT_ID=`aws sts get-caller-identity --query Account --output text`
export AWS_REGION={region}
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com

3. Create an Amazon ECR repository

aws ecr create-repository --repository-name prometheus-sample-tomcat-jmx \
 --image-scanning-configuration scanOnPush=true \
 --region $AWS_REGION

4. Build Docker image and push to ECR.

docker build -t $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/prometheus-sample-tomcat-jmx:latest .
docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/prometheus-sample-tomcat-jmx:latest

5. Install sample application

export SAMPLE_TRAFFIC_NAMESPACE=javajmx-sample
curl https://raw.githubusercontent.com/aws-observability/aws-otel-test-framework/terraform/sample-apps/jmx/examples/prometheus-metrics-sample.yaml > metrics-sample.yaml
sed -i "s/{{aws_account_id}}/$AWS_ACCOUNT_ID/g" metrics-sample.yaml
sed -i "s/{{region}}/$AWS_REGION/g" metrics-sample.yaml
sed -i "s/{{namespace}}/$SAMPLE_TRAFFIC_NAMESPACE/g" metrics-sample.yaml
kubectl apply -f metrics-sample.yaml

Verify that the sample application is running:

kubectl get pods -n $SAMPLE_TRAFFIC_NAMESPACE

NAME                              READY   STATUS              RESTARTS   AGE
tomcat-bad-traffic-generator      1/1     Running             0          11s
tomcat-example-7958666589-2q755   0/1     ContainerCreating   0          11s
tomcat-traffic-generator          1/1     Running             0          11s