I have been currently trying to connect VisualVM (A program which monitors the JVM, heap and memory usage etc) to a Spring Boot Application (Java App) running on AWS Fargate in Docker containers.
I have been exposing the JMX ports accordingly and I am able to connect through the JMX ports when running the Docker container locally. However, when running the Java App on Fargate, I have not found a way to connect to the Container through JMX. I have tried setting the VM argument -Djava.rmi.server.hostname to the IP Address of the container, but when I try to connect through JMX it still fails to do so. Has anyone had any experience with this?
JMX commands for reference:
-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.local.only=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-Djava.rmi.server.hostname=172.17.0.2 \
-Dcom.sun.management.jmxremote.port=9090\
-Dcom.sun.management.jmxremote.rmi.port=9090\
-jar java-api.jar server```
This means that a vCPU is essentially the same as an EC2 instance vCPU. From the docs: Amazon EC2 instances support Intel Hyper-Threading Technology, which enables multiple threads to run concurrently on a single Intel Xeon CPU core. Each vCPU is a hyperthread of an Intel Xeon CPU core, except for T2 instances.
Fargate is the better option for ease of use as it takes infrastructure management out of the equation allowing you to focus on just the tasks to be run. It works great for most workloads and enables a faster pace of operations.
Fargate removes the need to provision and manage servers. Instead, you simply specify the resources per task, which also improves security through application isolation by design. ECS then communicates with Fargate to launch, run, and manage the containers on your behalf.
In the Service Quotas console, you can visualize your usage on a graph and configure alarms that alert you when your usage approaches a service quota. For more information, see AWS Fargate usage metrics .
Amazon ECS is a highly scalable, high-performance container orchestration service that supports Docker containers and allows you to easily run and scale containerized applications on AWS. AWS Fargate is a compute engine for Amazon ECS that allows you to run containers without having to manage servers or clusters.
Fargate On-Demand usage combines Amazon EKS pods using Fargate, Amazon ECS tasks using the Fargate launch type and Amazon ECS tasks using the FARGATE capacity provider. The class of resource being tracked. Currently, AWS Fargate does not use the class dimension.
The Applications Manager briefing documents stress that the JVM monitoring tool focuses on how JVM manages the memory allocation and release processes. There is a lot more to JVM memory usage and the Applications Manager covers all of those issues. The Applications Manager isn’t just a JVM monitoring tool.
Following changes worked for me in connecting Visual VM to Spring Boot Application deployed in AWS Fargate (private VPC)
-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=1099 \
-Dcom.sun.management.jmxremote.rmi.port=1099 \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.local.only=false \
-Djava.rmi.server.hostname=127.0.0.1
export port 1099 (both in dockerfile and cloudformation template - PortMappings->ContainerPort)
Container security group to accept incoming traffic on 1099 (tcp and udp) from one of the existing EC2 in vpc (jump server)
ssh port forwarding by using EC2 (jump server) to task running in fargate (use private ip of task running in fargate)
run following command on local
ssh -l <user> -L 127.0.0.1:1099:<task-private-ip-in-fargate>:1099 <ec2-ip(jump server)>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With