diff --git a/.localized b/.localized new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/grz/.gitignore b/grz/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..a81c8ee121952cf06bfaf9ff9988edd8cded763c --- /dev/null +++ b/grz/.gitignore @@ -0,0 +1,138 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ diff --git a/grz/LICENSE b/grz/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..9e32cdef1625daed25cf365c865f01050877cff3 --- /dev/null +++ b/grz/LICENSE @@ -0,0 +1,127 @@ + 木兰宽松许可证, 第2版 + + 木兰宽松许可证, 第2版 + 2020年1月 http://license.coscl.org.cn/MulanPSL2 + + + 您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束: + + 0. 定义 + + “软件”是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。 + + “贡献”是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。 + + “贡献者”是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。 + + “法人实体”是指提交贡献的机构及其“关联实体”。 + + “关联实体”是指,对“本许可证”下的行为方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。 + + 1. 授予版权许可 + + 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。 + + 2. 授予专利许可 + + 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。 + + 3. 无商标许可 + + “本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可,但您为满足第4条规定的声明义务而必须使用除外。 + + 4. 分发限制 + + 您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。 + + 5. 免责声明与责任限制 + + “软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。 + + 6. 语言 + “本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。 + + 条款结束 + + 如何将木兰宽松许可证,第2版,应用到您的软件 + + 如果您希望将木兰宽松许可证,第2版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步: + + 1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字; + + 2, 请您在软件包的一级目录下创建以“LICENSE”为名的文件,将整个许可证文本放入该文件中; + + 3, 请将如下声明文本放入每个源文件的头部注释中。 + + Copyright (c) [Year] [name of copyright holder] + [Software Name] is licensed under Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. + + + Mulan Permissive Software License,Version 2 + + Mulan Permissive Software License,Version 2 (Mulan PSL v2) + January 2020 http://license.coscl.org.cn/MulanPSL2 + + Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions: + + 0. Definition + + Software means the program and related documents which are licensed under this License and comprise all Contribution(s). + + Contribution means the copyrightable work licensed by a particular Contributor under this License. + + Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License. + + Legal Entity means the entity making a Contribution and all its Affiliates. + + Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity. + + 1. Grant of Copyright License + + Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not. + + 2. Grant of Patent License + + Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken. + + 3. No Trademark License + + No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in Section 4. + + 4. Distribution Restriction + + You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software. + + 5. Disclaimer of Warranty and Limitation of Liability + + THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + + 6. Language + + THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL. + + END OF THE TERMS AND CONDITIONS + + How to Apply the Mulan Permissive Software License,Version 2 (Mulan PSL v2) to Your Software + + To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps: + + i Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner; + + ii Create a file named “LICENSE” which contains the whole context of this License in the first directory of your software package; + + iii Attach the statement to the appropriate annotated syntax at the beginning of each source file. + + + Copyright (c) [Year] [name of copyright holder] + [Software Name] is licensed under Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. diff --git a/grz/LICENSE.html b/grz/LICENSE.html new file mode 100644 index 0000000000000000000000000000000000000000..ae4224f716b35f2f2d497b01e432176dd2c6221e --- /dev/null +++ b/grz/LICENSE.html @@ -0,0 +1,9 @@ +Copyright (c) [2024] [Xurui] +[grz] is licensed under Mulan PubL v2. +You can use this software according to the terms and conditions of the Mulan PubL v2. +You may obtain a copy of Mulan PubL v2 at: + http://license.coscl.org.cn/MulanPubL-2.0 +THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +See the Mulan PubL v2 for more details. \ No newline at end of file diff --git a/grz/README.md b/grz/README.md new file mode 100644 index 0000000000000000000000000000000000000000..e27deb000fab0128138482ea8d7705de929656e4 --- /dev/null +++ b/grz/README.md @@ -0,0 +1,193 @@ +# Grz - openGauss 自动巡检工具 + +## 项目概述 + +        **Grz** 是专为 openGauss 数据库开发的自动巡检工具,旨在简化和优化数据库的监控与管理操作。该工具参考了 Oracle 的 Orz 工具和达梦数据库的 Drz 工具,帮助用户通过简单的命令获取数据库的健康状况和性能指标。 + +        Grz 工具能够将用户输入的简单命令自动转换为底层复杂操作,如通过输入 `grz status` 获取数据库状态。此外,Grz 支持生成 HTML 格式的巡检报告,便于管理员对数据库状态和性能指标进行综合分析。 + +## 功能模块 + +Grz 工具采用模块化设计,包含以下主要模块: + +- **命令采集模块**:收集并验证用户输入的指令。 + +- **命令解析模块**:将简单命令映射为底层复杂操作。  + +- **命令执行模块**:使用 `subprocess` 模块执行解析后的复杂命令。  + +- **错误处理模块**:确保在执行过程中捕获并记录所有错误信息。 + +## 安装指南 + +### 环境要求 + +- Python 3.6+ +- openGauss 企业版数据库环境 +- 必需的 Python 库:`argparse`, `subprocess`, `logging` + +### 安装步骤 + +1. 确保openGauss 企业版数据库环境正确 + +2. 克隆或下载本项目代码: + +```bash +git clone https://gitee.com/cndba/orz.git +or +pip install grz==1.2.0 +``` + +## 使用方法 + +### 1. 常见命令操作 + +| 命令 | 描述 | +| ------------------------------------- | ------------------- | +| `grz help` | 显示所有命令的帮助信息 | +| `grz start` | 启动 openGauss | +| `grz stop` | 停止 openGauss | +| `grz restart` | 重启 openGauss | +| `grz status` | 查看 openGauss 状态 | +| `grz generateconf` | 生成配置文件 | +| `grz check` | 检查 openGauss 整体健康状态 | +| `grz checkos ` | 检查操作系统参数 | +| `grz checkperf` | 检查数据库性能 | +| `grz wdr ` | 生成 WDR 巡检报告 | +| `grz collect ` | 收集数据库运行日志 | + +### 2. 使用示例 + +        在使用之前,请确保当前环境已正确配置为企业版本的数据库。仅企业版本数据库提供所需的运维命令。Grz工具会将用户输入的简化命令映射到相应的运维命令,并执行这些命令以返回结果。以下为一些常用操作命令示例: + +1. **启动 openGauss**: + + ```bash + grz start + ``` + +2. **查看数据库状态**: + + ```bash + grz status + ``` + +3. **生成 WDR 巡检报告**: + + 请注意,访问WDR快照数据需要具有sysadmin或monadmin权限。因此,必须使用root账户或其他具有相应权限的账户来生成WDR诊断报告。在执行以下命令时,将在指定路径下创建HTML文件,并连接至系统库postgres,默认端口号为5432。接下来,进入gsql模式,用户可以选择不同的快照及输出格式,以生成HTML格式的WDR报告。 + + ```bash + grz wdr /file_path + ``` + +4. **收集运行日志**: + + 执行命令后根据界面输出提示,进入相应的日志收集目录,解压收集的日志,并检查数据库日志。 + + ```bash + grz collect "20240818 01:01" "20240818 23:59" + ``` + +### 3. 帮助信息 + +可以`help` 参数查看帮助信息: + +```bash +grz help +``` + +输出: + +```bash +❯ grz help + +Available commands: + +    start        - Start the openGauss database + +    stop         - Stop the openGauss database + +    restart      - Restart the openGauss database + +    ---------------------------------------------------------------------------- + +    status       - Show detailed status of the database cluster + +    generateconf - Generate and distribute configuration files + +    check        - Check cluster state with specified option + +    checkos      - Check operating system compatibility + +    checkperf    - Check system performance  + +    ---------------------------------------------------------------------------- + +    wdr          - Generate WDR performance report (requires --file_path) + +    collect      - Collect diagnostic logs (requires --start_time, --end_time) + +    help         - Show this help message +``` + +## 代码结构 + +``` +grz +├── LICENSE.html +├── README.md +├── dist +│   ├── grz-1.3.0-py3-none-any.whl +│   └── grz-1.3.0.tar.gz +├── pyproject.toml +├── setup.py +├── src +│   ├── grz +│   │   ├── CommandCollector +│   │   │   ├── Collector.py +│   │   │   ├── __init__.py +│   │   │   └── __pycache__ +│   │   │   ├── Collector.cpython-310.pyc +│   │   │   └── __init__.cpython-310.pyc +│   │   ├── CommandParser +│   │   │   ├── Parser.py +│   │   │   ├── __init__.py +│   │   │   └── __pycache__ +│   │   │   ├── Parser.cpython-310.pyc +│   │   │   └── __init__.cpython-310.pyc +│   │   ├── ErrorHandler +│   │   │   ├── Handler.py +│   │   │   ├── __init__.py +│   │   │   └── __pycache__ +│   │   │   ├── Handler.cpython-310.pyc +│   │   │   └── __init__.cpython-310.pyc +│   │   └── grz.py +│   └── grz.egg-info +│   ├── PKG-INFO +│   ├── SOURCES.txt +│   ├── dependency_links.txt +│   ├── entry_points.txt +│   └── top_level.txt +└── tests +12 directories, 24 files +``` + +## 错误处理 + +Grz 工具内置错误处理模块,能够在执行过程中捕获并记录所有错误信息,包括缺失参数、无效命令等。日志文件保存在项目根目录下,便于用户进行后续的审计和问题排查。 + +## 未来开发 + +Grz 工具后续计划包括: + +- **增加命令支持**:涵盖更多数据库监控、备份和恢复功能。 +- **增强错误处理**:增加自动恢复机制,减少手动干预。 +- **性能优化**:优化工具执行效率,降低资源消耗。 + +## 贡献 + +如果您有任何建议或改进意见,欢迎提交 Issue 或 Pull Request。您的贡献将帮助 Grz 工具更好地服务 openGauss 社区。 + +## 许可证 + +本项目使用 Mulan PSL v2 许可证 - 有关详细信息,请参见 `LICENSE` 文件。 diff --git a/grz/dist/grz-1.2.0-py3-none-any.whl b/grz/dist/grz-1.2.0-py3-none-any.whl new file mode 100644 index 0000000000000000000000000000000000000000..87f491f0c03b43a6a94b84587f98a8008992259b Binary files /dev/null and b/grz/dist/grz-1.2.0-py3-none-any.whl differ diff --git a/grz/dist/grz-1.2.0.tar.gz b/grz/dist/grz-1.2.0.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..3243466b540afd16c23c5a82257f6ec1d5ae5ae8 Binary files /dev/null and b/grz/dist/grz-1.2.0.tar.gz differ diff --git a/grz/pyproject.toml b/grz/pyproject.toml new file mode 100644 index 0000000000000000000000000000000000000000..39844a0b3857d175f75c888bba9d775f6b9ba5cd --- /dev/null +++ b/grz/pyproject.toml @@ -0,0 +1,28 @@ +[build-system] +requires = ["setuptools", "wheel"] # 构建项目所需依赖 +build-backend = "setuptools.build_meta" + +[project] +name = "grz" # 项目名称 +version = "1.2.0" # 项目版本 +description = "This is a widget designed for openGauss Database inspection Tool!" # 简要描述 +readme = "README.md" # 项目的说明文件 +requires-python = ">=3.6" # Python版本要求 +license = {text = "License: GPL version 3, excluding DRM provisions"} # 许可证 +authors = [{name = "RuiXu", email = "ruixu@std.uestc.edu.cn"}] +classifiers = [ + "Programming Language :: Python :: 3", + 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', +] + +dependencies = [ + # 示例依赖,如 'requests' +] + + +[tool.setuptools] +packages = ["grz", "grz.CommandCollector", "grz.CommandParser", "grz.ErrorHandler"] + +[project.scripts] # 定义命令行入口 +grz = "grz.grz:main" + diff --git a/grz/setup.py b/grz/setup.py new file mode 100644 index 0000000000000000000000000000000000000000..c914d4e4e9f8a4451809a365a82af3997db3edda --- /dev/null +++ b/grz/setup.py @@ -0,0 +1,18 @@ +from setuptools import setup, find_packages + +setup( + name='grz', + version='1.2.0', + description='This is a widget designed for openGauss Database inspection Tool!', + author='RuiXu', + author_email='ruixu@std.uestc.edu.cn', + license='Mulan PSL v2', # 或其他许可证 + packages=find_packages(where='src'), # 查找 src 目录中的包 + package_dir={'': 'src'}, # 指定包的根目录 + entry_points={ + 'console_scripts': [ + 'grz=grz.grz:main', # 将命令 `orz` 映射到 `orz/orz.py` 中的 `main` 函数 + ], + }, + python_requires='>=3.6', # Python 版本要求 +) \ No newline at end of file diff --git a/grz/src/grz.egg-info/PKG-INFO b/grz/src/grz.egg-info/PKG-INFO new file mode 100644 index 0000000000000000000000000000000000000000..93b4ba7cc7f0b34cba847f208e186ec80e7345c9 --- /dev/null +++ b/grz/src/grz.egg-info/PKG-INFO @@ -0,0 +1,202 @@ +Metadata-Version: 2.1 +Name: grz +Version: 1.2.0 +Summary: This is a widget designed for openGauss Database inspection Tool! +Author: RuiXu +Author-email: RuiXu +License: License: GPL version 3, excluding DRM provisions +Classifier: Programming Language :: Python :: 3 +Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3) +Requires-Python: >=3.6 +Description-Content-Type: text/markdown +License-File: LICENSE.html + +# Grz - openGauss 自动巡检工具 + +## 项目概述 + +        **Grz** 是专为 openGauss 数据库开发的自动巡检工具,旨在简化和优化数据库的监控与管理操作。该工具参考了 Oracle 的 Orz 工具和达梦数据库的 Drz 工具,帮助用户通过简单的命令获取数据库的健康状况和性能指标。 + +        Grz 工具能够将用户输入的简单命令自动转换为底层复杂操作,如通过输入 `grz status` 获取数据库状态。此外,Grz 支持生成 HTML 格式的巡检报告,便于管理员对数据库状态和性能指标进行综合分析。 + +## 功能模块 + +Grz 工具采用模块化设计,包含以下主要模块: + +- **命令采集模块**:收集并验证用户输入的指令。 + +- **命令解析模块**:将简单命令映射为底层复杂操作。  + +- **命令执行模块**:使用 `subprocess` 模块执行解析后的复杂命令。  + +- **错误处理模块**:确保在执行过程中捕获并记录所有错误信息。 + +## 安装指南 + +### 环境要求 + +- Python 3.6+ +- openGauss 企业版数据库环境 +- 必需的 Python 库:`argparse`, `subprocess`, `logging` + +### 安装步骤 + +1. 确保openGauss 企业版数据库环境正确 + +2. 克隆或下载本项目代码: + +```bash +git clone https://gitee.com/cndba/orz +or +pip install grz +``` + +## 使用方法 + +### 1. 常见命令操作 + +| 命令 | 描述 | +| ------------------------------------- | ------------------- | +| `grz help` | 显示所有命令的帮助信息 | +| `grz start` | 启动 openGauss | +| `grz stop` | 停止 openGauss | +| `grz restart` | 重启 openGauss | +| `grz status` | 查看 openGauss 状态 | +| `grz generateconf` | 生成配置文件 | +| `grz check` | 检查 openGauss 整体健康状态 | +| `grz checkos ` | 检查操作系统参数 | +| `grz checkperf` | 检查数据库性能 | +| `grz wdr ` | 生成 WDR 报告 | +| `grz collect ` | 收集数据库运行日志 | + +### 2. 使用示例 + +以下为一些常用操作命令示例: + +1. **启动 openGauss**: + + ```bash + grz start + ``` + +2. **查看数据库状态**: + + ```bash + grz status + ``` + +3. **生成 WDR 报告**: + + ```bash + grz wdr /file_path + ``` + +4. **收集运行日志**: + + ```bash + grz collect "20240818 01:01" "20240818 23:59" + ``` + +### 3. 帮助信息 + +可以`help` 参数查看帮助信息: + +```bash +grz help +``` + +输出: + +```bash +❯ grz help + +Available commands: + +    start        - Start the openGauss database + +    stop         - Stop the openGauss database + +    restart      - Restart the openGauss database + +    ---------------------------------------------------------------------------- + +    status       - Show detailed status of the database cluster + +    generateconf - Generate and distribute configuration files + +    check        - Check cluster state with specified option + +    checkos      - Check operating system compatibility + +    checkperf    - Check system performance  + +    ---------------------------------------------------------------------------- + +    wdr          - Generate WDR performance report (requires --file_path) + +    collect      - Collect diagnostic logs (requires --start_time, --end_time) + +    help         - Show this help message +``` + +## 代码结构 + +``` +grz +├── LICENSE.html +├── README.md +├── dist +│   ├── grz-1.3.0-py3-none-any.whl +│   └── grz-1.3.0.tar.gz +├── pyproject.toml +├── setup.py +├── src +│   ├── grz +│   │   ├── CommandCollector +│   │   │   ├── Collector.py +│   │   │   ├── __init__.py +│   │   │   └── __pycache__ +│   │   │   ├── Collector.cpython-310.pyc +│   │   │   └── __init__.cpython-310.pyc +│   │   ├── CommandParser +│   │   │   ├── Parser.py +│   │   │   ├── __init__.py +│   │   │   └── __pycache__ +│   │   │   ├── Parser.cpython-310.pyc +│   │   │   └── __init__.cpython-310.pyc +│   │   ├── ErrorHandler +│   │   │   ├── Handler.py +│   │   │   ├── __init__.py +│   │   │   └── __pycache__ +│   │   │   ├── Handler.cpython-310.pyc +│   │   │   └── __init__.cpython-310.pyc +│   │   └── grz.py +│   └── grz.egg-info +│   ├── PKG-INFO +│   ├── SOURCES.txt +│   ├── dependency_links.txt +│   ├── entry_points.txt +│   └── top_level.txt +└── tests +12 directories, 24 files +``` + +## 错误处理 + +Grz 工具内置错误处理模块,能够在执行过程中捕获并记录所有错误信息,包括缺失参数、无效命令等。日志文件保存在项目根目录下,便于用户进行后续的审计和问题排查。 + +## 未来开发 + +Grz 工具后续计划包括: + +- **增加命令支持**:涵盖更多数据库监控、备份和恢复功能。 +- **增强错误处理**:增加自动恢复机制,减少手动干预。 +- **性能优化**:优化工具执行效率,降低资源消耗。 + +## 贡献 + +如果您有任何建议或改进意见,欢迎提交 Issue 或 Pull Request。您的贡献将帮助 Grz 工具更好地服务 openGauss 社区。 + +## 许可证 + +本项目使用 Mulan PSL v2 许可证 - 有关详细信息,请参见 `LICENSE` 文件。 diff --git a/grz/src/grz.egg-info/SOURCES.txt b/grz/src/grz.egg-info/SOURCES.txt new file mode 100644 index 0000000000000000000000000000000000000000..6b17b290258996188f4f513fddbfda5d65ce8e17 --- /dev/null +++ b/grz/src/grz.egg-info/SOURCES.txt @@ -0,0 +1,16 @@ +LICENSE.html +README.md +pyproject.toml +setup.py +src/grz/grz.py +src/grz.egg-info/PKG-INFO +src/grz.egg-info/SOURCES.txt +src/grz.egg-info/dependency_links.txt +src/grz.egg-info/entry_points.txt +src/grz.egg-info/top_level.txt +src/grz/CommandCollector/Collector.py +src/grz/CommandCollector/__init__.py +src/grz/CommandParser/Parser.py +src/grz/CommandParser/__init__.py +src/grz/ErrorHandler/Handler.py +src/grz/ErrorHandler/__init__.py \ No newline at end of file diff --git a/grz/src/grz.egg-info/dependency_links.txt b/grz/src/grz.egg-info/dependency_links.txt new file mode 100644 index 0000000000000000000000000000000000000000..8b137891791fe96927ad78e64b0aad7bded08bdc --- /dev/null +++ b/grz/src/grz.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/grz/src/grz.egg-info/entry_points.txt b/grz/src/grz.egg-info/entry_points.txt new file mode 100644 index 0000000000000000000000000000000000000000..1f27e5280320eca416244d661f74fd5cd8636888 --- /dev/null +++ b/grz/src/grz.egg-info/entry_points.txt @@ -0,0 +1,2 @@ +[console_scripts] +grz = grz.grz:main diff --git a/grz/src/grz.egg-info/top_level.txt b/grz/src/grz.egg-info/top_level.txt new file mode 100644 index 0000000000000000000000000000000000000000..969f4e7294e09f32de5e3f6067bbe8cae87441bb --- /dev/null +++ b/grz/src/grz.egg-info/top_level.txt @@ -0,0 +1 @@ +grz diff --git a/grz/src/grz/CommandCollector/Collector.py b/grz/src/grz/CommandCollector/Collector.py new file mode 100644 index 0000000000000000000000000000000000000000..6baf960a4af6920e70c486fb4ab01ce7da7c7d2a --- /dev/null +++ b/grz/src/grz/CommandCollector/Collector.py @@ -0,0 +1,36 @@ +# CommandCollector/Collector.py + +import argparse + +class CommandCollector: + def __init__(self): + self.parser = argparse.ArgumentParser(description="Command collector for openGauss operations") + self.subparsers = self.parser.add_subparsers(dest="command", required=True) + + # 定义各个命令 + self.subparsers.add_parser("start", help="启动 openGauss") + self.subparsers.add_parser("stop", help="停止 openGauss") + self.subparsers.add_parser("restart", help="重启 openGauss") + self.subparsers.add_parser("status", help="查看 openGauss 状态") + self.subparsers.add_parser("generateconf", help="生成配置文件") + self.subparsers.add_parser("check", help="检查 openGauss 整体健康状态") + + checkos_parser = self.subparsers.add_parser("checkos", help="检查操作系统参数") + checkos_parser.add_argument("option", help="检查选项") + + self.subparsers.add_parser("checkperf", help="检查性能") + + wdr_parser = self.subparsers.add_parser("wdr", help="生成 WDR 报告") + wdr_parser.add_argument("file_path", help="WDR 报告的文件路径") + + collect_parser = self.subparsers.add_parser("collect", help="收集数据库运行日志") + collect_parser.add_argument("start_time", help="日志收集的开始时间") + collect_parser.add_argument("end_time", help="日志收集的结束时间") + + self.subparsers.add_parser("help", help="显示所有命令的帮助信息") + + def set_command(self, command): + self.command = command + + def get_command(self): + return self.parser.parse_args() # 返回解析后的命令对象 diff --git a/grz/src/grz/CommandCollector/__init__.py b/grz/src/grz/CommandCollector/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/grz/src/grz/CommandCollector/__pycache__/Collector.cpython-310.pyc b/grz/src/grz/CommandCollector/__pycache__/Collector.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ccd531942219070db9b063336042fb70b768fe40 Binary files /dev/null and b/grz/src/grz/CommandCollector/__pycache__/Collector.cpython-310.pyc differ diff --git a/grz/src/grz/CommandCollector/__pycache__/__init__.cpython-310.pyc b/grz/src/grz/CommandCollector/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..06d7a4644f52dfc8cfb8397939bea8f79ce15013 Binary files /dev/null and b/grz/src/grz/CommandCollector/__pycache__/__init__.cpython-310.pyc differ diff --git a/grz/src/grz/CommandParser/Parser.py b/grz/src/grz/CommandParser/Parser.py new file mode 100644 index 0000000000000000000000000000000000000000..9d5ccc82e2c1b573d054b535ee4c5315bbc9bf4d --- /dev/null +++ b/grz/src/grz/CommandParser/Parser.py @@ -0,0 +1,75 @@ +# CommandParser/Parser.py +import subprocess +from ..ErrorHandler.Handler import ErrorHandler + +def get_current_port(): + return 5432 + +def generate_help_message(): + help_text = """Available commands: + start - Start the openGauss database + stop - Stop the openGauss database + restart - Restart the openGauss database + ---------------------------------------------------------------------------- + status - Show detailed status of the database cluster + generateconf - Generate and distribute configuration files + check - Check cluster state with specified option + checkos - Check operating system compatibility + checkperf - Check system performance + ---------------------------------------------------------------------------- + wdr - Generate WDR performance report (requires --file_path) + collect - Collect diagnostic logs (requires --start_time, --end_time) + help - Show this help message""" + return help_text + +class CommandParser: + def __init__(self): + self.error_handler = ErrorHandler() + self.command_map = { + "start": "gs_om -t start", + "stop": "gs_om -t stop", + "restart": "gs_om -t restart", + "status": "gs_om -t status --detail", + "generateconf": "gs_om -t generateconf -X /opt/software/openGauss/clusterconfig.xml --distribute", + "check": "gs_check -U omm -i CheckClusterState", + "checkos": lambda option: f'gs_checkos -i {option}', + "checkperf": "gs_checkperf", + "wdr": lambda file_path: f'touch {file_path} && gsql -d postgres -p {get_current_port()} -r', + "collect": lambda start_time, end_time: f'gs_collector --begin-time="{start_time}" --end-time="{end_time}"', + "help": '' + } + + def parse_and_execute_command(self, args): + command = args.command.lower() + available_commands = list(self.command_map.keys()) + + if not self.error_handler.check_invalid_command(command, available_commands): + return + + required_args_map = { + "checkos": ["option"], + "wdr": ["file_path"], + "collect": ["start_time", "end_time"] + } + + if command in required_args_map: + required_args = required_args_map[command] + if not self.error_handler.check_missing_argument(args, required_args): + return + + if command == "help": + print(generate_help_message()) + return + + if callable(self.command_map[command]): + if command == "checkos": + full_command = self.command_map[command](args.option) + elif command == "wdr": + full_command = self.command_map[command](args.file_path) + elif command == "collect": + full_command = self.command_map[command](args.start_time, args.end_time) + else: + full_command = self.command_map[command] + + result = subprocess.run(full_command, shell=True, capture_output=True, text=True) + print(result.stdout if result.returncode == 0 else result.stderr) diff --git a/grz/src/grz/CommandParser/__init__.py b/grz/src/grz/CommandParser/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/grz/src/grz/CommandParser/__pycache__/Parser.cpython-310.pyc b/grz/src/grz/CommandParser/__pycache__/Parser.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..39f52ac6ec0c12cca6cf4aaa19f6c94c663b0f9d Binary files /dev/null and b/grz/src/grz/CommandParser/__pycache__/Parser.cpython-310.pyc differ diff --git a/grz/src/grz/CommandParser/__pycache__/__init__.cpython-310.pyc b/grz/src/grz/CommandParser/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1eae8682fe78475300c95fc829536de09ce6d9a9 Binary files /dev/null and b/grz/src/grz/CommandParser/__pycache__/__init__.cpython-310.pyc differ diff --git a/grz/src/grz/ErrorHandler/Handler.py b/grz/src/grz/ErrorHandler/Handler.py new file mode 100644 index 0000000000000000000000000000000000000000..e54028cbf0f32c207339afb27c7e42d3eea85e99 --- /dev/null +++ b/grz/src/grz/ErrorHandler/Handler.py @@ -0,0 +1,39 @@ +# ErrorHandler/Handler.py + +class ErrorHandler: + def handle_error(self, error): + if isinstance(error, ValueError): + print(f"[Error] Invalid input: {error}") + elif isinstance(error, FileNotFoundError): + print("[Error] File not found. Please check the file path.") + elif isinstance(error, PermissionError): + print("[Error] Permission denied. Please check your permissions.") + elif isinstance(error, KeyError): + print(f"[Error] Missing key: {error}") + else: + print(f"[Error] An unexpected error occurred: {error}") + + def check_missing_argument(self, args, required_args): + """ + 检查是否缺少必要的参数。 + :param args: 用户提供的参数。 + :param required_args: 当前命令所需的参数列表。 + :return: 缺少参数则返回False,否则返回True。 + """ + missing_args = [arg for arg in required_args if not getattr(args, arg, None)] + if missing_args: + print(f"[Error] Missing required arguments: {', '.join(missing_args)}") + return False + return True + + def check_invalid_command(self, command, available_commands): + """ + 检查命令是否有效。 + :param command: 用户输入的命令。 + :param available_commands: 支持的命令列表。 + :return: 若命令有效则返回True否则返回False。 + """ + if command not in available_commands: + print(f"[Error] Unknown command '{command}'. Type 'help' to see available commands.") + return False + return True diff --git a/grz/src/grz/ErrorHandler/__init__.py b/grz/src/grz/ErrorHandler/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/grz/src/grz/ErrorHandler/__pycache__/Handler.cpython-310.pyc b/grz/src/grz/ErrorHandler/__pycache__/Handler.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6cfa64296e5ded25b328c8bf51f1e700959207ab Binary files /dev/null and b/grz/src/grz/ErrorHandler/__pycache__/Handler.cpython-310.pyc differ diff --git a/grz/src/grz/ErrorHandler/__pycache__/__init__.cpython-310.pyc b/grz/src/grz/ErrorHandler/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5cb39f0830e487136454d4c76ac7cafac94c161c Binary files /dev/null and b/grz/src/grz/ErrorHandler/__pycache__/__init__.cpython-310.pyc differ diff --git a/grz/src/grz/grz.py b/grz/src/grz/grz.py new file mode 100644 index 0000000000000000000000000000000000000000..72bad9717c9bc30d00c2e8fb2981225a10da0af4 --- /dev/null +++ b/grz/src/grz/grz.py @@ -0,0 +1,21 @@ +# main.py + +import argparse +from .CommandCollector.Collector import CommandCollector +from .CommandParser.Parser import CommandParser +from .ErrorHandler.Handler import ErrorHandler + +def grz(): + collector = CommandCollector() + command_args = collector.get_command() # 获取解析后的命令对象 + error_handler = ErrorHandler() + + try: + # 直接使用解析后的命令对象 + CommandParser().parse_and_execute_command(command_args) # 使用解析的命令 + except Exception as e: + error_handler.handle_error(e) + +def main(): + grz() +