Django TBase Admin
Django TBase Admin 是一个强大的 Django 管理模块,专门用于系统性能监控和数据库优化。该模块提供了直观的 Web 界面,让管理员可以轻松查看系统状态、清理过期数据和优化数据库性能。
✨ 主要功能
📊 性能监控仪表板
- 实时显示数据库表统计信息
- 监控表大小和记录数量
- 提供可视化性能指标
- 自动刷新和状态指示器
🧹 Session 管理
- 查看当前活跃 sessions 数量
- 清理过期 sessions
- 释放数据库空间
- 批量处理支持
📈 Hitcount 数据管理
- 统计访问记录数据
- 按时间范围清理历史数据
- 支持批量操作和预览模式
- 性能优化的删除策略
⚡ 数据库优化
- 表优化操作
- 索引重建
- 查询性能分析
- 智能表选择
🚀 快速开始
安装
使用 pip 安装:
pip install django-tbase-admin
配置
- 在
settings.py中添加模块:
INSTALLED_APPS = [
# ... 其他应用
'tbase_admin',
]
- 在主项目的
urls.py中包含模块路由:
from django.urls import path, include
urlpatterns = [
# ... 其他 URL
path('tbase-admin/', include('tbase_admin.urls')),
]
- 运行数据库迁移:
python manage.py migrate
- 收集静态文件:
python manage.py collectstatic
访问
使用管理员账号登录 Django Admin,然后访问 /tbase-admin/performance/ 进入性能仪表板。
📖 详细文档
核心功能
性能仪表板
访问路径:/tbase-admin/performance/
仪表板显示以下信息:
- 数据库表统计:各表的行数和占用空间
- 实时数据刷新:点击刷新按钮获取最新数据
- 可视化图表:表大小和行数的直观展示
Sessions 清理
功能:清理过期的用户会话数据
操作步骤:
- 在性能仪表板找到 "Sessions 管理" 区域
- 点击 "清理 Sessions" 按钮
- 系统会自动清理过期会话并显示删除的记录数
Hitcount 数据清理
功能:清理网站的访问统计数据
参数设置:
- 保留天数:删除多少天前的数据(默认 30 天)
- 批量大小:每次处理的数据量(默认 5000)
- 预览模式:显示将要删除的数据量,不实际删除
数据库表优化
功能:优化数据库表结构,提高查询性能
操作步骤:
- 在仪表板找到 "表优化" 区域
- 选择要优化的表(可多选)
- 点击 "优化选中表" 按钮
- 等待优化完成
管理命令
模块提供了以下管理命令:
# 清理过期 sessions
python manage.py tbase_clearsessions
# 清理 hitcount 数据
python manage.py tbase_clearhitcount --days=30 --batch-size=5000
# 预览模式清理
python manage.py tbase_clearhitcount --dry-run
API 接口
模块提供 RESTful API 用于集成:
GET /tbase-admin/api/stats/ # 获取数据库统计
POST /tbase-admin/cleanup/sessions/ # 清理 sessions
POST /tbase-admin/cleanup/hitcount/ # 清理 hitcount
POST /tbase-admin/optimize/tables/ # 优化表
⚙️ 配置选项
可以在 settings.py 中添加自定义配置:
TBASE_ADMIN = {
'DEFAULT_BATCH_SIZE': 5000,
'DEFAULT_CLEANUP_DAYS': 30,
'MONITORED_TABLES': [
'django_session',
'hitcount_hit',
'hitcount_hit_count',
'tbase_post_post',
'tbase_page_basepage',
'django_admin_log'
],
'ALERT_THRESHOLDS': {
'SESSION_COUNT_WARNING': 10000,
'TABLE_SIZE_WARNING_MB': 500,
'HITCOUNT_COUNT_WARNING': 100000,
}
}
🔧 开发
开发环境设置
- 克隆仓库:
git clone https://github.com/terrychan/django-tbase-admin.git
cd django-tbase-admin
- 创建虚拟环境:
python -m venv venv
source venv/bin/activate # Linux/Mac
# 或
venv\Scripts\activate # Windows
- 安装开发依赖:
pip install -e ".[dev]"
- 运行测试:
pytest
代码质量
项目使用以下工具确保代码质量:
- Black: 代码格式化
- Flake8: 代码风格检查
- MyPy: 类型检查
black tbase_admin/
flake8 tbase_admin/
mypy tbase_admin/
📋 系统要求
- Python 3.8+
- Django 3.2+
- MySQL 5.7+ 或 PostgreSQL 10+ (推荐)
🤝 贡献
欢迎贡献代码!请遵循以下步骤:
- Fork 项目
- 创建功能分支 (
git checkout -b feature/AmazingFeature) - 提交更改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 开启 Pull Request
📄 许可证
本项目采用 GPL-3.0 许可证。详情请参阅 LICENSE 文件。
🙏 致谢
- 感谢 Django 社区的优秀框架
- 感谢所有贡献者的支持
📞 支持
如果遇到问题或需要帮助:
注意: 这是一个开源项目,欢迎社区贡献和反馈!
Metadata
Release files for django-tbase-admin 1.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_tbase_admin-1.1.3.tar.gz | 87.4 kB | Without provenance | Details for django_tbase_admin-1.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_tbase_admin-1.1.3-py3-none-any.whl | Python 3 | none | any | Details for django_tbase_admin-1.1.3-py3-none-any.whl |
Total release size: 151.4 kB
Release files / django_tbase_admin-1.1.3.tar.gz
| Download URL | django_tbase_admin-1.1.3.tar.gz |
|---|---|
| Size | 87.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6fc6a91941ee7b20fbc033cc41ac294335dfe8bfa1bb0787cef05143f6768adc
|
|
BLAKE2b-256 checksum How to use checksums |
d2d07d1bb1c4ce2a966c6c1ccfb014c993955c6f6f225de8f289fa00f1be4995
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.9.20
|
Release files / django_tbase_admin-1.1.3-py3-none-any.whl
| Download URL | django_tbase_admin-1.1.3-py3-none-any.whl |
|---|---|
| Size | 64.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eb3eec077c00927f739a91b97b1a40c7d6ecb530493b7e7d96a6e38a82624875
|
|
BLAKE2b-256 checksum How to use checksums |
be52e06f2478db39702928be5b164ddc65d7f3f73a7f8b83bb7f43cbb616b5fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.9.20
|
Security for django-tbase-admin 1.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.