Search code examples
pythondjangonewrelicsupervisord

Can't get Newrelic with gunicorn supervisor django 1.6 to work


Im trying to get NewRelic python agent to work with my setup with supervisor and gunicorn, but can't get it to work.

Here is my current supervisor setup that works:

[program:gunicorn]
directory = /home/<USER>/.virtualenvs/<DOMAIN>/myproject/
command=/home/<USER>/.virtualenvs/<DOMAIN>/bin/gunicorn my_project.wsgi:application

I tried to do this:

[program:gunicorn]
directory = /home/<USER>/.virtualenvs/<DOMAIN>/myproject/

#Working command
#command=/home/<USER>/.virtualenvs/<DOMAIN>/bin/gunicorn myproject.wsgi:application


command=/home/<USER>/.virtualenvs/<DOMAIN>/bin/newrelic-admin run-program /home/<USER>/.virtualenvs/<DOMAIN>/bin/gunicorn myproject.wsgi:application
environment=NEW_RELIC_CONFIG_FILE=/home/<USER>/.virtualenvs/<DOMAIN>/myproject/newrelic.ini

user = <USER>
autostart = true
autorestart = true
stderr_events_enabled = true
redirect_stderr = true
stdout_logfile = /home/<USER>/logs/gunicorn.log
stderr_logfile = /home/<USER>/logs/gunicorn_err.log

but then I get this error:

Traceback (most recent call last):
  File "/home/user/.virtualenvs/domain.com/lib/python2.7/site.py", line 688, in <module>
    main()
  File "/home/user/.virtualenvs/domain.com/lib/python2.7/site.py", line 679, in main
    execsitecustomize()
  File "/home/user/.virtualenvs/domain.com/lib/python2.7/site.py", line 547, in execsitecustomize
    import sitecustomize
  File "/home/user/.virtualenvs/domain.com/local/lib/python2.7/site-packages/newrelic-1.10.2.38-py2.7-linux-x86_64.egg/newrelic/bootstrap/sitecustomize.py", line 74, in <module>
    newrelic.agent.initialize(config_file, environment)
  File "/home/user/.virtualenvs/domain.com/local/lib/python2.7/site-packages/newrelic-1.10.2.38-py2.7-linux-x86_64.egg/newrelic/config.py", line 1456, in initialize
    log_file, log_level)
  File "/home/user/.virtualenvs/domain.com/local/lib/python2.7/site-packages/newrelic-1.10.2.38-py2.7-linux-x86_64.egg/newrelic/config.py", line 383, in _load_configuration
    'Unable to open configuration file %s.' % config_file)
newrelic.api.exceptions.ConfigurationError: Unable to open configuration file /.

The newrelic.ini file is on that path, so what am I doing wrong?

Edit:

Path to newrelic.ini file is:

/home/<USER>/.virtualenvs/<DOMAIN>/myproject/newrelic.ini

Solution

  • Environment needs quotes to work.

    Here is a working setup:

    [program:gunicorn]
    directory = /home/<USER>/.virtualenvs/<DOMAIN>/<PROJECT>/
    command=/home/<USER>/.virtualenvs/<DOMAIN>/bin/newrelic-admin run-program /home/<USER>/.virtualenvs/<DOMAIN>/bin/gunicorn <PROJECT>.wsgi:application
    environment=NEW_RELIC_CONFIG_FILE="/home/<USER>/.virtualenvs/<DOMAIN>/<PROJECT>/newrelic.ini"
    
    user = <USER>
    autostart = true
    autorestart = true
    stderr_events_enabled = true
    redirect_stderr = true
    stdout_logfile = /home/<USER>/logs/gunicorn.log
    stderr_logfile = /home/<USER>/logs/gunicorn_err.log