A
A
Alexey Kuzmin2013-11-15 08:34:21
Django
Alexey Kuzmin, 2013-11-15 08:34:21

Using New Relic in Django projects?

All health!
Who used New Relic in Django projects, please tell us about how to use it =) (step by step)
When registering, a new user is given Gold mode for 14 days, but it is not possible to use it (no data appears in the panel). I spent a couple of evenings on screwing: I found this lib + docks on the New Relic website
PS: raised on Python 2.7, virtualenv, Django 1.5.5, Ubuntu 12.04. The project is launched on a bunch of Nginx & uWSGI

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladimir Sokolovsky, 2013-11-15
@inlanger

Python agent installation instructions - https://docs.newrelic.com/docs/python/python-agent-installation

Instructions for setting it up on uwsgi - https://docs.newrelic.com/docs/python/python-agent-and-uwsgi

Just add "newrelic-admin run-program" before the uwsgi run command and specify the path to the settings:

NEW_RELIC_CONFIG_FILE=newrelic.ini newrelic-admin run-program uwsgi --socket /tmp/uwsgi.sock --single-interpreter --enable-threads wsgi.py

A
Alexey Kuzmin, 2013-11-16
@DrMartiner

Let's go sequentially.
1. generated newrelic.ini:

newrelic-admin generate-config bbf3ab09ff newrelic.ini

2. modified project/wsgi.py:
import os
newrelic.agent.initialize('/home/username/path/to/myproject/newrelic.ini')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings") 
from django.core.wsgi import get_wsgi_application 
application = get_wsgi_application()
application = newrelic.agent.wsgi_application()(application)

3. added the last line to /etc/uwsgi/apps-available/myapp.ini
[uwsgi]
workers = 2
processes = 2
autoload = true

env = DJANGO_SETTINGS_MODULE=project.settings
module = project.wsgi

log-date = true

chdir = /home/www/%n/
virtualenv = /home/www/%n/.env/
pythonpath = /home/www/%n/

harakiri = 30
no-orphans = true
reload-mercy = 8
max-requests = 5000

eval = import newrelic.agent, wsgi; application = newrelic.agent.wsgi_application()(wsgi.application)

And... ...it didn't work :(
What could be the problem? Perhaps you need to run a separate uWSGI service?
PS: if you execute newrelic-admin validate-config newrelic.ini, then everything is fine - requests go to the test project.

M
Michael, 2013-11-17
@MikeVL

Here is the config for running a Django project with New Relic via supervisor:

[program:django]
user = www-data
command = newrelic-admin run-program /usr/local/bin/uwsgi
  --module 'project.wsgi:application'
  --socket /tmp/%(program_name)s_%(process_num)02d.sock
  --processes 1
  --threads 6
  --single-interpreter
  --enable-threads
  --vacuum
  --need-app
  --log-x-forwarded-for
  --buffer-size 32768
  --post-buffering 65536
  --disable-logging

environment =
  NEW_RELIC_CONFIG_FILE="/etc/project/newrelic.ini",
  DJANGO_SETTINGS_MODULE="project.settings"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question