Tracking Java Usage in a Container

You can track Java usage of Java applications running in a container using JMS Fleets. This section exemplifies how to configure a container using a docker image.
Note

Only containers with Oracle JDKs are detected.
Prerequisites:
  • You've completed Installing Management Agent and Deploying JMS Plug-in on your container host. The container host can be a compute instance on your premises, on OCI, or on any other cloud platform.
  • Docker image is stored in the container host. The image contains one or more Java applications (jar files), the Oracle JDK, and other dependencies required to run your Java applications.
  • Docker is installed in the container host.

To track Java usage in a container:

  1. Ensure that Java Usage Tracker records are written to /var/log/java/usagetracker.log. Use the following command to start a container.
    Note

    You should only use this configuration with trusted containers or where you don't require isolation between the host container and the container, or between containers. If you require isolation, you should use a separate usagetracker.log file for each container and aggregate those logs into /var/log/java/usagetracker.log on the container host.
    docker run -d -v /var/log/java/:/var/log/java/ -v /etc/oracle/java/:/etc/oracle/java/:ro --name <container_name> <docker_image>:latest
    • -d starts the container as a daemon process.
    • -v /var/log/java/:/var/log/java/ maps the bind mount /var/log/java/ on the container host to /var/log/java/ in the container. This ensures the /var/log/java/usagetracker.log file in the container is present in the container host.
    • -v /etc/oracle/java/:/etc/oracle/java/:ro maps as a read-only bind mount /etc/oracle/java/ on the container host to /etc/oracle/java/ in the container. This ensures the /etc/oracle/java/usagetracker.properties file in the container is present in the container host.
    • --name <container_name> identifies the name on the container. Replace <container_name> with the name of your container
    • <docker_image>:latest indicates the use of the latest version of your image. Replace <docker_image> with the name of your docker image.
  2. Use docker inspect to verify that the bind mounts were created correctly in the container.
    docker inspect <container_name>

    Look for the Mounts section:

     "Mounts": [
                {
                    "Type": "bind",
                    "Source": "/var/log/java/",
                    "Destination": "/var/log/java/",
                    "Mode": "",
                    "RW": true,
                    "Propagation": "rprivate"
                },
                    "Type": "bind",
                    "Source": "/etc/oracle/java/",
                    "Destination": "/etc/oracle/java/",
                    "Mode": "ro",
                    "RW": false,
                    "Propagation": "rprivate"
            ],
  3. Verify the log file to validate it contains your Java applications (jar files) and the JDK version of your docker image.
    cat /var/log/java/usagetracker.log
  4. Include usagetracker.config to create a specific log file on the host.
    Copy usagetracker.properties from the host /etc/oracle/java to the current directory so you can include as part of a docker build.
    # usage tracker configuration
    RUN mkdir -p /etc/oracle/java/
    COPY ./usagetracker.properties /etc/oracle/java/
    RUN chmod 644 /etc/oracle/java/usagetracker.properties
    RUN sed -i "s/\usagetracker.log/usagetracker.log_${CONTAINER_NAME}/g" /etc/oracle/java/usagetracker.properties
  5. Ensure that Java Usage Tracker records are written to /var/log/java/ for each container. Use the following command to start a container:
    docker run -d -v /var/log/java/:/var/log/java/ --name <container_name> <docker_image>:latest
  6. Aggregate multiple usage files into /var/log/java/usagetracker.log on the the host.
  7. Check your Fleet in JMS to see if your Docker container was detected. You should be able to see the jar files of your Java applications under Applications.