Skip to main content

Installing Docker Python

At the bottom of Management > Agent installation, click Install Application > Select the Docker Python tab in Install guide.

This process applies the WhaTap monitoring agent to the Python application running on the Docker container and packages the container image as follows. To release the Kubernetes application, the Docker image is required. Create a Docker image with the whatap-python package installed using the following process.

Note
  • EKS Fargate is to be supported later.

  • To help you understand the Python application integration process, Git example codes are provided. See the following.

Download agent

Install the whatap-python package when building your Python application docker image.

RUN pip3 install --upgrade whatap-python

See the following definition example of the following Dockerfile.

python ver 3.10
# Install python3.10 In the Docker environment.
FROM python:3.10

# Set the working directory to /app.
WORKDIR /app

# Copy all the files and folers in the current directory to the /app directory in the container.
ADD . /app/

# In Python, any external library can be installed using pip.
# Install the WhaTap Python agent when building the docker image.
RUN pip3 install --upgrade whatap-python

Configuration and execution of the agent

Before running the application, determine the Python agent's working directory and then create a default configuration file. Pass the authentication information to the agent and set whether or not to trace logs through the configuration file (entrypoint.sh).

Configuration file (entrypoint.sh) example
entrypoint.sh
#!/bin/bash

# Set the working directory of the container to the WhaTap path. The agent logs and configuration file are generated in the path.
export WHATAP_HOME=${PWD}

# If any permission error occurs, remove the following comment.
#chmod -R 777 $WHATAP_HOME

# The following lists the settings required for agent configuration. Configure them through the yaml file for release of applications.
whatap-setting-config \
--host $whatap_server_host \
--license $license \
--app_name $app_name \
--app_process_name $app_process_name

# The following comments are additionally configured for agent grouping and activation of log collection. Use them if necessary.

# Agent grouping
#echo "okind=$okind" >> whatap.conf

# Activation of log collection
#echo "logsink_enabled=true" >> whatap.conf
#echo "logsink_trace_enabled=true" >> whatap.conf
#echo "trace_logging_enabled=true" >> whatap.conf


# Add whatap-start-agent before the application startup command to run the agent.
whatap-start-agent uvicorn server:app --host 0.0.0.0 --port 8000
  1. Set the container's working directory with the WHATAP_HOME environment variable. Create the agent log and configuration files in the path.

    export WHATAP_HOME=${PWD}
  2. Execute the following command to create and configure the whatap.conf file in the path set as WHATAP_HOME. Variables marked with $ are required for agent configuration and are set through the yaml file for releasing the application.

    whatap-setting-config \
    --host $whatap_server_host \
    --license $license \
    --app_name $app_name \
    --app_process_name $app_process_name
  3. Run the agent by adding whatap-start-agent before the application startup command as follows:

whatap-start-agent uvicorn server:app --host 0.0.0.0 --port 8000
Caution

If any role issues, assign roles to the $WHATAP_HOME variable as follows:

echo `sudo chmod -R 777 $WHATAP_HOME`
Note

Script running example

See the following definition example of the following Dockerfile. This is a complete example to run the entrypoint.sh script.

FROM python:3.10
WORKDIR /app
ADD . /app/
RUN pip3 install --upgrade whatap-python

# Assign a role to run the entrypoint.sh script in the container.
RUN chmod +x ./entrypoint.sh

# Execute the entrypoint.sh script when generating the container.
CMD ["./entrypoint.sh"]

Additional function

The following settings are optional and must be used if necessary. In addition to the following additional settings in the configuration file (entrypoint.sh), log and transaction-related settings are also configurable. For additional settings, see the following.

  • Agent grouping

    echo "okind=$okind" >> whatap.conf
  • Enabling the log collection

    echo "logsink_enabled=true" >> whatap.conf
    echo "logsink_trace_enabled=true" >> whatap.conf
    echo "trace_logging_enabled=true" >> whatap.conf

Configuring the container environment variables

After building Docker, set container environment variables in the Kubernetes environment. Add the following items in the yaml file for releasing the application.

	  env:
- name: license
value: XXXXXXXXXXXXXX-XXXXXXXXXXXXXX-XXXXXXXXXXXXXX
- name: whatap_server_host
value: XXX.XXX.XXX.XXX
- name: app_name
value: {YOUR_APP_NAME}
- name: app_process_name
value: {YOUR_PROCESS_NAME}
- name: okind
value: {YOUR_GROUP_NAME}
- name: NODE_IP
valueFrom: {fieldRef: {fieldPath: status.hostIP}}
- name: NODE_NAME
valueFrom: {fieldRef: {fieldPath: spec.nodeName}}
- name: POD_NAME
valueFrom: {fieldRef: {fieldPath: metadata.name}}

See the following example:

apiVersion: apps/v1
kind: Deployment
metadata:
name: python-fastapi-deployment
spec:
replicas: 3
selector:
matchLabels:
app: python-fastapi-pod
template:
metadata:
labels:
app: python-fastapi-pod
containers:
- name: agent-python-fastapi
image: whatap/agent-python-fastapi
env:
- name: license
value: XXXXXXXXXXXXXX-XXXXXXXXXXXXXX-XXXXXXXXXXXXXX
- name: whatap_server_host
value: XXX.XXX.XXX.XXX
- name: app_name
value: "myapp-python-fastapi"
- name: app_process_name
value: "uvicorn"
- name: NODE_IP
valueFrom: {fieldRef: {fieldPath: status.hostIP}}
- name: NODE_NAME
valueFrom: {fieldRef: {fieldPath: spec.nodeName}}
- name: POD_NAME
valueFrom: {fieldRef: {fieldPath: metadata.name}}
Note

Roles of environment variables

  • license: Key for agent authentication.

  • whatap_server_host: Host IP of the WhaTap collection server

  • app_name: Name to identify the agent for the application. For more information about the agent identification, see the following.

  • app_process_name: Set the target processes such as CPU and Heap Memory. For example, there are uwsgi and gunicorn.

  • okind (optional): Groups applications for the Pod. If set using the deployment name, the corresponding Pods are grouped together.

  • NODE_IP: Collects the IP address of the node where the current Pod has been hosted.

  • NODE_NAME: Collects the name of the node where the current Pod is running.

  • POD_NAME: Collects the name of the current Pod.

Checking the agent installation

  • To check whether the agent has been installed, go to Dashboard > Application Service Dashboard.

  • Run the ps -ef | grep whatap_python command in the container to check whether the Whatap Python service is running normally.