Skip to content

Instantly share code, notes, and snippets.

@GrahamDumpleton
Created November 7, 2012 22:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GrahamDumpleton/4035071 to your computer and use it in GitHub Desktop.
Save GrahamDumpleton/4035071 to your computer and use it in GitHub Desktop.
# Run this as:
#
# NEW_RELIC_CONFIG_FILE=newrelic.ini newrelic-admin run-python example.py
#
# If being run under Heroku, you can skip setting NEW_RELIC_CONFIG_FILE on the
# command line as the required environment variable settings added by the
# Heroku New Relic addon will be picked up automatically.
import time
import newrelic.agent
# This force registers the agent and waits for it to register for period up to
# that specified by timeout. If doesn't register in that time, execution will
# continue anyway. It needs to be force registered when only collecting custom
# metrics as otherwise will not be registered due to registration usually on
# being lazily done on first web transaction or background task.
#
# If this is being done as background thread to web process where agent is
# already running and in use, then you can comment out the line to register the
# agent.
application = newrelic.agent.register_application(timeout=5.0)
count = 0
while True:
time.sleep(10.0)
count += 1
# Use of record_metric() within application object currently is stepping
# outside of declared public API and may be subject to change in the future.
application.record_metric('Custom/Counter', count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment