如何使用newrelic监视这个樱桃般的Web应用程序,并可能将其转换为wsgi



我正在Windows上使用python 2.7运行一个cherrypy应用程序(并使用pipi的cherrypy版本)。该应用程序在内部网中运行,结构基本类似于下面的代码。

为了使用 newrelic 监控此应用程序,我尝试按照 newrelic 文档中的说明包装它。但是当以这种方式启动时,它并没有出现在 newrelic 后端中,尽管 cherry 应用程序有效。

我也尝试了手动方法,在def main():后仅插入一行新遗物剂。这使得应用程序出现在newrelich后端中,但它没有监控任何内容。所有关系图均为空。

我已经在网上搜索了几个小时,并询问了一些没有任何进展的同事。

从newrelic文档中,我怀疑我必须在我的樱桃应用程序中选择不同的结构或技术。他们不使用quickstart.所以我的问题是我如何转换我的应用程序,使其适合监控应用程序的新方式。

这或多或少是应用程序的主文件:

# -*- coding: utf-8 -*-
def main():
  import cherrypy
  from auth import AuthController
  from my_routes import RouteOne, RouteTwo
  dispatcher = cherrypy.dispatch.RoutesDispatcher()
  dispatcher.explicit = False
  dc = dispatcher.connect
  dc(u'd_home', u'/', RouteOne().index_home)
  dc(u'd_content', u'/content/', RouteOne().index_content)
  dc(u'd_search', u'/search/:find', RouteRoot().index_search)
  conf = { 
    '/' : {
      u'request.dispatch' : dispatcher,
      u'tools.staticdir.root' : 'c:/app/src', 
      u'tools.sessions.on' : True,
      u'tools.auth.on': True,
      u'tools.sessions.storage_type' : "file",
      u'tools.sessions.storage_path' : 'c:/app/sessions',
      u'tools.sessions.timeout' : 60,
      u'log.screen' : False,
      u'log.error_file' : 'c:/app/log/error.txt',
      u'log.access_file' : 'c:/app/log/access.txt',
      },
    u'/app/public' : {
      u'tools.staticdir.debug' : True,
      u'tools.staticdir.on' : True,
      u'tools.staticdir.dir' : u"public",
      },
  }
  # ... some additional initialisation left out ...
  cherrypy.tree.mount(None, u"/", config=conf)
  cherrypy.config.update({
    'server.socket_host': myhost.test.com,
    'server.socket_port': 8080,})
  from auth import check_auth
  cherrypy.tools.auth = cherrypy.Tool('before_handler', check_auth)
  cherrypy.quickstart(None, config=conf)
if __name__ == "__main__":
    main()

请帮助我以 newrelic 兼容的方式构建,例如 wsgi,不同的部分,例如配置、调度、身份验证和路由,以便我可以监控它。

我准备在必要时做不同的事情,我知道使用 python 几乎一切皆有可能。

因此,如果这需要是一个 wsgi 应用程序,我该如何更改它?我更喜欢这个而不是其他方法(如paste)。


我希望这也可以帮助许多其他人,因为我无法找到任何具体的信息,我可以想象那里的许多樱桃应用程序的结构相似。我花了很多时间在樱桃文档中,但不知何故无法将不同的部分放在一起。

newrelic-admin wrapper 脚本可用于使用 cherrypy.quickstart() 的 CherryPy WSGI 应用程序。生成代理配置文件后,您需要做的就是运行:

NEW_RELIC_CONFIG_FILE=newrelic.ini newrelic-admin run-python app.py

其中 app.py 是你的脚本。

一个工作的 app.py 脚本(包括路由调度程序)的简单示例是:

import cherrypy
class EndPoint(object):
    def index(self):
        return 'INDEX RESPONSE'
dispatcher = cherrypy.dispatch.RoutesDispatcher()
dispatcher.connect(action='index', name='endpoint', route='/endpoint',
        controller=EndPoint())
conf = { '/': { 'request.dispatch': dispatcher } }
cherrypy.quickstart(None, config=conf)

您可以使用该示例验证某些内容是否适用于您的特定环境和包版本。

最新更新