[ Pobierz całość w formacie PDF ]

viewing. Each namespace gets its own header and attribute table, plus an extra table for each collection. This is NOT
part of the statistics specification; other tools can format how they like.
You can control which columns are output and how they are formatted by updating StatsPage.formatting, which is
a dict that mirrors the keys and nesting of logging.statistics. The difference is that, instead of data values, it has
formatting values. Use None for a given key to indicate to the StatsPage that a given column should not be output. Use
a string with formatting (such as  %.3f ) to interpolate the value(s), or use a callable (such as lambda v: v.isoformat())
for more advanced formatting. Any entry which is not mentioned in the formatting dict is output unchanged.
130 Chapter 7. Reference Manual
CherryPy Documentation, Release 3.2.4
Monitoring
Although the HTML output takes pains to assign unique id s to each with statistical data, you re probably better
off fetching /cpstats/data, which outputs the whole (extrapolated) logging.statistics dict in JSON format. That is
probably easier to parse, and doesn t have any formatting controls, so you get the  original data in a consistently-
serialized format. Note: there s no treatment yet for datetime objects. Try time.time() instead for now if you can.
Nagios will probably thank you.
Turning Collection Off
It is recommended each namespace have an  Enabled item which, if False, stops collection (but not reporting) of
statistical data. Applications SHOULD provide controls to pause and resume collection by setting these entries to
False or True, if present.
Usage
To collect statistics on CherryPy applications:
from cherrypy.lib import cpstats
appconfig[ / ][ tools.cpstats.on ] = True
To collect statistics on your own code:
import logging
# Initialize the repository
if not hasattr(logging,  statistics ): logging.statistics = {}
# Initialize my namespace
mystats = logging.statistics.setdefault( My Stuff , {})
# Initialize my namespace s scalars and collections
mystats.update({
 Enabled : True,
 Start Time : time.time(),
 Important Events : 0,
 Events/Second : lambda s: (
(s[ Important Events ] / (time.time() - s[ Start Time ]))),
})
...
for event in events:
...
# Collect stats
if mystats.get( Enabled , False):
mystats[ Important Events ] += 1
To report statistics:
root.cpstats = cpstats.StatsPage()
To format statistics reports:
See  Reporting , above.
Classes
classcherrypy.lib.cpstats.StatsTool
Record various information about the current request.
7.13. cherrypy.lib 131
CherryPy Documentation, Release 3.2.4
record_start()
Record the beginning of a request.
record_stop(uriset=None, slow_queries=1.0, slow_queries_count=100, debug=False, **kwargs)
Record the end of a request.
classcherrypy.lib.cpstats.StatsPage
7.13.7 cherrypy.lib.cptools
Functions for builtin CherryPy tools.
Classes
classcherrypy.lib.cptools.SessionAuth
Assert that the user is logged in.
anonymous()
Provide a temporary user name for anonymous users.
do_check()
Assert username. May raise redirect, or return True if request handled.
do_login(username, password, from_page= .. , **kwargs)
Login. May raise redirect, or return True if request handled.
do_logout(from_page= .. , **kwargs)
Logout. May raise redirect, or return True if request handled.
classcherrypy.lib.cptools.MonitoredHeaderMap
Functions
cherrypy.lib.cptools.validate_etags(autotags=False, debug=False)
Validate the current ETag against If-Match, If-None-Match headers.
If autotags is True, an ETag response-header value will be provided from an MD5 hash of the response body
(unless some other code has already provided an ETag header). If False (the default), the ETag will not be
automatic.
WARNING: the autotags feature is not designed for URL s which allow methods other than GET. For example,
if a POST to the same URL returns no content, the automatic ETag will be incorrect, breaking a fundamental
use for entity tags in a possibly destructive fashion. Likewise, if you raise 304 Not Modified, the response body
will be empty, the ETag hash will be incorrect, and your application will break. See RFC 2616 Section 14.24.
cherrypy.lib.cptools.validate_since()
Validate the current Last-Modified against If-Modified-Since headers.
If no code has set the Last-Modified response header, then no validation will be performed.
cherrypy.lib.cptools.proxy(base=None, local= X-Forwarded-Host , remote= X-Forwarded-For ,
scheme= X-Forwarded-Proto , debug=False)
Change the base URL (scheme://host[:port][/path]).
For running a CP server behind Apache, lighttpd, or other HTTP server.
For Apache and lighttpd, you should leave the  local argument at the default value of  X-Forwarded-Host . For
Squid, you probably want to set tools.proxy.local =  Origin .
132 Chapter 7. Reference Manual
CherryPy Documentation, Release 3.2.4
If you want the new request.base to include path info (not just the host), you must explicitly set base to the full
base path, and ALSO set  local to   , so that the X-Forwarded-Host request header (which never includes path
info) does not override it. Regardless, the value for  base MUST NOT end in a slash.
cherrypy.request.remote.ip (the IP address of the client) will be rewritten if the header specified by the  remote
arg is valid. By default,  remote is set to  X-Forwarded-For . If you do not want to rewrite remote.ip, set the
 remote arg to an empty string.
cherrypy.lib.cptools.ignore_headers(headers=( Range , ), debug=False)
Delete request headers whose field names are included in  headers .
This is a useful tool for working behind certain HTTP servers; for example, Apache duplicates the work that CP
does for  Range headers, and will doubly-truncate the response.
cherrypy.lib.cptools.response_headers(headers=None, debug=False)
Set headers on the response.
cherrypy.lib.cptools.referer(pattern, accept=True, accept_missing=False, error=403, mes-
sage= Forbidden Referer header. , debug=False)
Raise HTTPError if Referer header does/does not match the given pattern.
pattern A regular expression pattern to test against the Referer.
accept If True, the Referer must match the pattern; if False, the Referer must NOT match the pattern.
accept_missing If True, permit requests with no Referer header.
error The HTTP error code to return to the client on failure.
message A string to include in the response body on failure.
cherrypy.lib.cptools.session_auth(**kwargs)
Session authentication hook.
Any attribute of the SessionAuth class may be overridden via a keyword arg to this function:
anonymous: instancemethod check_username_and_password: instancemethod debug: bool do_check: in-
stancemethod do_login: instancemethod do_logout: instancemethod login_screen: instancemethod on_check:
instancemethod on_login: instancemethod on_logout: instancemethod run: instancemethod session_key: str
cherrypy.lib.cptools.log_traceback(severity=40, debug=False)
Write the last error s traceback to the cherrypy error log.
cherrypy.lib.cptools.log_request_headers(debug=False)
Write request headers to the cherrypy error log.
cherrypy.lib.cptools.log_hooks(debug=False)
Write request.hooks to the cherrypy error log. [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • grecja.xlx.pl