Skip to main content

Install Java Agent in Docker Environment

Prerequisites

  • The installer is familiar with the manual installation process of the Java Agent.
  • The Agent Collector has been installed.
  • Before installing the Agent, ensure that the local browser time, server time zone, and time are all consistent. If there are multiple servers, ensure that the local browser, all server time zones, and times are consistent. Otherwise, it may affect data accuracy, such as incorrect topology, etc.

Install Java Agent Inside Docker Container

  1. Use docker images to view local images.

    docker_deploy1

  2. Use the docker ps command to view running containers.

    docker_deploy2

  3. Run docker exec -it <container_id> /bin/bash.

    docker_deploy3

For other steps, please refer to the Manual Installation Guide.

Install Java Agent via Dockerfile

Installation by Modifying Configuration File

Take the Tomcat environment as an example. The Dockerfile is shown below: docker_deploy5

The related configuration for embedding the Agent is as follows:

docker_deploy6

Configuration details:

  1. Add the Agent installation package to the docker image and specify the extraction directory as /opt/apache-tomcat-8.5.11/.

    ADD tingyun-agent-java-3.4.6.zip /opt/apache-tomcat-8.5.11/

    Note: Some containers generated by Dockerfile do not support the unzip command. It is recommended to extract the Agent zip package first, repackage it as a tar.gz, and then upload it.

  2. Modify the tingyun.properties file and catalina.sh configuration file.

    1. Modify license_key.

      RUN sed -i 's/<%=license_key%>/oiHCIGbcaZ3Il4zd/' /opt/apache-tomcat-8.5.11/tingyun/tingyun.properties
    2. Add the address and port of the Agent Collector server.

      RUN sed -i 's/<%=collector_addresses>/tingyun.server.com:8080/' /opt/apache-tomcat-8.5.11/tingyun/tingyun.properties
    3. Modify the application name.

      RUN sed -i 's/Java Application/docker_appname/' /opt/apache-tomcat-8.5.11/tingyun/tingyun.properties
    4. Back up the modified script file.

      RUN cp /opt/apache-tomcat-8.5.11/bin/catalina.sh /opt/apache-tomcat-8.5.11/bin/catalina.sh.bak
    5. Add the Agent startup parameter.

      RUN sed -i '1a\export CATALINA_OPTS="$CATALINA_OPTS -javaagent:/opt/apache-tomcat-8.5.11/tingyun/tingyun-agent-java.jar"' /opt/apache-tomcat-8.5.11/bin/catalina.sh
    6. Run the docker build command to create an image containing the Java Agent.

      docker_deploy7

      docker_deploy8

  3. Based on the image, create and run a container, check the Agent logs and reports, and observe whether performance data is uploaded normally.

Installation by Adding JVM Parameters

Configure JAVA_OPTS, and add the following three parameters after -javaagent, separated by spaces:

-Dtingyun.app_name=${APP_NAME} -Dtingyun.license_key=${LICENSE_KEY} -Dtingyun.collector.addresses=${COLLECTOR_ADDRESSES}
- -Dtingyun.app_name: Application name, recommended to be the business name of the application.
- -Dtingyun.license_key: Associated with your Tingyun account. Data collected by the Agent will be uploaded to the account bound to this LicenseKey.
- -Dtingyun.collector.addresses: The address and port of the Agent Collector server, e.g., tingyun.server.com:8080. For high-availability deployment, be sure to configure all Agent Collector server addresses and ports in the same data center, separated by commas.