Poznámka
Na prístup k tejto stránke sa vyžaduje oprávnenie. Môžete sa skúsiť prihlásiť alebo zmeniť adresáre.
Na prístup k tejto stránke sa vyžaduje oprávnenie. Môžete skúsiť zmeniť adresáre.
This article describes how to get started using the Java Diagnostic Agent. It also describes the Java Diagnostic Tool on AKS plugin for IntelliJ IDEA.
The Java Diagnostic Agent is a Java agent for troubleshooting a Java process. It doesn't need to rebuild, redeploy, or restart an application. Currently, it supports adding logs around a function in a Java class. When the function is called, the log is printed along with a calculation of the total time consumed by the function.
Prerequisites
diag4j installed in your cluster.
Java LTS version 11, 17, or 21.
The IntelliJ IDEA plugin, installed locally through Settings > Plugins > Install Plugin from Disk.
Java applications to troubleshoot with. For more information, see Deploy Spring Boot Application to the Azure Kubernetes Service.
Establish port forwarding
Use the following command to establish port forwarding to the agent service:
kubectl port-forward svc/diag4j-agent-service -n <namespace> <port>:8080
Use the Java Diagnostic Tool on AKS plugin for IntelliJ IDEA
Use the Java Diagnostic Tool on AKS plugin to attach the Java Diagnostic Agent to the Java application running in a pod container on an Azure Kubernetes Service (AKS) cluster.
After you attach the agent, you can troubleshoot by adding logs around a class function. Use this log to test whether the function is executed and to calculate the total time spent in the function. This analysis can help you locate performance bottlenecks in your application.
The Diagnostic tab shows the plugin configuration. Here, you can:
- Configure the local port that forwards to the agent service.
- View the pods listed with
kubeconfigin your local environment. - Select Refresh to refresh the pod table. After you switch clusters, refresh the table to load the pods in new cluster.
Attach the agent
The pod container must have a /tmp folder, and it must have write permission to the /tmp folder.
To enable attaching the agent in the JVM, don't add -XX:+DisableAttachMechanism to the JVM options.
The backend diagnostic server closes after 6 hours.
To attach the agent, select the pod you want to attach the agent to, and then select the container. You can only attach the agent to one container in the pod. Then, wait for the attachment process to complete.
Set the active pod container
After you attach the agent successfully, use it for troubleshooting.
Multiple pods might have injected the agent, so you must set an active pod. In IntelliJ IDEA, on the Diagnostic tab, right-click a pod and then select Select as the active one.
Add logging around a class function
The configured log is automatically removed after 30 minutes.
You can use the tool to add logging around class functions, but not interfaces, constructors, and so on.
To add logging to a function, right-click it in the editor, and then select Java Diagnostic > Add AroundLog, as shown in the following screenshot.
In this example, after you add the logging, you can call <host>/infor to see output similar to the following example before and after the function is called:
===== START ===== Method: updateInformation Start Time: 2024-12-12T07:37:55.404107848Z
Done with the validation
Done with the DB access
Done with the data filtering
===== END ===== Method: updateInformation End Time: 2024-12-12T07:37:55.404316940Z Total Time: 0 milliseconds
Remove all configured logs
To remove all the logs that the agent adds, select Remove All AroundLogs.
Note
An ephemeral container in the pod uses the backend Java agent. After the pod restarts, the agent is removed.
Troubleshooting
A timeout can occur when you attempt to attach the agent to a pod running on a node that isn't already enabled for the feature. The timeout happens because the node first needs to retrieve the agent image, which causes a delay. When this delay occurs, select Refresh to check whether the agent is attached, or try attaching the agent again.
If the attachment fails, check the log named diagnostic-container-<hashcode> in the ephemeral container.
You can find information about the operations of the plugin in the logs under the pod container named diag4j-agent-service-<hashcode>.
Next step
Get started with the Spring Boot Admin component of the Java Diagnostic Tool (diag4j) on AKS