-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Separate ZODB connection information into new ZODB Connections view
- Loading branch information
Showing
7 changed files
with
178 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2023 Zope Foundation and Contributors. | ||
# | ||
# This software is subject to the provisions of the Zope Public License, | ||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. | ||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
# FOR A PARTICULAR PURPOSE | ||
# | ||
############################################################################## | ||
|
||
import pprint | ||
import time | ||
from operator import itemgetter | ||
|
||
from AccessControl.class_init import InitializeClass | ||
from AccessControl.SecurityInfo import ClassSecurityInfo | ||
from Acquisition import Implicit | ||
from App.special_dtml import DTMLFile | ||
from OFS.SimpleItem import Item | ||
|
||
|
||
class ZODBConnectionDebugger(Item, Implicit): | ||
id = 'ZODBConnectionDebugger' | ||
name = title = 'ZODB Connections' | ||
meta_type = 'ZODB Connection Debugger' | ||
zmi_icon = 'fas fa-bug' | ||
|
||
security = ClassSecurityInfo() | ||
|
||
manage_zodb_conns = manage_main = manage = manage_workspace = DTMLFile( | ||
'dtml/zodbConnections', globals()) | ||
manage_zodb_conns._setName('manage_zodb_conns') | ||
manage_options = ( | ||
{'label': 'Control Panel', 'action': '../manage_main'}, | ||
{'label': 'Databases', 'action': '../Database/manage_main'}, | ||
{'label': 'Configuration', 'action': '../Configuration/manage_main'}, | ||
{'label': 'DAV Locks', 'action': '../DavLocks/manage_main'}, | ||
{'label': 'Reference Counts', 'action': '../DebugInfo/manage_main'}, | ||
{'label': 'ZODB Connections', 'action': 'manage_main'}, | ||
) | ||
|
||
def dbconnections(self): | ||
import Zope2 # for data | ||
|
||
result = [] | ||
now = time.time() | ||
|
||
def get_info(connection): | ||
# `result`, `time` and `before` are lexically inherited. | ||
request_info = {} | ||
request_info_formatted = '' | ||
debug_info_formatted = '' | ||
opened = connection.opened | ||
debug_info = connection.getDebugInfo() or {} | ||
|
||
if debug_info: | ||
debug_info_formatted = pprint.pformat(debug_info) | ||
if len(debug_info) == 2: | ||
request_info = debug_info[0] | ||
request_info.update(debug_info[1]) | ||
request_info_formatted = pprint.pformat(request_info) | ||
|
||
if opened is not None: | ||
open_since = "{}".format( | ||
time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(opened))) | ||
open_for = "{:.2f}s".format(now - opened) | ||
else: | ||
open_since = '(closed)' | ||
open_for = '' | ||
|
||
# output UTC time with the standard Z time zone indicator | ||
result.append({ | ||
'open_since': open_since, | ||
'open_for': open_for, | ||
'info': debug_info, | ||
'info_formatted': debug_info_formatted, | ||
'request_info': request_info, | ||
'request_formatted': request_info_formatted, | ||
'before': connection.before, | ||
'cache_size': len(connection._cache), | ||
}) | ||
|
||
Zope2.DB._connectionMap(get_info) | ||
return sorted(result, key=itemgetter('open_since')) | ||
|
||
|
||
InitializeClass(ZODBConnectionDebugger) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<dtml-var manage_page_header> | ||
<dtml-if debug_auto_reload> | ||
<meta HTTP-EQUIV="Refresh" | ||
CONTENT="&dtml-debug_auto_reload;;URL=&dtml-URL;?debug_auto_reload=&dtml-debug_auto_reload;"> | ||
</dtml-if> | ||
<dtml-with "_(management_view='ZODB Connections')"> | ||
<dtml-var manage_tabs> | ||
</dtml-with> | ||
|
||
<main class="container-fluid"> | ||
|
||
<p class="form-help mt-4"> | ||
This page shows ZODB database connections and their current state. The | ||
Duration column tells you how long an open database connection has been | ||
held by the request shown in the Info column next to it. You can use this | ||
view to diagnose long-running requests. | ||
</p> | ||
|
||
<h3>ZODB database connections</h3> | ||
<table class="table-sm table-bordered mb-5"> | ||
<tr> | ||
<th>Opened at</th> | ||
<th>Duration</th> | ||
<th>Info</th> | ||
</tr> | ||
<dtml-in dbconnections mapping> | ||
<tr> | ||
<td class="text-nowrap" valign="top">&dtml-open_since;</td> | ||
<td class="text-nowrap" valign="top"><dtml-var "open_for or '-'"></td> | ||
<td> | ||
<dtml-if open_for> | ||
<details> | ||
<dtml-if request_info> | ||
<summary> | ||
<b><dtml-var "request_info['REQUEST_METHOD']"> <dtml-var "request_info['REQUEST_URI']"></b> | ||
</summary> | ||
<pre><dtml-var request_formatted html_quote></pre> | ||
<dtml-else> | ||
<summary> | ||
No request information available | ||
</summary> | ||
<pre><dtml-var info_formatted html_quote></pre> | ||
</dtml-if> | ||
</details> | ||
<dtml-else> | ||
- | ||
</dtml-if> | ||
</td> | ||
</tr> | ||
</dtml-in> | ||
</table> | ||
|
||
</main> | ||
|
||
<dtml-var manage_page_footer> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters