Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Django New Relic Systemd service Not working

django
apm
ubuntu
gunicorn

#1

Unable to collect any data into newrelic.
Running on Ubuntu 16.04.1 LTS, Django==2.0, gunicorn==19.6.0, newrelic==2.98.0.81

Following is the /etc/systemd/system/gunicorn.service file

[Unit]
Description=gunicorn daemon
After=network.target

[Service] 
User=ubuntu 
Group=www-data 
Environment=NEW_RELIC_CONFIG_FILE=/PATH/TO/newrelic.ini
Environment=NEW_RELIC_ENVIRONMENT=staging
WorkingDirectory=PATH/TO/PROJECTROOT
ExecStart=/PATH/TO/venv/bin/newrelic-admin run-program /PATH/TO/venv/bin/gunicorn --workers 3 --timeout 1800 --bind unix:/PATH/TO/project.sock project.wsgi:application --access-logfile /var/log/gunicorn_project/access.log --error-logfile /var/log/gunicorn_project/error.log

[Install]
WantedBy=multi-user.target

I have tested the config file, and it works. newrelic-admin validate-config newrelic.ini.
Also, no errors as such while running the gunicorn.service.

systemctl status gunicorn gives

ubuntu@XX-X-XX-XXX:~$ systemctl status gunicorn
● gunicorn.service - gunicorn daemon
   Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2018-02-10 06:17:20 UTC; 23min ago

Still no data inside the APM.


#2

@anurag722 Thanks for you post and also for opening the support ticket regarding this issue. In the support ticket, I asked for clarification on whether your Django app was getting traffic during the time your collected agent logs. I also asked if you can try starting the app from the command line to see if we can isolate an issue with your Systemd config.


#3

Hi,

I’m wondering if there were any progress regarding this issue. Since I have a similar problem, however with Django==1.11.14, uWSGI==2.0.15, newrelic==4.4.1.104(Tried multiple older versions as well with no success).

Where we run uWSGI with emperor mode.

newrelic-admin validate-config newrelic.ini posts data for me as well, but I capture no data for the web application.


uwsgi.service:

[Unit]
Description=uWSGI Emperor
After=syslog.target

[Service]
Environment=EMPEROR=/path/to/vassals/configs/
Environment=LOGTO=/var/log/uwsgi/emperor.log


Environment=NEW_RELIC_CONFIG_FILE=/path/to/newrelic.ini
Environment=NEW_RELIC_ENVIRONMENT=develop
Environment=NEW_RELIC_LICENSE_KEY=<KEY>
Environment=NEW_RELIC_APP_NAME=myappname
Environment=NEW_RELIC_LOG=/var/log/uwsgi/newrelic.log

WorkingDirectory=/path/
ExecStartPre=/bin/bash -c 'mkdir -p -m 1775 /run/uwsgi && chown root:app-data /run/uwsgi'
ExecStop=/bin/bash -c '/path/to/env/bin/newrelic-admin run-program /usr/local/bin/uwsgi --emperor "/path/to/vassals/configs/" --logto /var/log/uwsgi/emperor.log --stop'
ExecStart=/bin/bash -c '/path/to/env/bin/bin/newrelic-admin run-program /usr/local/bin/uwsgi --emperor "/path/to/vassals/configs/" --logto /var/log/uwsgi/emperor.log'
ExecReload=/bin/bash -c '/path/to/env/bin/bin/newrelic-admin run-program /usr/local/bin/uwsgi --emperor "/path/to/vassals/configs/" --logto /var/log/uwsgi/emperor.log --reload'
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardOutput=syslog
StandardError=syslog
NotifyAccess=all

[Install]
WantedBy=multi-user.target

I’m aware of what is mentioned regarding uWSGI and master process

Hence (at least) these parameters can be found in uwsgi.vassal config (cropped):

...
master = true
processes = 4
module = django.core.wsgi:get_wsgi_application()
...
enable-threads = true
single-interpreter = true
lazy-apps = true
...

I’m still experiencing what is described regarding master process, lazy loading, etc:

If using a master process and you are seeing no data being reported for the web application running in the worker processes, you should also use lazy loading mode

Even though lazy-apps = true is set.

It shall also be said that I’m able to capture data from background tasks, but nothing regarding our web application.

Let me know if you’re interested in anything else regarding our setup.

Thanks.


#4

@petter1 Could you send a permalink to your application? I want to make sure I’m looking at the same app/data you are.


#5

@petter1 I was wondering if you could try [manual integration]( Manual integration in app code) of the Python agent. It could be possible that using emperor mode in that fashion is preventing the agent from starting in the uwsgi workers. If you are still having issues after trying that method, let me know! Could you also send me a permalink to your app?


#6

@eileen I got it to work by not using NEW_RELIC_CONFIG_FILE and instead configure the client only through env-variables.

Although, if I remember correctly I think I attempted to initialise each worker manually (unsuccessfully) along these lines in the vassal config:

eval = import newrelic.agent; newrelic.agent.initialize('/path/to/newrelic.ini'); import django.wsgi; application = newrelic.agent.wsgi_application()(django.wsgi.application)

#7

@petter1 Thanks for updating us with a solution that worked for you! I’m glad to hear it’s working for you now.