Before You Begin
- Confirm you have access to a 4.1 or later AppDynamics controller:
- If you use a SaaS controller, AppDynamics sent you the controller host name in your Welcome email.
- If you use the on-premise controller, you supplied the host and port when you installed the controller.
- Verify that your Python environment meets the following requirements:
- CPython 2.6 or CPython 2.7
- pip 1.4 or later
- access to the Python Package Index (https://pypi.python.org/) by the machine on which you will install the agent
- Verify that you have a WSGI-based application to monitor. See Supported Environments and Versions for Python.
- If the application that you will monitor runs in a virtual environment, activate the virtual environment. This is not necessary if the application runs in the global Python environment.
Example of activating a virtual environment:
Install the Agent
The machine that the application is running on must have access to the Python Package Index (https://pypi.python.org/).
To install the agent package in the virtual environment you need to be the user who owns that virtual environment. Install the agent into the virtual environment after you have activated it.
If the application uses the global Python environment, you need to run the install command as root.
To install or upgrade to the latest 4.1.x version of the agent and its dependencies, run the pip install command as follows:
This command works for new Python agent installations, upgrades from 4.0 to 4.1, and upgrades from 18.104.22.168 to a later 4.1 patch release.
When there are multiple packages, you can locate the agent using the
pip list command or using the List packages facility at https://pypi.python.org/pypi and then find "appdynamics" in the output. Here is sample output from the List packages command:
For production deployments, AppDynamics recommends that you freeze the versions of dependencies so that they are not upgraded in production without first being deployed to your test/staging environments. The command to install (or upgrade to) a particular version of the AppDynamics Python Agent is:
This command always installs the exact same version of the agent each time it is run.
Configure the Agent
Provide a configuration file that specifies at least the minimal AppDynamics settings for communication between the agent and the controller.
The configuration file should be in the Python ConfigParser format. The Python application user must have read access on the configuration file.
Note that lines in the configuration file must not start with spaces. Lines that begin with a # are comments and are ignored by the agent,
Here is a simple sample configuration file with the minimal settings.
The ssl setting is off by default. Set it to on if you are connecting to the controller via SSL.
The account is required if you are using a SaaS account or a multi-tenant on-premise controller. It defaults to customer1 for a single tenant controller.
The accesskey is required for all controllers. To find your account name and access key, click the settings (gear) icon in the upper right corner of the AppDynamics UI, then click License.
You can store this configuration file anywhere.
When you instrument an application using
pyagent run, you pass the configuration file's path as a parameter to the pyagent run command. In other deployments set the APPD_CONFIG_FILE environment variable as illustrated below in the samples for uWSGI with Emperor and Apache with mod_wsgi.
Instrument the Application
Which instrumentation instructions to uses depends on how the application is deployed.
There are three deployment options.
In addition, irrespective of your Python environment, if you built your application using PasteDeploy, you have the option of instrumenting it with the Python Agent it by modifying your PasteDeploy configuration. See PasteDeploy.
If you can control the way your WSGI server is invoked, you can instrument the application using
pyagent run. This command runs your WSGI server with the Python agent enabled. This option is generally possible if you use a process launcher/manager that takes a command to execute; for example, frameworks managed by Supervisor, uWSGI without Emperor, init.d scripts, etc.
To use the
pyagent run command, prepend to your existing application run command the
pyagent run command, passing the AppDynamics configuration file described in Configure the Agent as a parameter.
Do not overwrite PYTHONPATH for any reason, because this will prevent the
pyagent run command from loading the agent. If you need to add to the PYTHONPATH, use the pythonpath configuration variable. For example, these commands add /foo and /bar to the PYTHONPATH instead of overwriting it:
but DO NOT DO THIS:
Important for Supervisor Users
After updating your Supervisor configuration you must use the supervisorctl reload command to get the Python agent loaded. Supervisor does not re-read its configuration files when you use the supervisorctl restart command.
To verify that the agent was loaded, look for the Python agent log file. Its default location is /tmp/appd/logs/<app_name>-<node_name>.log. For example, if your application name is "myapp" and your node name is "mynode" as specified in the agent configuration file, and you have not changed the location of the log file, the log file will be /tmp/appd/logs/myapp-mynode.
If the log file exists, the agent was loaded. If the log file does not exist, the agent was not loaded, in which case you should try reloading the Supervisor configuration with supervisorctl reload.
Django and Flask
If your framework is Django or Flask, all you need to do is prepend the
pyagent run to your run command.
If your current run command looks like this:
replace it with this:
Other Pure Python WSGI-Based Frameworks
If you use a WSGI-based framework that is not Django or Flask:
- In the AppDynamics configuration file, specify your actual WSGI application by setting the APPD_WSGI_MODULE directive to point to your app module. See Python Agent Settings.
- Prepend the
pyagent runto your run command.
- Run the Appdynamics-generated application.
If your run command looks like this:
replace it with these two commands:
uWSGI with Emperor
If your environment is uWSGI with Emperor, you need to modify your WSGI configuration files and then manually launch the proxy.
To instrument an application for uWSGI with Emperor:
- Create the configuration file described in Configure the Agent.
Modify the uWSGI configuration file. Do one of the following, depending on whether the configuration uses a module directive or a wsgi-file directive:
If the uWSGI configuration has a module directive like so:
modify that configuration by changing the module setting and adding the APPD_WSGI_MODULE and APPD_CONFIG_FILE settings to look like this, assuming that you have stored the configuration file in /etc/appdynamics.cfg:
If the uWSGI configuration has a wsgi-file directive like so:
modify that configuration to look like this, assuming you have stored the configuration file in /etc/appdynamics.cfg:
Before running any traffic through the instrumented application, manually launch the proxy by executing:
Apache with mod_wsgi
The Python Agent supports only mod_wsgi configurations that use
WSGIScriptAlias pointing to a single WSGI file. For example, the following type of configuration is supported:
If, instead, the script alias points to a directory, or if they are using the
WSGIScriptAliasMatch directive, contact email@example.com to discuss how the Python Agent can be deployed in your environment.
If the environment is Apache with mod_wsgi with a supported configuration as described above, you need to modify their mod_wsgi configuration files and manually launch the proxy.
To instrument an app for Apache with mod_wsgi:
- Create the configuration file described in Configure the Agent.
Modify the mod_wsgi configuration file.
If the mod_wsgi configuration file has an entry like this:
modify it to look like this, assuming that you have stored the configuration file in /etc/appdynamics.cfg:
Before running any traffic through the instrumented app, manually launch the proxy by executing:
You can instrument a Python application built with PasteDeploy by modifying your PasteDeploy configuration to use a composite factory supplied by AppDynamics. This feature can be used to instrument applications described by the other deployment options if they were built with PasteDeploy.
The AppDynamics composite factory is named "egg:appdynamics#instrument". It requires a parameter named "target" that points to the application to the original application and the full path to the APPD_settings.
To instrument an application built with PasteDeploy:
Manually launch the AppDynamics proxy:
In the PasteDeploy configuration file, rename the existing composite to a unique name.
For example, if the existing composite configuration for an application named "metadata" is:
you could rename it:
Create a new composite section for the "metadata" application above the original one that you just renamed.
Give the name of the old renamed application to the new composite application.
Configure it to use the AppDynamics composite factory: egg:appdynamics#instrument.
Set its target to the renamed application.
Set the APPDYNAMICS configuration file environment variable to the path of your AppDynamics configuration file.
You can also set other APPD_ configuration variables here. For example: "APPD_LOGS_DIR=/var/log/appdynamics".
- Restart the application.