18

I am using Django and trying out New Relic. Is it possible to monitor the Django development server? I can only seem to find help on setting up New Relic with production servers.

Edit

'How to' for future reference:

(I used Django1.4)

  1. Follow this: https://newrelic.com/docs/python/python-agent-installation

  2. As the last step of that guide (Integration with your Application) change your wsgi.py file to the following:

    import newrelic.agent
    
    newrelic.agent.initialize('/home/username/path/to/myproject/newrelic-1.9.0.21/newrelic.ini')
    
    import os
    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)
    

Now sign in to your account on the New Relic platform, make a few requests to your development server and see the changes on the the platform. Grats, you made it!

Alasdair
  • 298,606
  • 55
  • 578
  • 516
Bentley4
  • 10,678
  • 25
  • 83
  • 134
  • @Alasdair ```newrelic.agent.initialize('/home/username/path/to/myproject/newrelic-1.9.0.21/newrelic.ini')``` newrelic.ini is supposed to be present int the python executable location right? Not sure if this is obsolete now. – Atom Apr 21 '19 at 16:56
  • @Atom The `newrelic.agent.initialize()` line was added by Bentley4 *after* I answered the question, so I can't help with that. If you're stuck, I would ask a new question instead of adding comments to a 6 year old question. – Alasdair Apr 21 '19 at 17:34
  • 1
    I got it to working. I have to point it to the newrelic.ini present in the python executable location. Thanks @Alasdair – Atom Apr 21 '19 at 19:26

1 Answers1

11

As of Django 1.4, the startproject command creates a wsgi file that the runserver command will use.

If you have an older Django project that does not have a wsgi file, you can create one as described in the Django docs, and set WSGI_APPLICATION in your settings.py file.

You should be able to set up new relic by modifying this wsgi file as described by the New Relic docs for Python agent integration.

Alasdair
  • 298,606
  • 55
  • 578
  • 516