跳转到主要内容

Zope/Plone Newrelic 工具

项目描述

简介

此包为NewRelic( http://www.newrelic.com )提供仪表化功能。目前已对catalog-tool、transformchains和zope-events进行仪表化。包含一个转换器以支持RUM(真实用户监控):在渲染页面的顶部和底部插入小的JavaScript代码片段。RUM在ZMI(Zope管理接口)中不起作用。

安装

您可以将此egg 'collective.newrelic' 添加到您的egg中,它还将引入 'newrelic' egg。

[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文件,见下文。

newrelic代理要工作,需要设置NEW_RELIC_ENABLED和NEW_RELIC_CONFIG_FILE变量。

省略NEW_RELIC_ENVIRONMENT变量将意味着[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

This will create a newrelic.ini file in the current directory.

您可能需要使用 newrelic-admin validate-config newrelic.ini 验证生成的文件。

默认配置文件为“staging”,您可以在补丁目录下的 __init__.py 中修改。您还可以在 newrelic.ini 文件中修改“Python Application (Staging)”的默认名称。为了得到合理的数据库跟踪,将

transaction_tracer.record_sql = obfuscated

修改为

transaction_tracer.record_sql = raw

示例用法

在 utils 中,您可以找到一些辅助函数来包装您的产品(部分)和/或 plone 和/或任何 Python 模块。例如,您可以为名为 myproduct.newrelic 的简单 egg 创建一个名为 __init__.py 的文件。在该文件中,您有一个名为 “initialize” 的函数,在那里您使用辅助函数进行进一步的包装。

整个模块的完整类+函数包装

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)

对单个类函数进行精确包装

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://www.newrelic.com

http://newrelic.com/docs/python/python-agent-installation

http://docs.newrelic.com/docs/python/testing-the-python-agent

变更历史

1.0.9 (2014-01-02)

  • 介绍和解释 NEW_RELIC_ENABLED 和 NEW_RELIC_CONFIG_FILE 环境变量 [fiterbek]

  • 修复文档格式 [fiterbek]

  • 打印更友好的信息消息 [fiterbek]

  • 更新 NEW_RELIC_ENVIRONMENT 环境变量的文档 [puittenbroek]

1.0.8 (2013-10-02)

  • 修复:当 PageTemplate 通过值而不是文件创建时,TALInterpreter 补丁失败 [puittenbroek]

  • 添加对 repoze.xmliter 的依赖 [fiterbek]

1.0.7 (2013-07-11)

  • 文档中的错误 [khink]

  • 为 pypi 发布检查文档 [puittenbroek]

  • 将 cron4plone tick(如果存在)修补为后台任务 [puittenbroek]

  • 改进挂钩逻辑,使其在 ZMI 中正常工作 [puittenbroek]

1.0.6 - 未发布

  • 更改事务的命名,现在基于使用的视图/模板 [puittenbroek]

  • 忽略资源文件(js、css、kss(?))的事务 [puittenbroek]

1.0.5 - 未发布

  • 首个生产测试版本

1.0.5 之前

  • 初始代码实现和测试

项目详情


下载文件

下载适合您平台的项目。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分发

collective.newrelic-1.0.9.zip (38.7 kB 查看散列)

上传时间

由以下支持