Zope/Plone Newrelic仪器
collective.newrelic的Python项目详细描述
简介
这个包为newrelic(http://www.newrelic.com)提供了工具。目前,catalog工具、transformchains和zope事件都已检测。包含一个支持rum(真实用户监控)的转换:它在呈现页面的顶部和底部插入一小段javascript代码。rum在zmi(zope管理接口)中不工作。
安装
你可以把这个蛋加上“collective.newrelic”,它也会把“newrelic”蛋拉进来。
[buildout] # either pin versions as shown below... versions=versions [versions] newrelic = 2.6.0.5 repoze.xmliter = 0.5 # update to 1.0.9 on next release: collective.newrelic = 1.0.8 # ...or allow picked versions and risk breakage on product updates #allow-picked-versions = true parts += newrelic [newrelic] recipe = zc.recipe.egg:scripts eggs = newrelic [instance] eggs += collective.newrelic # make sure newrelic itself is enabled and set the path to your newrelic.ini file environment-vars += NEW_RELIC_ENABLED true NEW_RELIC_CONFIG_FILE ${buildout:directory}/newrelic.ini NEW_RELIC_ENVIRONMENT development # when using supervisor, setting environment variables is slightly different: #[supervisor] #supervisord-environment=NEW_RELIC_ENABLED=true,NEW_RELIC_CONFIG_FILE=${buildout:directory}/newrelic.ini,NEW_RELIC_ENVIRONMENT=development
可以选择使用环境变量配置许多其他设置,有关详细信息,请参见http://docs.newrelic.com/docs/python/python-agent-configuration#environment-variables。 不过,建议您自定义newrelic.ini文件,请参见下文。
但是,需要设置new_relic_enabled和new_relic_config_file变量,newrelic代理才能工作。
省略new_relic_环境变量将意味着加载[newrelic]部分时不需要额外的[newrelic:yourenvname]设置。
请注意:newrelic包需要python>;=2.5。这个程序包对plone 3不起作用。
使用
要启用到newrelic.com的日志记录,请在newrelic.com上创建一个帐户并获取许可证密钥。在项目的根目录中创建一个“newrelic.ini”文件。从这个包或newrelic包复制模板,或运行
$ bin/newrelic-admin generate-config YOUR-LICENSE-KEY newrelic.ini
这将在当前目录中创建一个newrelic.ini文件。
您可能希望使用newrelic-adminvalidate-config newrelic.ini
验证生成的文件默认配置文件是“staging”,可以在修补程序目录中的\uuu init\uuu.py中更改。可以更改newrelic.ini文件中“python application(staging)”的默认名称。要获得合理的数据库跟踪更改
transaction_tracer.record_sql = obfuscated
到
transaction_tracer.record_sql = raw
示例用法
在utils中,您可以找到一些帮助函数来包装产品和/或plone和/或任何python模块的(部分)。 例如,您可以只使用.init\.py制作一个名为myproduct.newrelic的简单鸡蛋。 在该文件中有一个“initialize”函数,其中使用helper函数进一步包装。
整个模块的完整类+函数包装
from plone.app import viewletmanager as plone_viewletmanager from collective.newrelic.utils import wrap_module_classes_functions class_function_modules = [plone_viewletmanager, ] wrapped_methods = wrap_module_classes_functions(class_function_modules) print len(wrapped_methods)
单类包装
from zope.tal.talinterpreter import TALInterpreter from collective.newrelic.utils import wrap_class_found_functions wrapped_methods = wrap_class_found_functions(TALInterpreter) print len(wrapped_methods)
单类函数的pin point精度包装
from zope.tal.talinterpreter import TALInterpreter from collective.newrelic.utils import wrap_class_function wrapped_methods = wrap_class_function(TALInterpreter, TALInterpreter.__call__) print wrapped_methods "TALInterpreter.__call__"
故障排除
如果在zope实例日志中看到消息The Python Agent is not enabled.,请首先检查NEW_RELIC_ENABLED环境变量是否设置正确。
如果可以,请检查您的newrelic.ini文件,并确保您正在使用的配置文件(例如[newrelic:staging])具有monitor_mode = true。
也可能意味着找不到newrelic.ini。确保使用NEW_RELIC_CONFIG_FILE环境变量正确设置newrelic.ini文件的路径。
如果看到消息A valid account license key cannot be found.,请检查您是否具有有效的许可证密钥,并确保在newrelic.ini文件中正确设置了该密钥。
参考文献
http://newrelic.com/docs/python/python-agent-installation
http://docs.newrelic.com/docs/python/testing-the-python-agent
变更历史
1.0.9(2014-01-02)
- Introduce and explain NEW_RELIC_ENABLED and NEW_RELIC_CONFIG_FILE enviroment variables [fiterbek]
- Fix documentation formatting [fiterbek]
- Print nicer info message [fiterbek]
- Update documentation for NEW_RELIC_ENVIRONMENT enviroment variables [puittenbroek]
1.0.8(2013-10-02)
- Fix: TALInterpreter patch fails when PageTemplate is made by value instead of file [puittenbroek]
- Added dependency on repoze.xmliter [fiterbek]
1.0.7(2013-07-11)
- Documentation typos [khink]
- Documentation checking for pypi release [puittenbroek]
- Patch cron4plone tick (if present) to make it a backgroundtask [puittenbroek]
- Improve hook logic to worker properly in ZMI [puittenbroek]
1.0.6-未发布
- Changed naming of transactions, now based on view/templates being used [puittenbroek]
- Ignore transactions for resource files (js, css, kss(?)) [puittenbroek]
1.0.5-未发布
- First production test version
1.0.5之前的版本
- Inital code implemtation and testing