Skip to content

Instantly share code, notes, and snippets.

@jaraco
Last active March 27, 2019 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaraco/a7508147a72aa23e0936adbdc1395743 to your computer and use it in GitHub Desktop.
Save jaraco/a7508147a72aa23e0936adbdc1395743 to your computer and use it in GitHub Desktop.
# coding: future_fstrings
__requires__ = [
'cherrypy!=18.1.0',
'future-fstrings',
'backports.functools_lru_cache; python_version=="2.7"',
]
import logging
try:
from functools import lru_cache
except ImportError:
from backports.functools_lru_cache import lru_cache
import cherrypy.lib.cpstats
class CherootStatistics(cherrypy.process.plugins.SimplePlugin):
def main(self):
self._main(self.bus.log)
@staticmethod
@lru_cache()
def _main(log):
keys = (
key
for key in logging.statistics.keys()
if key.startswith('Cheroot HTTPServer')
)
for key in keys:
log(f'Enabling {key} statistics')
logging.statistics[key]['Enabled'] = True
class Server:
@cherrypy.expose
def index(self):
return 'Hello World'
cpstats = cherrypy.lib.cpstats.StatsPage()
def main():
CherootStatistics(cherrypy.engine).subscribe()
config = {
'global': {
'server.socket_host': '::0',
},
}
cherrypy.quickstart(Server(), config=config)
__name__ == '__main__' and main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment