Sunday, January 19, 2014

Deploying New Relic on Azure



I created a New Relic account a while ago, but never got around to deploying it, and then when I tried to log in again it told me
a) my account was not verified, I needed to click the verification link in the email
b) the verification link in the email was not valid
I emailed support and never heard back, so just gave up on it.

Today I saw they were doing a new promotion of access to Tutes+, which looked useful, so I figured it was time to sign up for a new account (as the old one was completely empty anyway, easier to abandon it than work through support). I signed up for a new account and chose to deploy the python agent. They provided some pretty easy-looking instructions, and I went to open up the django local copy of my python site, and it wouldn't run. Somehow, I have no idea why, I seem not to have python2.7 on my machine any more. So I had to reinstall that, following the steps at http://docs.python-guide.org/en/latest/starting/install/win/. Since I was resetting it all, I figured I'd try better practices this time and installed virtualenv as well.

C:\Dropbox\code\optimization\SimplySchedule>virtualenv --python=C:\Python27\python27.exe scheduler

(env)>pip install newrelic

....
   ***************************************************************************

   WARNING: The optional C extension components of the Python agent could
   not be compiled. This can occur where a compiler is not present on the
   target system or the Python installation does not have the corresponding
   developer package installed. The Python agent will instead be installed
   without the extensions. The consequence of this is that although the
   Python agent will still run, JSON encoding/decoding speedups will not be
   available, nor will some of the non core features of the Python agent.

   INFO: Only pure Python agent was installed.

   ***************************************************************************
....

I guess I probably don't have a C compiler installed, now I feel bad.

but....then it said I needed to relaunch the app with a different init string. Or, since I don't have access to actually do the launching, I need to edit the wsgi file.
modify the WSGI script file/module for your web application and insert at the start of that file:
import newrelic.agent
newrelic.agent.initialize('newrelic.ini')
I had no idea where that was at first, but after some googling (and temporary confusion between this and the wfastcgi.py file) I found the wsgi file in django.core and added those lines, but got an import error trying to start the server. I eventually realised that I had installed newrelic for python3, not python2 (sigh) but while noodling around looking for hints on that, I found a more detailed new relic setup guide which mentioned you should edit the newrelic.ini file to choose a real log file location and set the name of the app. So I did pip2 install newrelic, copied the files to the site-packages directory, and python27 manage.py runserver : everything works!

While I was fiddling with everything, I also took the time to set up a slightly more useful index/home page for the site. Then when I went to push to github for deployment (which is super nice) the local repository wasn't associated with the remote - maybe I lost all the old settings when I installed windows 8.1 over the preview? So I also had to reassociate my local copy of the repository with github to push to that - and it's running with the new pages :)
Post a Comment