Gunicorn¶
Gunicorn is a WSGI HTTP server for Python web applications. Librato’s Gunicorn instrumentation gives Python web developers access to essential performance and health metrics concerning their Python-based web applications running in Gunicorn.
Installation¶
Prequisites¶
You’ll need a Python-based web application running in Gunicorn on Python 2.7 or 3.
Create the Integration¶
To begin, navigate to the Integrations page. Select Gunicorn Monitoring to add your Gunicorn integration.
Provide a unique name for your your integration and click save.
A configuration snippet will appear containing basic instructions for instrumenting your Gunicorn application. Take note of the librato-config command with your Librato integration credentials:
Follow the steps below for each Gunicorn server your web application is running on.
Gunicorn Instrumentation¶
Install and configure the librato-python-web instrumentation using the commands provided in the integration settings.
$ pip install librato-python-web
$ librato-config --app-id gunicorn-prod-1 \
--user user@librato.com --api-token XXXXXXXXXXXX
The librato-config utility will create an agent-conf.json configuration file on your file system.
$ cat agent-conf.json
{
"integration": "gunicorn",
"metrics_hostname": "metrics-api.librato.com",
"hostname": "localhost",
"stop": false,
"app_id": "gunicorn-prod-1",
"no_aggregate_counters": false,
"pidfile": "/var/run/solarwinds-python-statsd.pid",
"flush_interval": 10000,
"daemonize": false,
"user": "user@librato.com",
"expire": 0,
"api_token": “XXXXXXXXXXXX”,
"debug": false,
"pct": 95,
"port": 8142,
"restart": false
}
There is no need to modify the default values unless the StatsD port happens to be used already. Simply replace the port value with an ephemeral port that is not in use.
Modify your startup script by prefixing the librato-launch command to your regular command arguments, making sure to include the --statsd-host
commandline option.
$ librato-launch gunicorn --statsd-host=127.0.0.1:8142 wsgi_app_module:app
Deploy your updated startup script and stop any running instances of your web application.
Start your web application from the folder containing the configuration file (the configuration file can be relocated as necessary). The librato-launch utility will run a bundled version of StatsD to aggregate and report metrics to Librato. We use a non-standard port (8142) by default to avoid conflicting with already running StatsD instances.
Gunicorn Workspace¶
You should now be able to see gunicorn.*
metrics in your Librato account. Navigate to Spaces to view your
Gunicorn dashboard.