Skip to content

Instantly share code, notes, and snippets.

View GrahamDumpleton's full-sized avatar
😎

Graham Dumpleton GrahamDumpleton

😎
View GitHub Profile
@GrahamDumpleton
GrahamDumpleton / gist:6418300
Created September 2, 2013 23:52
Example of a module proxy which selectively overrides behaviour of specific functions.
from __future__ import print_function
import wrapt
import time
import sys
class TimeModuleProxy(wrapt.ObjectProxy):
def __init__(self, module=time):
super(TimeModuleProxy, self).__init__(module)
# Put this on module path in file newrelic_django_nap.py.
#
# In agent configuration file add:
#
# [import-hook:nap.publisher]
# enabled = true
# execute = newrelic_django_nap:instrument_django_nap_publisher
from newrelic.agent import (current_transaction, set_transaction_name,
FunctionTrace, callable_name, wrap_function_wrapper)
@GrahamDumpleton
GrahamDumpleton / gist:4590267
Created January 21, 2013 22:51
Gunicorn crashing on closing file descriptors.
Traceback (most recent call last):
File "test-env/bin/gunicorn", line 8, in <module>
load_entry_point('gunicorn==0.16.1', 'console_scripts', 'gunicorn')()
File "/Users/graham/Work/python_agent-1.10.X/test-env/lib/python2.6/site-packages/gunicorn/app/wsgiapp.py", line 32, in run
WSGIApplication("%prog [OPTIONS] APP_MODULE").run()
File "/Users/graham/Work/python_agent-1.10.X/test-env/lib/python2.6/site-packages/gunicorn/app/base.py", line 127, in run
Arbiter(self).run()
File "/Users/graham/Work/python_agent-1.10.X/test-env/lib/python2.6/site-packages/gunicorn/arbiter.py", line 162, in run
self.start()
File "/Users/graham/Work/python_agent-1.10.X/test-env/lib/python2.6/site-packages/gunicorn/arbiter.py", line 122, in start
@GrahamDumpleton
GrahamDumpleton / gist:4341587
Created December 19, 2012 23:22
Manual method for optionally initialising agent based on environment variables.
# Add this at start of WSGI file before any imports, but if necessary after setting
# sys.path so that 'newrelic' package can be found.
import os
license_key = os.environ.get('NEW_RELIC_LICENSE_KEY', None)
config_file = os.environ.get('NEW_RELIC_CONFIG_FILE', None)
environment = os.environ.get('NEW_RELIC_ENVIRONMENT', None)
@GrahamDumpleton
GrahamDumpleton / gist:4133917
Created November 23, 2012 03:44
uWSGI error on shutting down with master, multiple processes and reload mercy.
$ uwsgi --ini uwsgi.ini -M -p 2 --reload-mercy 3
[uWSGI] getting INI configuration from uwsgi.ini
*** Starting uWSGI 1.4.1 (64bit) on [Fri Nov 23 14:43:05 2012] ***
compiled with version: 4.2.1 (Apple Inc. build 5666) (dot 3) on 22 November 2012 16:19:23
os: Darwin-10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386
nodename: Grumpys-MacBook-Pro-15.local
machine: i386
clock source: unix
detected number of CPU cores: 4
current working directory: /Library/WebServer/Sites/hello-1/htdocs
@GrahamDumpleton
GrahamDumpleton / gist:4133912
Created November 23, 2012 03:41
uWSGI crash when supplying float to --reload-mercy.
$ uwsgi --ini uwsgi.ini -M -p 2 --reload-mercy 3.0
[uWSGI] getting INI configuration from uwsgi.ini
*** Starting uWSGI 1.4.1 (64bit) on [Fri Nov 23 14:40:25 2012] ***
compiled with version: 4.2.1 (Apple Inc. build 5666) (dot 3) on 22 November 2012 16:19:23
os: Darwin-10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386
nodename: Grumpys-MacBook-Pro-15.local
machine: i386
clock source: unix
detected number of CPU cores: 4
current working directory: /Library/WebServer/Sites/hello-1/htdocs
@GrahamDumpleton
GrahamDumpleton / gist:4133897
Created November 23, 2012 03:36
uWSGI crash when using -p 2 option.
$ uwsgi --ini uwsgi.ini -p 2
[uWSGI] getting INI configuration from uwsgi.ini
*** Starting uWSGI 1.4.1 (64bit) on [Fri Nov 23 14:35:44 2012] ***
compiled with version: 4.2.1 (Apple Inc. build 5666) (dot 3) on 22 November 2012 16:19:23
os: Darwin-10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386
nodename: Grumpys-MacBook-Pro-15.local
machine: i386
clock source: unix
detected number of CPU cores: 4
current working directory: /Library/WebServer/Sites/hello-1/htdocs
@GrahamDumpleton
GrahamDumpleton / gist:4133450
Created November 23, 2012 00:30
New Relic version of manage.py.
# Save this as newrelic-manage.py in same directory as existing manage.py.
#
# Run as:
#
# NEW_RELIC_CONFIG_FILE=/some/path/newrelic.ini python newrelic-manage.py run_gunicorn
import os
import newrelic.agent
here = os.path.dirname(__file__)
@GrahamDumpleton
GrahamDumpleton / gist:4130197
Created November 22, 2012 09:29
uWSGI virtual environment PYTHONHOME issues.
(uwsgi-testing)Grumpys-MacBook-Pro-15:htdocs graham$ which python
/Users/graham/Python/uwsgi-testing/bin/python
(uwsgi-testing)Grumpys-MacBook-Pro-15:htdocs graham$ python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.prefix
'/Users/graham/Python/uwsgi-testing/bin/..'
@GrahamDumpleton
GrahamDumpleton / gist:4128656
Created November 22, 2012 00:14
Web external modules loaded.
843,httplib
843,urllib
813,urllib2
163,requests
94,httplib2
87,xmlrpclib
33,feedparser
6,urllib3