fastpluggy-debug-tools 0.0.14__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of fastpluggy-debug-tools might be problematic. Click here for more details.
- fastpluggy_debug_tools-0.0.14.dist-info/METADATA +12 -0
- fastpluggy_debug_tools-0.0.14.dist-info/RECORD +33 -0
- fastpluggy_debug_tools-0.0.14.dist-info/WHEEL +5 -0
- fastpluggy_debug_tools-0.0.14.dist-info/entry_points.txt +2 -0
- fastpluggy_debug_tools-0.0.14.dist-info/top_level.txt +1 -0
- fastpluggy_plugin/debug_tools/__init__.py +1 -0
- fastpluggy_plugin/debug_tools/config.py +14 -0
- fastpluggy_plugin/debug_tools/plugin.py +43 -0
- fastpluggy_plugin/debug_tools/requirements_tools.py +89 -0
- fastpluggy_plugin/debug_tools/router/__init__.py +274 -0
- fastpluggy_plugin/debug_tools/router/debug.py +94 -0
- fastpluggy_plugin/debug_tools/router/memory_tools.py +77 -0
- fastpluggy_plugin/debug_tools/router/menu_tools.py +48 -0
- fastpluggy_plugin/debug_tools/router/module_tools.py +70 -0
- fastpluggy_plugin/debug_tools/router/pool_info.py +59 -0
- fastpluggy_plugin/debug_tools/router/psutil_analyzer.py +43 -0
- fastpluggy_plugin/debug_tools/router/requirements.py +42 -0
- fastpluggy_plugin/debug_tools/router/task_thread_tools.py +94 -0
- fastpluggy_plugin/debug_tools/router/websocket_tool.py +46 -0
- fastpluggy_plugin/debug_tools/static/debug.css +0 -0
- fastpluggy_plugin/debug_tools/tasks/__init__.py +0 -0
- fastpluggy_plugin/debug_tools/tasks/locked_tasks.py +26 -0
- fastpluggy_plugin/debug_tools/tasks/progress.py +27 -0
- fastpluggy_plugin/debug_tools/tasks/sample_tasks.py +67 -0
- fastpluggy_plugin/debug_tools/tasks/task_sample.py +53 -0
- fastpluggy_plugin/debug_tools/templates/psutil_analyzer.html.j2 +243 -0
- fastpluggy_plugin/debug_tools/templates/widgets/debug/debug_panel.html.j2 +325 -0
- fastpluggy_plugin/debug_tools/templates/widgets/packages_view.html.j2 +207 -0
- fastpluggy_plugin/debug_tools/widgets/__init__.py +3 -0
- fastpluggy_plugin/debug_tools/widgets/debug/__init__.py +0 -0
- fastpluggy_plugin/debug_tools/widgets/debug/debug_panel.py +308 -0
- fastpluggy_plugin/debug_tools/widgets/packages_view.py +44 -0
- fastpluggy_plugin/debug_tools/widgets/psutil_analyzer.py +33 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fastpluggy-debug-tools
|
|
3
|
+
Version: 0.0.14
|
|
4
|
+
Summary: Debug Tools plugin for Fastpluggy
|
|
5
|
+
Author: FastPluggy Team
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: FastPluggy>=0.2.50
|
|
9
|
+
Requires-Dist: psutil
|
|
10
|
+
Requires-Dist: packaging
|
|
11
|
+
Provides-Extra: all
|
|
12
|
+
Requires-Dist: pympler; extra == "all"
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
fastpluggy_plugin/debug_tools/__init__.py,sha256=AqiUH5tcUNO98WLcRVqF434xByfZ47o6ANlCUqze-lg,36
|
|
2
|
+
fastpluggy_plugin/debug_tools/config.py,sha256=lACFxTO2Yo_I9ZXvUSl8oy1-r7Jjk5AP4RfcQD5rwAw,547
|
|
3
|
+
fastpluggy_plugin/debug_tools/plugin.py,sha256=ygZws0z8p8sdsL50aSOfd332OEDz0m2gmyOImjO2OZw,1353
|
|
4
|
+
fastpluggy_plugin/debug_tools/requirements_tools.py,sha256=aqhcouijSt7YR-a4fovLRlbXjViAwtrwBjziHgs3hwU,3021
|
|
5
|
+
fastpluggy_plugin/debug_tools/router/__init__.py,sha256=zoDI2l2HUK7AzFVeOqSRg9_A90jQvQV5icK44jrQIEE,9149
|
|
6
|
+
fastpluggy_plugin/debug_tools/router/debug.py,sha256=V_NyS7r8vU5lrCRkA_xtmfAW_RM1H2wQrRfVwcyCSzI,3393
|
|
7
|
+
fastpluggy_plugin/debug_tools/router/memory_tools.py,sha256=94sGGCI-Pgj6BRftkpIO_ECY4Vj4Thf8SpUw22SSxpc,2109
|
|
8
|
+
fastpluggy_plugin/debug_tools/router/menu_tools.py,sha256=ztAERNFwtW9B9TJnn_TNNImlfYTTErOTLMeebAK2kHs,1327
|
|
9
|
+
fastpluggy_plugin/debug_tools/router/module_tools.py,sha256=tTHAB2KRPNwBzZuJXpQSTmZwoFuEsuzDxPSh74uczEY,2346
|
|
10
|
+
fastpluggy_plugin/debug_tools/router/pool_info.py,sha256=mmnWFWNaKiSY4qiZ4LbPTp1V9SFvp8MOXb0NhgHFDM8,1843
|
|
11
|
+
fastpluggy_plugin/debug_tools/router/psutil_analyzer.py,sha256=YlLzuKFWbIarf8UlHaESyMZEttYJY4r4Izc0QRg8K6k,1675
|
|
12
|
+
fastpluggy_plugin/debug_tools/router/requirements.py,sha256=9_gkhONFwHWrfWTYrEi_vwkxiWkXLb8LuAMfhuAXMA0,1425
|
|
13
|
+
fastpluggy_plugin/debug_tools/router/task_thread_tools.py,sha256=2pfWyeG5im7_2h-LJ7YZqZeBemPXcI4OBQ_iw76sn9Q,2972
|
|
14
|
+
fastpluggy_plugin/debug_tools/router/websocket_tool.py,sha256=-x56HWDOFRpPvyRJzhxV7DFod92mSottE7YBkjn-JhM,1651
|
|
15
|
+
fastpluggy_plugin/debug_tools/static/debug.css,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
|
+
fastpluggy_plugin/debug_tools/tasks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
17
|
+
fastpluggy_plugin/debug_tools/tasks/locked_tasks.py,sha256=CqHgrbs1uKbq7E4roN93z749Za4-6t9IGqXDavoLjkQ,819
|
|
18
|
+
fastpluggy_plugin/debug_tools/tasks/progress.py,sha256=EW4Ub_yFWHQ7dMoaeRb3JDUUa9g9dd20WRBeusGLmWw,958
|
|
19
|
+
fastpluggy_plugin/debug_tools/tasks/sample_tasks.py,sha256=2JFz-4L143UUNWY955OFZlDBC05EsUbwOaks2Z4UdR0,1612
|
|
20
|
+
fastpluggy_plugin/debug_tools/tasks/task_sample.py,sha256=gZCp_4m-fNQ8-eu7ZVFaQY1q1xfgdmGeJtpiJNeXdVk,1512
|
|
21
|
+
fastpluggy_plugin/debug_tools/templates/psutil_analyzer.html.j2,sha256=5TKCAo7MBRLHJNCErU3bSIV2KjrHrrzuQ__Yccgp32U,17179
|
|
22
|
+
fastpluggy_plugin/debug_tools/templates/widgets/packages_view.html.j2,sha256=9AOOYGtDtLC1wRzfbwoUDjkJoC4A_SBWfFMaQcqul8A,7824
|
|
23
|
+
fastpluggy_plugin/debug_tools/templates/widgets/debug/debug_panel.html.j2,sha256=lAqnJHIGgb-d9jyXWG14WReKKKuVzFZuHocfxOk0th0,13621
|
|
24
|
+
fastpluggy_plugin/debug_tools/widgets/__init__.py,sha256=8OBANF_77qTBNeuRctNSq1UG4Yg7qTCBeCzhMC287A0,85
|
|
25
|
+
fastpluggy_plugin/debug_tools/widgets/packages_view.py,sha256=czzfhIg2Spw9kupPBZ05uRhxPJBo6QdSFs-gGYyTcVk,1677
|
|
26
|
+
fastpluggy_plugin/debug_tools/widgets/psutil_analyzer.py,sha256=39wmB45_GGwU6pHV6R2iPrb3hQGma1Pb1iDoWG_P9qc,930
|
|
27
|
+
fastpluggy_plugin/debug_tools/widgets/debug/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
28
|
+
fastpluggy_plugin/debug_tools/widgets/debug/debug_panel.py,sha256=UnUNv2HoHFbFHjblF4SalmlPJR1hHrmxjsQzs1qES_I,10696
|
|
29
|
+
fastpluggy_debug_tools-0.0.14.dist-info/METADATA,sha256=zDoQ4YU8Y3znx-1XmGCVFDJSzCR9iHC-VJy_a253mWg,338
|
|
30
|
+
fastpluggy_debug_tools-0.0.14.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
31
|
+
fastpluggy_debug_tools-0.0.14.dist-info/entry_points.txt,sha256=HP0bguoqGWVt71JL3dnSkGIghBSneeyq8nfC2pjw-pI,89
|
|
32
|
+
fastpluggy_debug_tools-0.0.14.dist-info/top_level.txt,sha256=RsbsJhwOAfoWo7cfx2y9jiglQ7dTrAStTWUwCDfzF5A,18
|
|
33
|
+
fastpluggy_debug_tools-0.0.14.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
fastpluggy_plugin
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .plugin import DebugToolsPlugin
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from fastpluggy.core.config import BaseDatabaseSettings
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class DebugToolsConfig(BaseDatabaseSettings):
|
|
6
|
+
# Enable/disable the Debug Panel Widget
|
|
7
|
+
show_debug_panel_widget: Optional[bool] = True
|
|
8
|
+
|
|
9
|
+
# Additional debug panel widget configuration options
|
|
10
|
+
debug_panel_max_depth: Optional[int] = 10
|
|
11
|
+
debug_panel_show_attributes: Optional[bool] = True
|
|
12
|
+
debug_panel_show_warnings: Optional[bool] = True
|
|
13
|
+
debug_panel_show_context: Optional[bool] = True
|
|
14
|
+
debug_panel_auto_expand: Optional[bool] = False
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# plugin.py
|
|
2
|
+
from typing import Any, Annotated
|
|
3
|
+
|
|
4
|
+
from fastpluggy.core.global_registry import GlobalRegistry
|
|
5
|
+
from fastpluggy.core.module_base import FastPluggyBaseModule
|
|
6
|
+
from fastpluggy.core.tools.inspect_tools import InjectDependency
|
|
7
|
+
from fastpluggy.core.tools.install import is_installed
|
|
8
|
+
from fastpluggy.fastpluggy import FastPluggy
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def get_debug_router():
|
|
12
|
+
from .router import debug_plugin_router
|
|
13
|
+
return debug_plugin_router
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class DebugToolsPlugin(FastPluggyBaseModule):
|
|
17
|
+
module_name: str = "debug_tools"
|
|
18
|
+
|
|
19
|
+
module_menu_name: str = "Debug Tools"
|
|
20
|
+
module_menu_icon: str = "fas fa-tools"
|
|
21
|
+
module_menu_type: str = "admin"
|
|
22
|
+
|
|
23
|
+
module_router: Any = get_debug_router
|
|
24
|
+
|
|
25
|
+
def on_load_complete(self,
|
|
26
|
+
fast_pluggy: Annotated[FastPluggy, InjectDependency],
|
|
27
|
+
plugin: Annotated["PluginState", InjectDependency],
|
|
28
|
+
) -> None:
|
|
29
|
+
|
|
30
|
+
if not is_installed('pympler'):
|
|
31
|
+
plugin.add_warning("pympler is not installed. Debug tools will not be available.")
|
|
32
|
+
|
|
33
|
+
from .widgets.debug.debug_panel import DebugPanelWidget
|
|
34
|
+
GlobalRegistry.extend_globals('list_widget_to_inject', items=[{
|
|
35
|
+
'widget': DebugPanelWidget,
|
|
36
|
+
'position': 0,
|
|
37
|
+
'kwargs': {
|
|
38
|
+
'inject_context': True,
|
|
39
|
+
},
|
|
40
|
+
'tag': '#ROOT#'
|
|
41
|
+
}])
|
|
42
|
+
|
|
43
|
+
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from importlib.metadata import distributions
|
|
3
|
+
from typing import List
|
|
4
|
+
|
|
5
|
+
from loguru import logger
|
|
6
|
+
from packaging.requirements import Requirement
|
|
7
|
+
from packaging.version import Version
|
|
8
|
+
|
|
9
|
+
from fastpluggy.core.plugin_state import PluginState
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def get_requirements_files(plugins_state: dict[str, PluginState]) -> List[str]:
|
|
13
|
+
"""
|
|
14
|
+
Returns a list of requirements.txt file paths for enabled and loaded plugins.
|
|
15
|
+
"""
|
|
16
|
+
requirements_files = []
|
|
17
|
+
for plugin in plugins_state.values():
|
|
18
|
+
if plugin.initialized :#and plugin.loaded:
|
|
19
|
+
req_path = os.path.join(plugin.path, "requirements.txt")
|
|
20
|
+
if os.path.isfile(req_path):
|
|
21
|
+
requirements_files.append(req_path)
|
|
22
|
+
return requirements_files
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def get_installed_packages():
|
|
26
|
+
"""
|
|
27
|
+
Returns a dictionary of installed packages with their metadata.
|
|
28
|
+
"""
|
|
29
|
+
packages = {}
|
|
30
|
+
for dist in distributions():
|
|
31
|
+
name = dist.metadata["Name"]
|
|
32
|
+
packages[name.lower()] = {
|
|
33
|
+
"name": name,
|
|
34
|
+
"version": dist.version,
|
|
35
|
+
"summary": dist.metadata.get("Summary", ""),
|
|
36
|
+
"author": dist.metadata.get("Author", ""),
|
|
37
|
+
"home_page": dist.metadata.get("Home-page", ""),
|
|
38
|
+
}
|
|
39
|
+
return packages
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def get_installed_packages_simple():
|
|
43
|
+
"""
|
|
44
|
+
Returns a simple dictionary of installed packages (name: version).
|
|
45
|
+
Used for compatibility with existing code.
|
|
46
|
+
"""
|
|
47
|
+
return {dist.metadata["Name"].lower(): dist.version for dist in distributions()}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def check_requirements_file(requirements_file: str) -> list[tuple[str, str | None, str]]:
|
|
51
|
+
"""
|
|
52
|
+
Checks a requirements.txt file and returns a list of missing or incompatible packages.
|
|
53
|
+
Returns a list of (package_name, installed_version, required_specifier).
|
|
54
|
+
"""
|
|
55
|
+
if not os.path.exists(requirements_file):
|
|
56
|
+
logger.warning(f"Requirements file not found: {requirements_file}")
|
|
57
|
+
return []
|
|
58
|
+
|
|
59
|
+
missing = []
|
|
60
|
+
installed = get_installed_packages_simple()
|
|
61
|
+
|
|
62
|
+
with open(requirements_file) as f:
|
|
63
|
+
lines = [line.strip() for line in f if line.strip() and not line.startswith("#")]
|
|
64
|
+
|
|
65
|
+
for line in lines:
|
|
66
|
+
try:
|
|
67
|
+
req = Requirement(line)
|
|
68
|
+
name = req.name.lower()
|
|
69
|
+
installed_version = installed.get(name)
|
|
70
|
+
if not installed_version:
|
|
71
|
+
missing.append((req.name, None, str(req.specifier)))
|
|
72
|
+
else:
|
|
73
|
+
if not req.specifier.contains(Version(installed_version), prereleases=True):
|
|
74
|
+
missing.append((req.name, installed_version, str(req.specifier)))
|
|
75
|
+
except Exception as e:
|
|
76
|
+
logger.error(f"Error parsing requirement line '{line}': {e}")
|
|
77
|
+
missing.append((line, "ERROR", "PARSE"))
|
|
78
|
+
|
|
79
|
+
return missing
|
|
80
|
+
|
|
81
|
+
def check_multiple_requirements_files(files: list[str]) -> dict[str, list[tuple[str, str | None, str]]]:
|
|
82
|
+
report = {}
|
|
83
|
+
|
|
84
|
+
for file in files:
|
|
85
|
+
issues = check_requirements_file(file)
|
|
86
|
+
if issues:
|
|
87
|
+
report[file] = issues
|
|
88
|
+
|
|
89
|
+
return report
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
# src/plugins/debug_plugin/router.py
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
from fastapi import APIRouter, Request, Depends
|
|
7
|
+
from fastapi.responses import HTMLResponse
|
|
8
|
+
from fastapi.routing import APIRoute
|
|
9
|
+
|
|
10
|
+
from fastpluggy.core.auth import require_authentication
|
|
11
|
+
from fastpluggy.core.database import Base
|
|
12
|
+
from fastpluggy.core.dependency import get_view_builder, get_fastpluggy
|
|
13
|
+
from fastpluggy.core.tools.fastapi import _extract_route_metadata
|
|
14
|
+
from fastpluggy.core.tools.install import is_installed
|
|
15
|
+
from fastpluggy.core.widgets.render_field_tools import RenderFieldTools
|
|
16
|
+
from fastpluggy.core.view_builer.components.table import TableView
|
|
17
|
+
from fastpluggy.core.widgets import TableWidget
|
|
18
|
+
from fastpluggy.core.widgets.categories.data.debug import DebugView
|
|
19
|
+
from fastpluggy.core.widgets.categories.input.button import AutoLinkWidget
|
|
20
|
+
from fastpluggy.core.widgets.categories.input.button_list import ButtonListWidget
|
|
21
|
+
from .menu_tools import menu_debug_router
|
|
22
|
+
from .module_tools import debug_module_router
|
|
23
|
+
from .pool_info import pool_router
|
|
24
|
+
from .psutil_analyzer import psutil_analyzer_router
|
|
25
|
+
from .requirements import requirements_router
|
|
26
|
+
from .task_thread_tools import task_thread_tools_router
|
|
27
|
+
from ..router.websocket_tool import websocket_notification_button
|
|
28
|
+
|
|
29
|
+
debug_plugin_router = APIRouter()
|
|
30
|
+
debug_plugin_router.include_router(menu_debug_router)
|
|
31
|
+
debug_plugin_router.include_router(debug_module_router)
|
|
32
|
+
debug_plugin_router.include_router(pool_router)
|
|
33
|
+
debug_plugin_router.include_router(psutil_analyzer_router)
|
|
34
|
+
debug_plugin_router.include_router(requirements_router)
|
|
35
|
+
debug_plugin_router.include_router(task_thread_tools_router)
|
|
36
|
+
|
|
37
|
+
if is_installed('pympler'):
|
|
38
|
+
from .memory_tools import menu_memory_router
|
|
39
|
+
debug_plugin_router.include_router(menu_memory_router)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@debug_plugin_router.get("/", response_class=HTMLResponse)
|
|
43
|
+
def list_tools(
|
|
44
|
+
request: Request,
|
|
45
|
+
view_builder=Depends(get_view_builder)
|
|
46
|
+
):
|
|
47
|
+
"""
|
|
48
|
+
Main debug tools page listing available debug functions as buttons.
|
|
49
|
+
"""
|
|
50
|
+
return view_builder.generate(
|
|
51
|
+
request,
|
|
52
|
+
widgets=[
|
|
53
|
+
ButtonListWidget(
|
|
54
|
+
buttons=[
|
|
55
|
+
AutoLinkWidget(route_name="list_tables", label="List Database Tables"),
|
|
56
|
+
AutoLinkWidget(route_name="list_env_vars", label="List Environment Variables"),
|
|
57
|
+
AutoLinkWidget(route_name="route_no_auth", label="List routes (with no auth,conflict)"),
|
|
58
|
+
AutoLinkWidget(route_name="list_session"),
|
|
59
|
+
AutoLinkWidget(route_name="pool_info"),
|
|
60
|
+
AutoLinkWidget(route_name="list_jinja2_templates", label="List Jinja2 Templates"),
|
|
61
|
+
]
|
|
62
|
+
),
|
|
63
|
+
ButtonListWidget(
|
|
64
|
+
title="Menu & Menu Entry",
|
|
65
|
+
buttons=[
|
|
66
|
+
AutoLinkWidget(route_name="list_menu", label="List menu"),
|
|
67
|
+
AutoLinkWidget(route_name="list_menu_entry", label="List _menu_entry "),
|
|
68
|
+
],
|
|
69
|
+
),
|
|
70
|
+
ButtonListWidget(
|
|
71
|
+
title="Modules",
|
|
72
|
+
buttons=[
|
|
73
|
+
AutoLinkWidget(route_name="list_modules_dependencies", label="Modules Dependencies"),
|
|
74
|
+
AutoLinkWidget(route_name="list_requirements", label="Modules requirements.txt"),
|
|
75
|
+
AutoLinkWidget(route_name="list_modules_package", label="Modules installed as package"),
|
|
76
|
+
],
|
|
77
|
+
),
|
|
78
|
+
ButtonListWidget(
|
|
79
|
+
title="WebSocket",
|
|
80
|
+
buttons=[websocket_notification_button(request=request)],
|
|
81
|
+
),
|
|
82
|
+
ButtonListWidget(
|
|
83
|
+
buttons=[
|
|
84
|
+
AutoLinkWidget(route_name="list_global_registry"),
|
|
85
|
+
]
|
|
86
|
+
),
|
|
87
|
+
ButtonListWidget(
|
|
88
|
+
title="Threads & Coroutines",
|
|
89
|
+
buttons=[
|
|
90
|
+
AutoLinkWidget(route_name="list_all_tasks"),
|
|
91
|
+
AutoLinkWidget(route_name="psutil_analyzer_dashboard", label="PSUtil Memory Analyzer"),
|
|
92
|
+
]
|
|
93
|
+
),
|
|
94
|
+
]
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
@debug_plugin_router.get("/list_tables", response_class=HTMLResponse, name="list_tables")
|
|
99
|
+
def list_tables(
|
|
100
|
+
request: Request,
|
|
101
|
+
view_builder=Depends(get_view_builder)
|
|
102
|
+
):
|
|
103
|
+
"""
|
|
104
|
+
Endpoint to list all database tables.
|
|
105
|
+
"""
|
|
106
|
+
data = [{"table_name": table} for table in Base.metadata.tables.keys()]
|
|
107
|
+
return view_builder.generate(
|
|
108
|
+
request,
|
|
109
|
+
widgets=[
|
|
110
|
+
TableWidget(
|
|
111
|
+
data=data,
|
|
112
|
+
title="Database Tables"
|
|
113
|
+
)
|
|
114
|
+
]
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@debug_plugin_router.get("/list_modules", response_class=HTMLResponse, name="list_modules")
|
|
119
|
+
def list_modules(
|
|
120
|
+
request: Request,
|
|
121
|
+
view_builder=Depends(get_view_builder)
|
|
122
|
+
):
|
|
123
|
+
"""
|
|
124
|
+
Endpoint to list all loaded Python modules.
|
|
125
|
+
"""
|
|
126
|
+
modules_info = [
|
|
127
|
+
{
|
|
128
|
+
"module_name": name,
|
|
129
|
+
"file_path": getattr(module, "__file__", "N/A"),
|
|
130
|
+
"package": getattr(module, "__package__", "N/A"),
|
|
131
|
+
"built_in": "yes" if name in sys.builtin_module_names else "no",
|
|
132
|
+
}
|
|
133
|
+
for name, module in sys.modules.items()
|
|
134
|
+
]
|
|
135
|
+
return view_builder.generate(
|
|
136
|
+
request,
|
|
137
|
+
widgets=[
|
|
138
|
+
TableView(
|
|
139
|
+
data=modules_info,
|
|
140
|
+
title="Loaded Modules"
|
|
141
|
+
)
|
|
142
|
+
]
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
@debug_plugin_router.get("/list_env_vars", response_class=HTMLResponse, name="list_env_vars")
|
|
147
|
+
def list_env_vars(
|
|
148
|
+
request: Request,
|
|
149
|
+
view_builder=Depends(get_view_builder)
|
|
150
|
+
):
|
|
151
|
+
"""
|
|
152
|
+
Endpoint to list all environment variables.
|
|
153
|
+
"""
|
|
154
|
+
env_vars = [{"key": key, "value": value} for key, value in os.environ.items()]
|
|
155
|
+
return view_builder.generate(
|
|
156
|
+
request,
|
|
157
|
+
widgets=[
|
|
158
|
+
TableView(
|
|
159
|
+
data=env_vars,
|
|
160
|
+
title="Environment Variables"
|
|
161
|
+
)
|
|
162
|
+
]
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def have_auth(router):
|
|
167
|
+
if router and hasattr(router, 'dependencies'):
|
|
168
|
+
for dep in router.dependencies:
|
|
169
|
+
if dep.dependency == require_authentication:
|
|
170
|
+
return True
|
|
171
|
+
return False
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
@debug_plugin_router.get("/route_no_auth")
|
|
175
|
+
async def route_no_auth(
|
|
176
|
+
request: Request,
|
|
177
|
+
view_builder=Depends(get_view_builder),
|
|
178
|
+
fast_pluggy=Depends(get_fastpluggy),
|
|
179
|
+
):
|
|
180
|
+
"""
|
|
181
|
+
List routes of the application, including authentication check and conflict detection.
|
|
182
|
+
"""
|
|
183
|
+
seen_routes = {}
|
|
184
|
+
route_items = []
|
|
185
|
+
|
|
186
|
+
for route in fast_pluggy.app.routes:
|
|
187
|
+
if not isinstance(route, APIRoute):
|
|
188
|
+
continue
|
|
189
|
+
|
|
190
|
+
metadata = _extract_route_metadata(route)
|
|
191
|
+
metadata["auth_required"] = have_auth(route) # You already use this
|
|
192
|
+
metadata["conflict"] = False # Default to no conflict
|
|
193
|
+
|
|
194
|
+
# Check for conflicts: same path + method
|
|
195
|
+
for method in metadata["methods"]:
|
|
196
|
+
key = f"{metadata['path']}::{method}"
|
|
197
|
+
if key in seen_routes:
|
|
198
|
+
seen_routes[key]["conflict"] = True
|
|
199
|
+
metadata["conflict"] = True
|
|
200
|
+
else:
|
|
201
|
+
seen_routes[key] = metadata
|
|
202
|
+
|
|
203
|
+
route_items.append(metadata)
|
|
204
|
+
|
|
205
|
+
return view_builder.generate(
|
|
206
|
+
request,
|
|
207
|
+
title="Routes without Auth + Conflict Detection",
|
|
208
|
+
widgets=[
|
|
209
|
+
TableView(
|
|
210
|
+
data=route_items,
|
|
211
|
+
field_callbacks={
|
|
212
|
+
"path": lambda v: f"<code>{v}</code>",
|
|
213
|
+
"methods": RenderFieldTools.render_http_verb_badges,
|
|
214
|
+
"auth_required": lambda v: "✅" if v else "❌",
|
|
215
|
+
"conflict": lambda v: "⚠️ Conflict" if v else "—",
|
|
216
|
+
},
|
|
217
|
+
fields=["name", "path", "methods", "auth_required", "conflict"]
|
|
218
|
+
)
|
|
219
|
+
]
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
@debug_plugin_router.get("/list_session")
|
|
224
|
+
async def list_session(
|
|
225
|
+
request: Request,
|
|
226
|
+
view_builder=Depends(get_view_builder)):
|
|
227
|
+
return view_builder.generate(
|
|
228
|
+
request,
|
|
229
|
+
title="List session",
|
|
230
|
+
widgets=[
|
|
231
|
+
DebugView(
|
|
232
|
+
data=request.session,
|
|
233
|
+
)
|
|
234
|
+
]
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
@debug_plugin_router.get("/list_global_registry")
|
|
239
|
+
async def list_global_registry(
|
|
240
|
+
request: Request,
|
|
241
|
+
view_builder=Depends(get_view_builder)):
|
|
242
|
+
from fastpluggy.fastpluggy import FastPluggy
|
|
243
|
+
return view_builder.generate(
|
|
244
|
+
request,
|
|
245
|
+
title="List global registry",
|
|
246
|
+
widgets=[
|
|
247
|
+
DebugView(
|
|
248
|
+
data=FastPluggy.get_all_globals(),
|
|
249
|
+
)
|
|
250
|
+
]
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
@debug_plugin_router.get("/list_jinja2_templates")
|
|
255
|
+
async def list_jinja2_templates(
|
|
256
|
+
request: Request,
|
|
257
|
+
view_builder=Depends(get_view_builder),
|
|
258
|
+
fast_pluggy=Depends(get_fastpluggy)):
|
|
259
|
+
"""
|
|
260
|
+
List all Jinja2 templates registered in the application.
|
|
261
|
+
"""
|
|
262
|
+
templates = fast_pluggy.templates.env.list_templates()
|
|
263
|
+
templates_data = [{"template_path": template} for template in templates]
|
|
264
|
+
|
|
265
|
+
return view_builder.generate(
|
|
266
|
+
request,
|
|
267
|
+
title="Registered Jinja2 Templates",
|
|
268
|
+
widgets=[
|
|
269
|
+
TableView(
|
|
270
|
+
data=templates_data,
|
|
271
|
+
title="Jinja2 Templates"
|
|
272
|
+
)
|
|
273
|
+
]
|
|
274
|
+
)
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import threading
|
|
2
|
+
|
|
3
|
+
import psutil
|
|
4
|
+
from fastapi import APIRouter, Request, Depends
|
|
5
|
+
from sqlalchemy.orm import Session
|
|
6
|
+
|
|
7
|
+
from fastpluggy.core.auth import require_authentication
|
|
8
|
+
from fastpluggy.core.database import get_db
|
|
9
|
+
from fastpluggy.core.dependency import get_view_builder
|
|
10
|
+
from fastpluggy.core.widgets.render_field_tools import RenderFieldTools
|
|
11
|
+
from fastpluggy.core.view_builer.components.table import TableView
|
|
12
|
+
from fastpluggy.core.widgets import ButtonListWidget, AutoLinkWidget
|
|
13
|
+
from fastpluggy.core.widgets.categories.data.debug import DebugView
|
|
14
|
+
from fastpluggy.core.widgets.categories.layout.tabbed import TabbedWidget
|
|
15
|
+
from ..config import TasksRunnerSettings
|
|
16
|
+
from ..services.task_discovery import discover_celery_periodic_tasks
|
|
17
|
+
from ..services.task_discovery import discover_celery_tasks_from_app
|
|
18
|
+
|
|
19
|
+
# Set custom /proc path if provided
|
|
20
|
+
# custom_proc_path = os.getenv("PROCFS_PATH", "/proc")
|
|
21
|
+
|
|
22
|
+
debug_router = APIRouter(
|
|
23
|
+
prefix="/debug",
|
|
24
|
+
tags=["debug"],
|
|
25
|
+
dependencies=[Depends(require_authentication)],
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@debug_router.get("/", name="list_threads")
|
|
30
|
+
async def list_threads(
|
|
31
|
+
request: Request,
|
|
32
|
+
db: Session = Depends(get_db),
|
|
33
|
+
view_builder=Depends(get_view_builder)
|
|
34
|
+
):
|
|
35
|
+
# if host_proces:
|
|
36
|
+
# psutil.PROCFS_PATH = custom_proc_path
|
|
37
|
+
|
|
38
|
+
process = psutil.Process()
|
|
39
|
+
num_threads = process.num_threads()
|
|
40
|
+
process_dict = process.as_dict()
|
|
41
|
+
threads = process_dict['threads']
|
|
42
|
+
threads_dict = [item._asdict() for item in threads]
|
|
43
|
+
clean_threads_dict = threads_dict
|
|
44
|
+
#clean_threads_dict = get_list_task_by_pid(db, threads_dict)
|
|
45
|
+
|
|
46
|
+
threads_enum = [thread for thread in threading.enumerate()]
|
|
47
|
+
|
|
48
|
+
return view_builder.generate(
|
|
49
|
+
request,
|
|
50
|
+
title=f"Thread list (running {num_threads})",
|
|
51
|
+
widgets=[
|
|
52
|
+
ButtonListWidget(buttons=[
|
|
53
|
+
AutoLinkWidget(route_name="celery_list_tasks"),
|
|
54
|
+
]),
|
|
55
|
+
TableView(
|
|
56
|
+
data=clean_threads_dict,
|
|
57
|
+
field_callbacks={'status': RenderFieldTools.render_enum},
|
|
58
|
+
links=[
|
|
59
|
+
AutoLinkWidget(
|
|
60
|
+
label="Details", route_name="task_details",
|
|
61
|
+
#param_mapping={'task_id': 'task_id'},
|
|
62
|
+
condition=lambda task: task['task_id'] is not None),
|
|
63
|
+
]
|
|
64
|
+
),
|
|
65
|
+
TabbedWidget(tabs=[
|
|
66
|
+
DebugView(data=threads_enum, title="Thread Enum"),
|
|
67
|
+
DebugView(data=clean_threads_dict, title="Clean threads dict"),
|
|
68
|
+
DebugView(data=process_dict, title="Process"),
|
|
69
|
+
DebugView(data=threads_dict, title="Thread"),
|
|
70
|
+
]),
|
|
71
|
+
ButtonListWidget(buttons=[
|
|
72
|
+
AutoLinkWidget(label="Back to Task Dashboard", route_name="list_tools"),
|
|
73
|
+
]),
|
|
74
|
+
]
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
@debug_router.get("/celery_list_tasks", name="celery_list_tasks")
|
|
78
|
+
async def celery_list_tasks(
|
|
79
|
+
request: Request,
|
|
80
|
+
view_builder=Depends(get_view_builder)
|
|
81
|
+
):
|
|
82
|
+
settings = TasksRunnerSettings()
|
|
83
|
+
data = discover_celery_tasks_from_app(settings.celery_app_path)
|
|
84
|
+
schedule = discover_celery_periodic_tasks(settings.celery_app_path)
|
|
85
|
+
|
|
86
|
+
return view_builder.generate(
|
|
87
|
+
request,
|
|
88
|
+
title="Celery list",
|
|
89
|
+
widgets=[
|
|
90
|
+
DebugView(data=data, title="Celery Tasks"),
|
|
91
|
+
DebugView(data=schedule, title="Celery Scheduled Tasks"),
|
|
92
|
+
]
|
|
93
|
+
)
|
|
94
|
+
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
import psutil
|
|
4
|
+
from fastapi import Query
|
|
5
|
+
from pydantic import BaseModel
|
|
6
|
+
from pympler import muppy, summary
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
from fastapi import APIRouter
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
menu_memory_router = APIRouter()
|
|
13
|
+
|
|
14
|
+
class MemTypeStat(BaseModel):
|
|
15
|
+
type: str
|
|
16
|
+
count: int
|
|
17
|
+
size_bytes: float
|
|
18
|
+
size_percent: float
|
|
19
|
+
|
|
20
|
+
class MemModuleStat(BaseModel):
|
|
21
|
+
module: str
|
|
22
|
+
count: int
|
|
23
|
+
size_bytes: float
|
|
24
|
+
size_percent: float
|
|
25
|
+
|
|
26
|
+
class MemOverview(BaseModel):
|
|
27
|
+
total_objects: int
|
|
28
|
+
total_size_bytes: float
|
|
29
|
+
process_rss_bytes: int
|
|
30
|
+
stats_by_type: List[MemTypeStat]
|
|
31
|
+
stats_by_module: List[MemModuleStat]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@menu_memory_router.get("/memory/overview", response_model=MemOverview)
|
|
35
|
+
def memory_overview(
|
|
36
|
+
type_limit: int = Query(10, description="Top N types to return"),
|
|
37
|
+
module_limit: int = Query(10, description="Top N modules to return")
|
|
38
|
+
):
|
|
39
|
+
# gather live objects
|
|
40
|
+
all_objs = muppy.get_objects()
|
|
41
|
+
# summary by type
|
|
42
|
+
sum_type = summary.summarize(all_objs)
|
|
43
|
+
sum_type.sort(key=lambda row: row[2], reverse=True)
|
|
44
|
+
top_types = sum_type[:type_limit]
|
|
45
|
+
# summary by module
|
|
46
|
+
sum_mod = summary.summarize(all_objs, groupby='module')
|
|
47
|
+
sum_mod.sort(key=lambda row: row[2], reverse=True)
|
|
48
|
+
top_modules = sum_mod[:module_limit]
|
|
49
|
+
|
|
50
|
+
# total counts and sizes
|
|
51
|
+
total_objects = len(all_objs)
|
|
52
|
+
total_size = sum(row[2] for row in sum_type)
|
|
53
|
+
|
|
54
|
+
# process RSS
|
|
55
|
+
process_rss = psutil.Process().memory_info().rss
|
|
56
|
+
|
|
57
|
+
# build response lists
|
|
58
|
+
stats_by_type = [
|
|
59
|
+
MemTypeStat(
|
|
60
|
+
type=row[0], count=row[1], size_bytes=row[2],
|
|
61
|
+
size_percent=(row[2] / total_size * 100 if total_size else 0)
|
|
62
|
+
) for row in top_types
|
|
63
|
+
]
|
|
64
|
+
stats_by_module = [
|
|
65
|
+
MemModuleStat(
|
|
66
|
+
module=row[0], count=row[1], size_bytes=row[2],
|
|
67
|
+
size_percent=(row[2] / total_size * 100 if total_size else 0)
|
|
68
|
+
) for row in top_modules
|
|
69
|
+
]
|
|
70
|
+
|
|
71
|
+
return MemOverview(
|
|
72
|
+
total_objects=total_objects,
|
|
73
|
+
total_size_bytes=total_size,
|
|
74
|
+
process_rss_bytes=process_rss,
|
|
75
|
+
stats_by_type=stats_by_type,
|
|
76
|
+
stats_by_module=stats_by_module,
|
|
77
|
+
)
|