Table of Contents¶
Django New Relic Plugin Agent Documentation¶
This project provides an interface for publishing arbitrary metrics to New Relic.
Usage¶
Configuration¶
Register Django settings
>>> NEWRELIC_PLUGIN_AGENT = {
... # number of milliseconds between retries to obtain lock on metric timeslice
... # lock acquired for atomic metric computation/publication operations
... 'TIMESLICE_LOCK_RETRY_DELAY_MS': 1000,
... # license key for newrelic account
... 'NEWRELIC_LICENSE_KEY': 'keyboardcat',
... }
Set metric push task to run as often as you like. New Relic recommends 60 seconds.
>>> from djcelery.models import PeriodicTask, IntervalSchedule
>>> interval_schedule = IntervalSchedule.from_schedule(schedule(timedelta(seconds=60)))
>>> interval_schedule.save()
>>> PeriodicTask.object.create(
... name='PushMetricTimeslice', interval=interval_schedule, enabled=True,
... task='newrelic_plugin_agent.tasks.PushMetricTimeslicesTask')
Add a Plugin Component¶
A component can be thought of as an aspect of your application/stack that you want to monitor.
>>> from newrelic_plugin_agent.models import NewRelicComponent
>>> # create a component
>>> component = NewRelicComponent.objects.create(
... name='AccountActivity', guid='com.your_company_name.account_activity')
Adding Metric Values to be Sent to New Relic¶
Push a metric value by forking an async job to add the value to the metric queue
>>> from newrelic_plugin_agent.tasks import PushMetricValueTask
>>> # created a new account, track frequency
>>> PushMetricValueTask.delay(component, 'AccountsCreated', 1)
Installation¶
To install the latest release, type:
pip install django-newrelic-plugin-agent
To install the latest code directly from source, type:
pip install git+git://github.com/ambitioninc/django-newrelic-plugin-agent.git
Contributing¶
Contributions and issues are most welcome! All issues and pull requests are handled through github on the ambitioninc repository. Also, please check for any existing issues before filing a new one. If you have a great idea but it involves big changes, please file a ticket before making a pull request! We want to make sure you don’t spend your time coding something that might not fit the scope of the project.
Running the tests¶
To get the source source code and run the unit tests, run:
git clone git://github.com/ambitioninc/django-newrelic-plugin-agent.git
cd django-newrelic-plugin-agent
virtualenv env
. env/bin/activate
python setup.py install
coverage run setup.py test
coverage report --fail-under=100
While 100% code coverage does not make a library bug-free, it significantly reduces the number of easily caught bugs! Please make sure coverage is at 100% before submitting a pull request!
Code Styling¶
Please arrange imports with the following style
# Standard library imports
import os
# Third party package imports
from mock import patch
from django.conf import settings
# Local package imports
from newrelic_plugin_agent.version import __version__
Please follow Google’s python style guide wherever possible.
Building the docs¶
When in the project directory:
pip install -r requirements/docs.txt
python setup.py build_sphinx
open docs/_build/html/index.html
Release Checklist¶
Before a new release, please go through the following checklist:
Bump version in newrelic_plugin_agent/version.py
Add a release note in docs/release_notes.rst
Git tag the version
Upload to pypi:
pip install wheel python setup.py sdist bdist_wheel upload
Uploading to pypi can be accomplished by running python publish.py
Vulnerability Reporting¶
For any security issues, please do NOT file an issue or pull request on github! Please contact security@ambition.com with the GPG key provided on Ambition’s website.