Agent Deployment for Docker Environment
Cavisson monitoring agent provides a user full-stack visibility into the performance of applications, databases, and micro services within a container environment. There are two agents, one is machine agent, and another is application agent. Machine agent is CMON and application agent is ND Agent.
This document explains the deployment of the ND agent for Java applications in a Docker container. The details are described in the following sections.
Install Cavisson Java agent for Docker
The following two options are available for installing agent in docker container:
- Create new docker image file by extending application docker file FROM <application image name>.
- Modify application docker image
In both the approaches, use the below mentioned steps to modify or create docker file. The required configurations for Java agent in a Docker container are also described.
Download Java Agent and Set-Up the Installation Directory
Download java agent build .tar or RPM package file to a temporary directory from Cavisson Build hub machine. Follow the below steps to copy the Java agent to the machine where the docker image file for application will be created:
- Obtain the tar compressed build or RPM package. Its format is X.X.X.XX.tar.gz (netdiagnostics.X.X.X.XX.rpm) where ‘X.X.X’ is the product release version and ‘XX’ is the build number.
- Copy the downloaded java agent .tar or RPM file to “./netdiagnostics” or any other desired folder.
- Add command in docker image file to copy and extract java agent .tar file in docker container.
ADD./netdiagnostics/netdiagnostics.X.X.X.XX.tar.gz
/export/cavisson/netdiagnostics/
- In case of RPM package, add below command in docker image file to install RPM package.
rpm -ivh –prefix=/home/netstorm/cavisson “cmon-nd-x-x.x.x.x.rpm”
Following directory structure is created when Java agent is extracted inside docker container:
- lib: Contains essential library and jars required by the agent.
- etc: Contains version information.
- logs: Contains debug and error log files created by the agent.
- config: Contains important configuration files that are required by the agent during startup.
- samples: Contains sample files for configuration.
Modify Application Startup Scripts
The startup script that contains the command to start the application server must include Java’s built-in argument ‘-javaagent’. Set this argument with the JAVA_OPTS environment variable. The value of that argument must contain the location where the Java APM agent’s jar file is added to the image.
For example, with Tomcat, use commands like these in the Dockerfile:
JAVA_OPTS=”$JAVA_OPTS javaagent:/export/cavisson/netdiagnostics/lib/ndmain.jar=time,ndAgentJar=/export/cavisson/netdiagnostics/lib/ndagent-with-dep.jar”
Set Java Agent Configurations
By default, Java agent behavior is controlled by configuration entries in ndsettings.conf , which is typically located in the same directory where the agent build is extracted. This section explains how to override configurations settings.
Follow the below mentioned steps for Java agent configuration:
- Create configuration file conf under ‘./netdiagnostics’ directory or the directory where Java agent .tar file is copied with following entries:
tier=<TierName>
server=<server name>
instance=<Instance name>
ndcHost=<NDCHost>
ndcPort=<NDCPort>
Example:
For profiling single application on a VM, config file name is ndsettings.conf.
Sample content:
tier=AppTier
ndcHost=10.206.249.62
ndcPort=7892
- Tier: Name of the logical tier of application to be monitored using java agent.
- Server: The display or actual name of the server where the agent is running. This can take both hostname and IP. This is optional field.
- Instance: The name of the standalone application instance or managed instances. This is optional field.
- ndcHost: IP Address or Host name of NS controller box to which agent installed communicate.
- ndcPort: Port number of NS controller box.
- Add below command in docker file to copy ndsetting.tar file in docker container.
ADD ./netdiagnostics/ndsettings.conf
/export/cavisson/netdiagnostics/config/ndsettings.conf
- Rebuild and start docker container instance.
Appendix – Sample Files
Approach 1
Create New Docker image file extending existing application image.
AppImage refers to existing image name already built for application which is present at working directory /opt/app and is exposed to 4655 port for receiving traffic. The jar being executed is SampleApplication.jar.
FROM AppImage
ADD ./netdiagnostics/netdiagnostics.4.2.1.23.tar.gz /export/cavisson/netdiagnostics/
ADD ./netdiagnostics/ndsettings.conf /export/cavisson/netdiagnostics/config/ndsettings.conf
EXPOSE 4655
WORKDIR /opt/app
CMD [“java”,”-jar”,”-javaagent:/export/cavisson/netdiagnostics/lib/ndmain.jar=time,ndAgentJar=/export/cavisson/netdiagnostics/lib/ndagent-with-dep.jar,ndHome=/export/cavisson/netdiagnostics”,”SampleApplication.jar”]
Approach 2
Modify in existing Docker image file.
Following example refers to a jar named SampleApplication.jar being exposed at port 4655 and present at /opt/app in container. Agent is installed by modifying existing Dockerfile.
FROM openjdk:11
RUN mkdir -p /opt/app
ADD SampleApplication.jar /opt/app/SampleApplication.jar
ADD ./netdiagnostics/netdiagnostics.4.2.1.23.tar.gz /export/cavisson/netdiagnostics/
ADD ./netdiagnostics/ndsettings.conf /export/cavisson/netdiagnostics/config/ndsettings.conf
EXPOSE 4655
WORKDIR /opt/app
CMD[“java”,”-jar”,”-javaagent:/export/cavisson/netdiagnostics/lib/ndmain.jar=time,ndAgentJar=/export/cavisson/netdiagnostics/lib/ndagent-with-dep.jar,ndHome=/export/cavisson/netdiagnostics”,”SampleApplication.jar”]