简体   繁体   中英

How to monitor this cherrypy web application with newrelic and probably convert it to wsgi

I am running a cherrypy application using python 2.7 on windows (and using the cherrypy version from pipi). The application is running in the intranet and basically structured like the code below.

To monitor this application with newrelic I tried to wrap it like explained in the newrelic documentation. But it did not appear in the newrelic backend when started that way, although the cherrypy application worked.

I also tried the manual method, inserting the newrelic agent just one line after def main(): . This made the application appear in the newrelich backend but it monitored nothing. All diagrams empty.

I already searched the web for hours and asked some colleages without any progress.

From the newrelic documentation I suspect I have to choose a different structure or technology in my cherrypy application. They do not use quickstart . So my question is how do I convert my application that it fits the newrelic way of monitoring applications.

This is more or less the main file of the application:

# -*- 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()

Please help me to construct in a newrelic compatible way, like wsgi, the different parts, like the config, the dispatch, the auth and the routes, so that I can monitor it.

I am ready to do things different where necessary, I know with python almost everything is possible.

So if this needs to be a wsgi application how do I change it? I would prefer this over other methods (like paste ).


I hope this can also help many other people, because I was not able to find anything specific about this and I can imagine that many cherrypy applications out there are structured similar. I spent a lot of time in the cherrypy docs but somehow was not able to put the different parts together.

The newrelic-admin wrapper script can be used for a CherryPy WSGI application which uses cherrypy.quickstart(). Once you have generated your agent configuration file, all you need to do is run:

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

where app.py is your script.

A simple example of an app.py script which works, including a route dispatcher is:

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)

You might verify that things are working for your specific environment and package versions with that example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM