From c0c0bc6ca3a5a1de3ea5837edb1816a2177cb3ef Mon Sep 17 00:00:00 2001 From: Amjith Ramanujam Date: Sun, 4 Oct 2015 05:06:20 -0700 Subject: [PATCH] Add newrelic for monitoring. --- README.rst | 3 +++ cookiecutter.json | 1 + {{cookiecutter.repo_name}}/app.json | 3 ++- {{cookiecutter.repo_name}}/config/settings/production.py | 5 +++++ {{cookiecutter.repo_name}}/config/wsgi.py | 9 +++++++++ {{cookiecutter.repo_name}}/requirements/production.txt | 6 ++++++ 6 files changed, 26 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index f0972d7a..c4cbc146 100644 --- a/README.rst +++ b/README.rst @@ -36,6 +36,7 @@ Features * Pre configured Celery_ (optional) * Integration with Maildump_ for local email testing (optional) * Integration with Sentry_ for error logging (optional) +* Integration with NewRelic_ for performance monitoring (optional) * Docker support using docker-compose_ for dev and prod * Procfile_ for deploying to Heroku @@ -53,6 +54,7 @@ Features .. _Celery: http://www.celeryproject.org/ .. _Maildump: https://github.com/ThiefMaster/maildump .. _Sentry: https://getsentry.com +.. _NewRelic: https://newrelic.com .. _docker-compose: https://www.github.com/docker/compose @@ -105,6 +107,7 @@ It prompts you for questions. Answer them:: use_celery [n]: y use_maildump [n]: n use_sentry [n]: y + use_newrelic [n]: y windows [n]: n use_python2 [n]: y diff --git a/cookiecutter.json b/cookiecutter.json index f214fad1..5bbcdc12 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -13,6 +13,7 @@ "use_celery": "n", "use_maildump": "n", "use_sentry": "n", + "use_newrelic": "n", "windows": "n", "use_python2": "n" } diff --git a/{{cookiecutter.repo_name}}/app.json b/{{cookiecutter.repo_name}}/app.json index 92358ffa..eb2bd723 100644 --- a/{{cookiecutter.repo_name}}/app.json +++ b/{{cookiecutter.repo_name}}/app.json @@ -21,7 +21,8 @@ "DJANGO_AWS_STORAGE_BUCKET_NAME": "", "DJANGO_MAILGUN_SERVER_NAME": "", "DJANGO_MAILGUN_API_KEY": ""{% if cookiecutter.use_sentry == "y" -%}, - "DJANGO_SENTRY_DSN": ""{%- endif %} + "DJANGO_SENTRY_DSN": ""{%- endif %}{% if cookiecutter.use_newrelic == "y -%"}, + "NEW_RELIC_LICENSE_KEY": ""{%- endif %} }, "scripts": { "postdeploy": "python manage.py migrate" diff --git a/{{cookiecutter.repo_name}}/config/settings/production.py b/{{cookiecutter.repo_name}}/config/settings/production.py index e21bc59b..edcf74a5 100644 --- a/{{cookiecutter.repo_name}}/config/settings/production.py +++ b/{{cookiecutter.repo_name}}/config/settings/production.py @@ -131,6 +131,11 @@ MAILGUN_SERVER_NAME = env('DJANGO_MAILGUN_SERVER_NAME') EMAIL_SUBJECT_PREFIX = env("DJANGO_EMAIL_SUBJECT_PREFIX", default='[{{cookiecutter.project_name}}] ') SERVER_EMAIL = env('DJANGO_SERVER_EMAIL', default=DEFAULT_FROM_EMAIL) +{% if cookiecutter.use_newrelic == 'y'-%} +NEW_RELIC_LICENSE_KEY = env('NEW_RELIC_LICENSE_KEY') +{%- endif %} + + # TEMPLATE CONFIGURATION # ------------------------------------------------------------------------------ # See: diff --git a/{{cookiecutter.repo_name}}/config/wsgi.py b/{{cookiecutter.repo_name}}/config/wsgi.py index 697aa5b3..9f2df6cf 100644 --- a/{{cookiecutter.repo_name}}/config/wsgi.py +++ b/{{cookiecutter.repo_name}}/config/wsgi.py @@ -15,6 +15,11 @@ framework. """ import os +{% if cookiecutter.use_newrelic == "y" -%} +if os.environ.get("DJANGO_SETTINGS_MODULE") == "config.settings.production": + import newrelic.agent + newrelic.agent.initialize() +{%- endif %} from django.core.wsgi import get_wsgi_application {% if cookiecutter.use_whitenoise == 'y' -%} from whitenoise.django import DjangoWhiteNoise @@ -44,6 +49,10 @@ application = DjangoWhiteNoise(application) if os.environ.get("DJANGO_SETTINGS_MODULE") == "config.settings.production": application = Sentry(application) {%- endif %} +{% if cookiecutter.use_newrelic == "y" -%} +if os.environ.get("DJANGO_SETTINGS_MODULE") == "config.settings.production": + application = newrelic.agent.WSGIApplicationWrapper(application) +{%- endif %} # Apply WSGI middleware here. # from helloworld.wsgi import HelloWorldApplication diff --git a/{{cookiecutter.repo_name}}/requirements/production.txt b/{{cookiecutter.repo_name}}/requirements/production.txt index e3c05bba..a27fb8fa 100644 --- a/{{cookiecutter.repo_name}}/requirements/production.txt +++ b/{{cookiecutter.repo_name}}/requirements/production.txt @@ -24,3 +24,9 @@ django-mailgun==0.7.2 # -------------------------- raven {%- endif %} + +{% if cookiecutter.use_newrelic == "y" -%} +# Newrelic agent for performance monitoring +# ----------------------------------------- +newrelic +{%- endif %}