How to setup monitoring for your Django app using New Relic
April 23, 2021 - by Themba Mahlangu - 1 min read
¶
Introduction
In this short guide, you will learn how to set app monitoring for your Django app using New Relic.
¶
Prerequisites
To complete this tutorial, you will need:
Django Starter Project
New Relic Account (Free Forever) - Sign up
[
here
](https://newrelic.com/pricing?utm_campaign=Brand-BeNeLux&utm_medium=cpc&utm_source=google&utm_content=PRICE_LP&fiscal_year=FY21&quarter=Q4&gtm=DEV&program=EVERBRAND&ad_type=None&geo=BENELUX&utm_term=new%20relic%20account&utm_device=c&_bt=497422423164&_bm=e&_bn=g&gclid=CjwKCAjwq7aGBhADEiwA6uGZp39keLNuuENNiIeBOSf3dB8HkU7zoHIlx96wk8PjBGlVawPz-RadVhoC98YQAvD_BwE)
¶
Set up the python agent.
Install the New Relic Python agent. See more detailed instructions
here
.
text
`# using pip
$ pip install newrelic
# add it to your requirements.txt file and specify the package version
...
new_relic==n.n.n.n`
¶
Configuration
Next, you will add the newrelic.ini config file. The config file allows you to specify custom behaviour for the Python agent.
You can generate a config file using the command below.
text
`# this will generate a new config file.
# you can retrieve YOUR_LICENSE_KEY from the dashboard when you sign up.
newrelic-admin generate-config YOUR_LICENSE_KEY newrelic.ini`
If you control how your application is started you will have to modify your startup command to include the newrelic_admin command before your command options. Some practical examples are below.
text
`# generic
NEW_RELIC_CONFIG_FILE=newrelic.ini newrelic-admin run-program YOUR_COMMAND_OPTIONS
# example - For deployments to Heroku modify the procfile.
web: newrelic-admin run-program bin/start-pgbouncer-stunnel gunicorn config.asgi:application -k uvicorn.workers.UvicornWorker
# docker file example
CMD NEW_RELIC_CONFIG_FILE=newrelic.ini newrelic-admin run-program gunicorn -b :$PORT main:app
`
Under the hood, the agent intercepts incoming /outgoing events to and from your
ASGI
/
WSGI
callable.
¶
Restart your application
Once you restart your application, and wait for 5 minutes, you should be able to see some action on the dashboard.
¶
Conclusion
That took less than ten minutes, but it could save you lots of debugging time later on. The dashboard has a host of other tools and options that we will be exploring in a more detailed post later.