You can configure the Python data collector to monitor on-premises Python applications running in individual Docker container. During data
collector deployment, the server information must be provided so that the data collector can be
configured to connect to the appropriate server. The server information is provided as a
configuration package for downloading from the Cloud App Management console.
About this task
To configure the Python data collector in
individual Docker container mode, do the following steps:
Procedure
- Update the Dockerfile to add the following lines to install Python data collectorfor your Python application. Add the
following lines in Dockerfile:
ADD ibm-cloud-apm-dc-configpack.tar /application/root/path
RUN mv /application/root/path/ibm-cloud-apm-dc-configpack /application/root/path/etc
ADD ibm_python_datacollector.tar.gz /application/root/path
RUN pip install --no-index --find-links=/application/root/path/python_dc ibm_python_dc
- Integrate the installed data collector in your Python
application:
- If your application is based on Django V1.10 or later versions, open
settings.py of your Django application, and add the following content into
first line of section MIDDLEWARE in that
file:
'ibm_python_dc.kpg_dc_django.ResourceMiddleware',
- If your application is based on Django V1.9 or older versions, add the following content
into the first line of the section MIDDLEWARE_CLASS in that
file:
'ibm_python_dc.kpg_dc_django.ResourceMiddleware',
- If your application is based on Flask, add the Python data collector wsgi middleware in your Python
application file, for example, if you run export FLASK_APP=run.py, then edit the
run.py file and ensure that the Python data collector wsgi middleware are added in front of
other middlewares. Example:
from flask import Flask
from flask_restful import Api
from api.board import Article
from api.auth import Login, Register, RefreshToken
from middleware import Test
from werkzeug.middleware.dispatcher import DispatcherMiddleware
api.add_resource(Login, '/login')
api.add_resource(Register, '/register')
from ibm_python_dc.kpg_dc_wsgi import ResourceMiddleware
app.wsgi_app = ResourceMiddleware(app.wsgi_app)
app.wsgi_app = DispatcherMiddleware(serve_frontend, {
'/test': test,
'/admin': admin,
})
......
......
- Build the new Docker image.
- Start your Python application with the new created Docker image.