This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import newrelic.agent | |
newrelic.agent.register_application(timeout=10.0) | |
def start_response(status, headers): pass | |
@newrelic.api.web_transaction.wsgi_application() | |
def handler(environ, start_response): | |
status = '200 OK' | |
output = 'Hello World!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from gevent import monkey | |
monkey.patch_all() | |
import os | |
os.environ['GEVENT_NOPATCH'] = '1' | |
import newrelic.agent | |
newrelic.agent.initialize('/srv/socialcode/project/socialcode/newrelic.ini') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This would go in the existing [newrelic] section of agent configuration file. | |
# There should already be a empty setting in sample configuration file. | |
transaction_tracer.function_trace = pycassa.columnfamily:ColumnFamily.xget | |
pycassa.columnfamily:ColumnFamily.get | |
pycassa.columnfamily:ColumnFamily.get_indexed_slices | |
pycassa.columnfamily:ColumnFamily.multiget | |
... add other methods | |
pycassa.columnfamilymap:ColumnFamilyMap.combine_columns | |
pycassa.columnfamilymap:ColumnFamilyMap.get |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ResinAdjust(object): | |
def __init__(self): | |
self._lastBlack = 0 | |
self._lastWhite = 1 | |
def __call__(self, value): | |
value = min(value, 180) | |
if self._lastBlack: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
w,h = new_img.size | |
for x in range(0, w): | |
adjuster = ResinAdjust() | |
for y in range(0, h): | |
p = new_img.getpixel((x, y)) | |
new_p = adjuster(p) | |
new_img.putpixel((x, y), new_p) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _name_transaction(self, f, *args): | |
transaction = newrelic.api.transaction.current_transaction() | |
if transaction: | |
name = newrelic.api.object_wrapper.callable_name(f) | |
transaction.name_transaction(name) | |
newrelic.api.in_function.wrap_in_function(module, 'application._delegate', | |
_name_transaction) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import psutil | |
import sys | |
THRESHOLD = 2*1024*1024 | |
class MemoryUsageMiddleware(object): | |
def process_request(self, request): | |
request._mem = psutil.Process(os.getpid()).get_memory_info() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
meta = getattr(instance, '_meta', None) | |
if meta is None: | |
group = 'Python/TastyPie/Api' | |
name = instance.api_name | |
elif meta.api_name is not None: | |
group = 'Python/TastyPie/Api' | |
name = '%s/%s/%s' % (meta.api_name, meta.resource_name, view_name) | |
else: | |
group = 'Python/TastyPie/Resource' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[import-hook:pyramid.router] | |
enabled = true | |
execute = newrelic.hooks.framework_pyramid:instrument_pyramid_router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is correct. | |
import os, sys | |
sys.path.append('/usr/local/django') | |
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings' | |
import django.core.handlers.wsgi | |
# This must be at global scope. | |
_application = django.core.handlers.wsgi.WSGIHandler() |
OlderNewer