|
|
|
|
@ -1,307 +1,242 @@
|
|
|
|
|
# 故障检测系统数据库设计文档
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
/* 统一本文件所有表格列宽与对齐 */
|
|
|
|
|
table {
|
|
|
|
|
width: 100%;
|
|
|
|
|
table-layout: fixed; /* 固定布局,列宽按百分比分配 */
|
|
|
|
|
border-collapse: collapse;
|
|
|
|
|
}
|
|
|
|
|
table th, table td {
|
|
|
|
|
text-align: left; /* 每一列首部对齐(左对齐) */
|
|
|
|
|
vertical-align: top; /* 条目从上到下对齐 */
|
|
|
|
|
}
|
|
|
|
|
/* 六列宽度统一为固定比例,确保从上到下列宽一致 */
|
|
|
|
|
table th:nth-child(1), table td:nth-child(1) { width: 16%; }
|
|
|
|
|
table th:nth-child(2), table td:nth-child(2) { width: 16%; }
|
|
|
|
|
table th:nth-child(3), table td:nth-child(3) { width: 8%; }
|
|
|
|
|
table th:nth-child(4), table td:nth-child(4) { width: 12%; }
|
|
|
|
|
table th:nth-child(5), table td:nth-child(5) { width: 12%; }
|
|
|
|
|
table th:nth-child(6), table td:nth-child(6) { width: 36%; }
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
## 1. 数据库概述
|
|
|
|
|
|
|
|
|
|
### 1.1 设计目标
|
|
|
|
|
- 支持Hadoop集群故障检测与自动修复系统
|
|
|
|
|
- 提供高效的日志存储和查询能力
|
|
|
|
|
- 支持执行日志、集群状态等核心业务数据
|
|
|
|
|
- 确保数据一致性和系统性能
|
|
|
|
|
|
|
|
|
|
### 1.2 技术选型
|
|
|
|
|
- **数据库**: PostgreSQL 14+
|
|
|
|
|
- **主要类型**: `JSONB`、`UUID`、`INET`、`TIMESTAMPTZ`
|
|
|
|
|
- **字符集**: UTF8
|
|
|
|
|
- **时区**: 推荐使用UTC并统一为`TIMESTAMPTZ`
|
|
|
|
|
- **后端**: `FastAPI` + `Uvicorn` + `Pydantic`
|
|
|
|
|
- **数据库访问**: `SQLAlchemy` + `asyncpg`
|
|
|
|
|
- **缓存/消息**: `Redis`(状态缓存/速率限制)
|
|
|
|
|
- **日志采集**: `Apache Flume`(可选替代:`Fluent Bit`)
|
|
|
|
|
- **前端**: `Vue3` + `Vite` + `Element Plus` + `ECharts`
|
|
|
|
|
- **实时通信**: WebSocket(状态与诊断结果推送)
|
|
|
|
|
- **多智能体编排**: `LangGraph`/`Ray`(Diagnosis/Repair/Policy Agent)
|
|
|
|
|
- **可观测性**: `Prometheus` + `Grafana`(API与Agent指标监控)
|
|
|
|
|
|
|
|
|
|
### 1.3 命名规范
|
|
|
|
|
- 表名:小写字母+下划线,复数形式
|
|
|
|
|
- 字段名:小写字母+下划线
|
|
|
|
|
- 索引名:idx_表名_字段名
|
|
|
|
|
- 外键名:fk_表名_字段名
|
|
|
|
|
|
|
|
|
|
## 2. 数据库结构设计
|
|
|
|
|
|
|
|
|
|
### 2.1 核心业务表
|
|
|
|
|
|
|
|
|
|
#### 2.1.1 执行日志表 (exec_logs)
|
|
|
|
|
记录自动修复脚本的执行过程和结果
|
|
|
|
|
|
|
|
|
|
| 字段名 | 数据类型 | 长度 | 是否为空 | 默认值 | 说明 |
|
|
|
|
|
| :----- | :------- | :--- | :------ | :----- | :--- |
|
|
|
|
|
| id | BIGINT | - | NOT NULL | - | (PK) 主键ID |
|
|
|
|
|
| exec_id | CHARACTER | - | NOT NULL | - | 执行唯一标识 |
|
|
|
|
|
| fault_id | CHARACTER | - | NOT NULL | - | 关联故障标识(无外键) |
|
|
|
|
|
| command_type | CHARACTER | - | NOT NULL | - | 命令类型 |
|
|
|
|
|
| script_path | CHARACTER | - | NULL | - | 脚本路径 |
|
|
|
|
|
| command_content | TEXT | - | NOT NULL | - | 执行的命令内容 |
|
|
|
|
|
| target_nodes | JSONB | - | NULL | - | 目标执行节点(JSONB) |
|
|
|
|
|
| risk_level | CHARACTER | - | NOT NULL | 'medium'::character | 风险级别(low/medium/high) |
|
|
|
|
|
| execution_status | CHARACTER | - | NOT NULL | 'pending'::character | 执行状态(pending/running/success/failed/timeout) |
|
|
|
|
|
| start_time | TIMESTAMP | - | NULL | - | 开始执行时间 |
|
|
|
|
|
| end_time | TIMESTAMP | - | NULL | - | 结束执行时间 |
|
|
|
|
|
| duration | INTEGER | - | NULL | - | 执行时长(秒) |
|
|
|
|
|
| stdout_log | TEXT | - | NULL | - | 标准输出日志 |
|
|
|
|
|
| stderr_log | TEXT | - | NULL | - | 错误输出日志 |
|
|
|
|
|
| exit_code | INTEGER | - | NULL | - | 退出码 |
|
|
|
|
|
| operator | CHARACTER | - | NOT NULL | 'system'::character | 操作人 |
|
|
|
|
|
| created_at | TIMESTAMP | - | NOT NULL | now() | 创建时间 |
|
|
|
|
|
| updated_at | TIMESTAMP | - | NOT NULL | now() | 更新时间 |
|
|
|
|
|
|
|
|
|
|
**索引/约束设计:**
|
|
|
|
|
- PRIMARY KEY: (id)
|
|
|
|
|
- INDEX: idx_exec_logs_end_time (end_time)
|
|
|
|
|
- INDEX: idx_exec_logs_fault_id (fault_id)
|
|
|
|
|
- INDEX: idx_exec_logs_start_time (start_time)
|
|
|
|
|
- INDEX: idx_exec_logs_status (execution_status)
|
|
|
|
|
#### 2.1.2 节点信息表 (nodes)
|
|
|
|
|
记录集群内各节点的状态信息
|
|
|
|
|
|
|
|
|
|
| 字段名 | 数据类型 | 长度 | 是否为空 | 默认值 | 说明 |
|
|
|
|
|
| :----- | :------- | :--- | :------ | :----- | :--- |
|
|
|
|
|
| id | BIGINT | - | NOT NULL | - | (PK) 主键ID |
|
|
|
|
|
| uuid | UUID | - | NOT NULL | - | 节点唯一标识(UUID) |
|
|
|
|
|
| cluster_id | BIGINT | - | NOT NULL | - | 所属集群ID |
|
|
|
|
|
| hostname | CHARACTER | - | NOT NULL | - | 节点主机名 |
|
|
|
|
|
| ip_address | INET | - | NOT NULL | - | 节点IP地址(INET, 兼容IPv4/IPv6) |
|
|
|
|
|
| status | CHARACTER | - | NOT NULL | 'unknown'::character | 节点健康状态(healthy/unhealthy/warning/unknown) |
|
|
|
|
|
| last_heartbeat | TIMESTAMP | - | NULL | - | 最后心跳时间 |
|
|
|
|
|
| created_at | TIMESTAMP | - | NOT NULL | now() | 创建时间 |
|
|
|
|
|
| updated_at | TIMESTAMP | - | NOT NULL | now() | 更新时间 |
|
|
|
|
|
| ssh_user | CHARACTER | - | NULL | - | |
|
|
|
|
|
| ssh_password | CHARACTER | - | NULL | - | |
|
|
|
|
|
|
|
|
|
|
**索引/约束设计:**
|
|
|
|
|
- PRIMARY KEY: (id)
|
|
|
|
|
- INDEX: idx_nodes_cluster_id (cluster_id)
|
|
|
|
|
- INDEX: idx_nodes_ip_address (ip_address)
|
|
|
|
|
- INDEX: idx_nodes_last_heartbeat (last_heartbeat)
|
|
|
|
|
- INDEX: idx_nodes_status (status)
|
|
|
|
|
- INDEX: uk_cluster_hostname (cluster_id, hostname)
|
|
|
|
|
- FOREIGN KEY: FK(cluster_id) -> public.clusters(id)
|
|
|
|
|
#### 2.1.3 系统日志表 (system_logs)
|
|
|
|
|
存储从Flume采集的原始日志数据
|
|
|
|
|
|
|
|
|
|
| 字段名 | 数据类型 | 长度 | 是否为空 | 默认值 | 说明 |
|
|
|
|
|
| :----- | :------- | :--- | :------ | :----- | :--- |
|
|
|
|
|
| id | BIGINT | - | NOT NULL | - | (PK) 主键ID |
|
|
|
|
|
| log_id | CHARACTER | - | NOT NULL | - | 日志唯一标识 |
|
|
|
|
|
| fault_id | CHARACTER | - | NULL | - | 关联故障标识(无外键) |
|
|
|
|
|
| cluster_id | BIGINT | - | NULL | - | 关联集群ID |
|
|
|
|
|
| host | CHARACTER | - | NOT NULL | - | 主机名 |
|
|
|
|
|
| service | CHARACTER | - | NOT NULL | - | 服务名 |
|
|
|
|
|
| source | CHARACTER | - | NULL | - | 来源 |
|
|
|
|
|
| log_level | CHARACTER | - | NOT NULL | - | 日志级别(DEBUG/INFO/WARN/ERROR/FATAL) |
|
|
|
|
|
| message | TEXT | - | NOT NULL | - | 日志消息 |
|
|
|
|
|
| exception | TEXT | - | NULL | - | 异常堆栈 |
|
|
|
|
|
| raw_log | TEXT | - | NULL | - | 原始日志内容 |
|
|
|
|
|
| processed | BOOLEAN | - | NOT NULL | false | 是否已处理 |
|
|
|
|
|
| created_at | TIMESTAMP | - | NOT NULL | now() | 创建时间 |
|
|
|
|
|
|
|
|
|
|
**索引/约束设计:**
|
|
|
|
|
- PRIMARY KEY: (id)
|
|
|
|
|
- INDEX: idx_system_logs_cluster_id (cluster_id)
|
|
|
|
|
- INDEX: idx_system_logs_fault_id (fault_id)
|
|
|
|
|
- INDEX: idx_system_logs_level (log_level)
|
|
|
|
|
- INDEX: idx_system_logs_processed (processed)
|
|
|
|
|
- INDEX: idx_system_logs_timestamp ("timestamp")
|
|
|
|
|
- FOREIGN KEY: FK(cluster_id) -> public.clusters(id)
|
|
|
|
|
#### 2.2.0 角色表 (roles)
|
|
|
|
|
系统角色定义
|
|
|
|
|
|
|
|
|
|
| 字段名 | 数据类型 | 长度 | 是否为空 | 默认值 | 说明 |
|
|
|
|
|
| :----- | :------- | :--- | :------ | :----- | :--- |
|
|
|
|
|
| id | BIGINT | - | NOT NULL | - | (PK) 主键ID |
|
|
|
|
|
| role_name | CHARACTER | - | NOT NULL | - | 角色名称 |
|
|
|
|
|
| role_key | CHARACTER | - | NOT NULL | - | 角色唯一标识 |
|
|
|
|
|
| description | CHARACTER | - | NULL | - | 角色描述 |
|
|
|
|
|
| is_system_role | BOOLEAN | - | NOT NULL | false | 是否为系统内置角色 |
|
|
|
|
|
| created_at | TIMESTAMP | - | NOT NULL | now() | 创建时间 |
|
|
|
|
|
| updated_at | TIMESTAMP | - | NOT NULL | now() | 更新时间 |
|
|
|
|
|
|
|
|
|
|
**索引/约束设计:**
|
|
|
|
|
- PRIMARY KEY: (id)
|
|
|
|
|
#### 2.2.1 权限表 (permissions)
|
|
|
|
|
系统权限定义
|
|
|
|
|
|
|
|
|
|
| 字段名 | 数据类型 | 长度 | 是否为空 | 默认值 | 说明 |
|
|
|
|
|
| :----- | :------- | :--- | :------ | :----- | :--- |
|
|
|
|
|
| id | BIGINT | - | NOT NULL | - | (PK) 主键ID |
|
|
|
|
|
| permission_name | CHARACTER | - | NOT NULL | - | 权限名称 |
|
|
|
|
|
| permission_key | CHARACTER | - | NOT NULL | - | 权限唯一标识 |
|
|
|
|
|
| description | CHARACTER | - | NULL | - | 权限描述 |
|
|
|
|
|
| created_at | TIMESTAMP | - | NOT NULL | now() | 创建时间 |
|
|
|
|
|
|
|
|
|
|
**索引/约束设计:**
|
|
|
|
|
- PRIMARY KEY: (id)
|
|
|
|
|
#### 2.2.2 角色-权限映射表 (role_permission_mapping)
|
|
|
|
|
多对多关系的中间表
|
|
|
|
|
|
|
|
|
|
| 字段名 | 数据类型 | 长度 | 是否为空 | 默认值 | 说明 |
|
|
|
|
|
| :----- | :------- | :--- | :------ | :----- | :--- |
|
|
|
|
|
| role_id | BIGINT | - | NOT NULL | - | (PK) 角色ID |
|
|
|
|
|
| permission_id | BIGINT | - | NOT NULL | - | (PK) 权限ID |
|
|
|
|
|
|
|
|
|
|
**索引/约束设计:**
|
|
|
|
|
- PRIMARY KEY: (role_id, permission_id)
|
|
|
|
|
- FOREIGN KEY: FK(permission_id) -> public.permissions(id)
|
|
|
|
|
- FOREIGN KEY: FK(role_id) -> public.roles(id)
|
|
|
|
|
#### 2.2.1 集群信息表 (clusters)
|
|
|
|
|
存储用户管理的集群信息
|
|
|
|
|
|
|
|
|
|
| 字段名 | 数据类型 | 长度 | 是否为空 | 默认值 | 说明 |
|
|
|
|
|
| :----- | :------- | :--- | :------ | :----- | :--- |
|
|
|
|
|
| id | BIGINT | - | NOT NULL | - | (PK) 主键ID |
|
|
|
|
|
| uuid | UUID | - | NOT NULL | - | 集群唯一标识(UUID) |
|
|
|
|
|
| name | CHARACTER | - | NOT NULL | - | 集群名称 |
|
|
|
|
|
| type | CHARACTER | - | NOT NULL | - | 集群类型 |
|
|
|
|
|
| node_count | INTEGER | - | NOT NULL | 0 | 集群节点数量 |
|
|
|
|
|
| health_status | CHARACTER | - | NOT NULL | 'unknown'::character | 集群健康状态(healthy/warning/error/unknown) |
|
|
|
|
|
| description | TEXT | - | NULL | - | 集群描述 |
|
|
|
|
|
| config_info | JSONB | - | NULL | - | 集群配置信息(JSONB) |
|
|
|
|
|
| created_at | TIMESTAMP | - | NOT NULL | now() | 创建时间 |
|
|
|
|
|
| updated_at | TIMESTAMP | - | NOT NULL | now() | 更新时间 |
|
|
|
|
|
| namenode_ip | INET | - | NULL | - | |
|
|
|
|
|
| namenode_psw | CHARACTER | - | NULL | - | |
|
|
|
|
|
| rm_ip | INET | - | NULL | - | |
|
|
|
|
|
| rm_psw | CHARACTER | - | NULL | - | |
|
|
|
|
|
|
|
|
|
|
**索引/约束设计:**
|
|
|
|
|
- PRIMARY KEY: (id)
|
|
|
|
|
#### 2.2.2 用户与集群映射表 (user_cluster_mapping)
|
|
|
|
|
管理用户和集群的多对多关系
|
|
|
|
|
|
|
|
|
|
| 字段名 | 数据类型 | 长度 | 是否为空 | 默认值 | 说明 |
|
|
|
|
|
| :----- | :------- | :--- | :------ | :----- | :--- |
|
|
|
|
|
| id | BIGINT | - | NOT NULL | - | (PK) 主键ID |
|
|
|
|
|
| user_id | BIGINT | - | NOT NULL | - | 用户ID |
|
|
|
|
|
| cluster_id | BIGINT | - | NOT NULL | - | 集群ID |
|
|
|
|
|
| role_id | BIGINT | - | NOT NULL | - | 角色ID |
|
|
|
|
|
| created_at | TIMESTAMP | - | NOT NULL | now() | 创建时间 |
|
|
|
|
|
|
|
|
|
|
**索引/约束设计:**
|
|
|
|
|
- PRIMARY KEY: (id)
|
|
|
|
|
- FOREIGN KEY: FK(cluster_id) -> public.clusters(id)
|
|
|
|
|
- FOREIGN KEY: FK(role_id) -> public.roles(id)
|
|
|
|
|
- FOREIGN KEY: FK(user_id) -> public.users(id)
|
|
|
|
|
#### 2.2.3 应用统一配置表 (app_configurations)
|
|
|
|
|
统一管理系统配置、告警规则和通知设置
|
|
|
|
|
|
|
|
|
|
| 字段名 | 数据类型 | 长度 | 是否为空 | 默认值 | 说明 |
|
|
|
|
|
| :----- | :------- | :--- | :------ | :----- | :--- |
|
|
|
|
|
| id | BIGINT | - | NOT NULL | - | (PK) 主键ID |
|
|
|
|
|
| config_type | CHARACTER | - | NOT NULL | - | 配置类型(system/alert_rule/notification/llm) |
|
|
|
|
|
| config_key | CHARACTER | - | NOT NULL | - | 配置键 |
|
|
|
|
|
| config_value | JSONB | - | NOT NULL | - | 配置值(JSONB) |
|
|
|
|
|
| description | CHARACTER | - | NULL | - | 配置描述 |
|
|
|
|
|
| is_enabled | BOOLEAN | - | NOT NULL | true | 是否启用 |
|
|
|
|
|
| created_at | TIMESTAMP | - | NOT NULL | now() | 创建时间 |
|
|
|
|
|
| updated_at | TIMESTAMP | - | NOT NULL | now() | 更新时间 |
|
|
|
|
|
|
|
|
|
|
**索引/约束设计:**
|
|
|
|
|
- PRIMARY KEY: (id)
|
|
|
|
|
- INDEX: idx_app_config_enabled (is_enabled)
|
|
|
|
|
#### 2.2.4 用户表 (users)
|
|
|
|
|
系统用户信息
|
|
|
|
|
|
|
|
|
|
| 字段名 | 数据类型 | 长度 | 是否为空 | 默认值 | 说明 |
|
|
|
|
|
| :----- | :------- | :--- | :------ | :----- | :--- |
|
|
|
|
|
| id | BIGINT | - | NOT NULL | - | (PK) 主键ID |
|
|
|
|
|
| username | CHARACTER | - | NOT NULL | - | 用户名 |
|
|
|
|
|
| email | CHARACTER | - | NOT NULL | - | 邮箱 |
|
|
|
|
|
| password_hash | CHARACTER | - | NOT NULL | - | 密码哈希 |
|
|
|
|
|
| full_name | CHARACTER | - | NOT NULL | - | 姓名 |
|
|
|
|
|
| is_active | BOOLEAN | - | NOT NULL | true | 是否激活 |
|
|
|
|
|
| last_login | TIMESTAMP | - | NULL | - | 最后登录时间 |
|
|
|
|
|
| created_at | TIMESTAMP | - | NOT NULL | now() | 创建时间 |
|
|
|
|
|
| updated_at | TIMESTAMP | - | NOT NULL | now() | 更新时间 |
|
|
|
|
|
|
|
|
|
|
**索引/约束设计:**
|
|
|
|
|
- PRIMARY KEY: (id)
|
|
|
|
|
#### 2.2.5 用户-角色映射表 (user_role_mapping)
|
|
|
|
|
用户与角色的多对多关系
|
|
|
|
|
|
|
|
|
|
| 字段名 | 数据类型 | 长度 | 是否为空 | 默认值 | 说明 |
|
|
|
|
|
| :----- | :------- | :--- | :------ | :----- | :--- |
|
|
|
|
|
| user_id | BIGINT | - | NOT NULL | - | (PK) 用户ID |
|
|
|
|
|
| role_id | BIGINT | - | NOT NULL | - | (PK) 角色ID |
|
|
|
|
|
|
|
|
|
|
**索引/约束设计:**
|
|
|
|
|
- PRIMARY KEY: (user_id, role_id)
|
|
|
|
|
- FOREIGN KEY: FK(role_id) -> public.roles(id)
|
|
|
|
|
- FOREIGN KEY: FK(user_id) -> public.users(id)
|
|
|
|
|
#### 2.2.6 操作审计表 (audit_logs)
|
|
|
|
|
记录用户操作审计日志
|
|
|
|
|
|
|
|
|
|
| 字段名 | 数据类型 | 长度 | 是否为空 | 默认值 | 说明 |
|
|
|
|
|
| :----- | :------- | :--- | :------ | :----- | :--- |
|
|
|
|
|
| id | BIGINT | - | NOT NULL | - | (PK) 主键ID |
|
|
|
|
|
| user_id | BIGINT | - | NULL | - | 用户ID |
|
|
|
|
|
| cluster_id | BIGINT | - | NULL | - | 集群ID |
|
|
|
|
|
| role_id | BIGINT | - | NULL | - | 角色ID |
|
|
|
|
|
| username | CHARACTER | - | NOT NULL | - | 用户名 |
|
|
|
|
|
| action | CHARACTER | - | NOT NULL | - | 操作动作 |
|
|
|
|
|
| resource_type | CHARACTER | - | NOT NULL | - | 资源类型 |
|
|
|
|
|
| resource_id | CHARACTER | - | NULL | - | 资源ID |
|
|
|
|
|
| ip_address | INET | - | NOT NULL | - | 请求来源IP(INET, 兼容IPv4/IPv6) |
|
|
|
|
|
| request_data | JSONB | - | NULL | - | 请求数据(JSONB) |
|
|
|
|
|
| response_status | INTEGER | - | NULL | - | 响应状态码 |
|
|
|
|
|
| created_at | TIMESTAMP | - | NOT NULL | now() | 创建时间 |
|
|
|
|
|
|
|
|
|
|
**索引/约束设计:**
|
|
|
|
|
- PRIMARY KEY: (id)
|
|
|
|
|
- INDEX: idx_audit_logs_action (action)
|
|
|
|
|
- INDEX: idx_audit_logs_cluster_id (cluster_id)
|
|
|
|
|
- INDEX: idx_audit_logs_created_at (created_at)
|
|
|
|
|
- INDEX: idx_audit_logs_role_id (role_id)
|
|
|
|
|
- INDEX: idx_audit_logs_user_id (user_id)
|
|
|
|
|
- FOREIGN KEY: FK(cluster_id) -> public.clusters(id)
|
|
|
|
|
- FOREIGN KEY: FK(role_id) -> public.roles(id)
|
|
|
|
|
- FOREIGN KEY: FK(user_id) -> public.users(id)
|
|
|
|
|
#### 2.3.1 修复脚本模板表 (repair_templates)
|
|
|
|
|
存储用于自动修复的脚本模板
|
|
|
|
|
|
|
|
|
|
| 字段名 | 数据类型 | 长度 | 是否为空 | 默认值 | 说明 |
|
|
|
|
|
| :----- | :------- | :--- | :------ | :----- | :--- |
|
|
|
|
|
| id | BIGINT | - | NOT NULL | - | (PK) 主键ID |
|
|
|
|
|
| template_name | CHARACTER | - | NOT NULL | - | 模板名称 |
|
|
|
|
|
| fault_type | CHARACTER | - | NOT NULL | - | 适用故障类型 |
|
|
|
|
|
| script_content | TEXT | - | NOT NULL | - | 脚本内容 |
|
|
|
|
|
| risk_level | CHARACTER | - | NOT NULL | 'medium'::character | 风险级别(low/medium/high) |
|
|
|
|
|
| description | TEXT | - | NULL | - | 模板描述 |
|
|
|
|
|
| parameters | JSONB | - | NULL | - | 模板参数定义(JSONB) |
|
|
|
|
|
| created_by | CHARACTER | - | NULL | - | 创建人 |
|
|
|
|
|
| created_at | TIMESTAMP | - | NOT NULL | now() | 创建时间 |
|
|
|
|
|
| updated_at | TIMESTAMP | - | NOT NULL | now() | 更新时间 |
|
|
|
|
|
|
|
|
|
|
**索引/约束设计:**
|
|
|
|
|
- PRIMARY KEY: (id)
|
|
|
|
|
- INDEX: idx_repair_templates_fault_type (fault_type)
|
|
|
|
|
# 数据库设计文档
|
|
|
|
|
|
|
|
|
|
## 1. 数据库概览
|
|
|
|
|
本数据库名为 `hadoop_fault_db`,包含核心业务表及系统日志表。
|
|
|
|
|
|
|
|
|
|
## 2. 表结构详述
|
|
|
|
|
|
|
|
|
|
### app_configurations (应用配置表)
|
|
|
|
|
**表名**: `app_configurations` (应用配置表)
|
|
|
|
|
|
|
|
|
|
**字段列表**:
|
|
|
|
|
| 序号 | 字段名 | 类型 | 说明 |
|
|
|
|
|
| :--- | :--- | :--- | :--- |
|
|
|
|
|
| 1 | id | bigint NOT NULL | 主键ID |
|
|
|
|
|
| 2 | config_type | character varying(20) NOT NULL | 配置类型(system/alert_rule/notification/llm) |
|
|
|
|
|
| 3 | config_key | character varying(100) NOT NULL | 配置键 |
|
|
|
|
|
| 4 | config_value | jsonb NOT NULL | 配置值(JSONB) |
|
|
|
|
|
| 5 | description | character varying(500) | 配置描述 |
|
|
|
|
|
| 6 | is_enabled | boolean DEFAULT true NOT NULL | 是否启用 |
|
|
|
|
|
| 7 | created_at | timestamp with time zone DEFAULT now() NOT NULL | 创建时间 |
|
|
|
|
|
| 8 | updated_at | timestamp with time zone DEFAULT now() NOT NULL | 更新时间 |
|
|
|
|
|
|
|
|
|
|
### chat_messages
|
|
|
|
|
**表名**: `chat_messages`
|
|
|
|
|
|
|
|
|
|
**字段列表**:
|
|
|
|
|
| 序号 | 字段名 | 类型 | 说明 |
|
|
|
|
|
| :--- | :--- | :--- | :--- |
|
|
|
|
|
| 1 | id | integer NOT NULL | |
|
|
|
|
|
| 2 | session_id | character varying NOT NULL | |
|
|
|
|
|
| 3 | role | character varying NOT NULL | |
|
|
|
|
|
| 4 | content | text NOT NULL | |
|
|
|
|
|
| 5 | created_at | timestamp with time zone | |
|
|
|
|
|
| 6 | reasoning | text | |
|
|
|
|
|
| 7 | username | character varying(64) | |
|
|
|
|
|
|
|
|
|
|
### chat_sessions
|
|
|
|
|
**表名**: `chat_sessions`
|
|
|
|
|
|
|
|
|
|
**字段列表**:
|
|
|
|
|
| 序号 | 字段名 | 类型 | 说明 |
|
|
|
|
|
| :--- | :--- | :--- | :--- |
|
|
|
|
|
| 1 | id | character varying NOT NULL | |
|
|
|
|
|
| 2 | user_id | integer | |
|
|
|
|
|
| 3 | title | character varying | |
|
|
|
|
|
| 4 | created_at | timestamp with time zone | |
|
|
|
|
|
| 5 | updated_at | timestamp with time zone | |
|
|
|
|
|
|
|
|
|
|
### cluster_metrics (集群指标表)
|
|
|
|
|
**表名**: `cluster_metrics` (集群指标表)
|
|
|
|
|
|
|
|
|
|
**字段列表**:
|
|
|
|
|
| 序号 | 字段名 | 类型 | 说明 |
|
|
|
|
|
| :--- | :--- | :--- | :--- |
|
|
|
|
|
| 1 | id | integer NOT NULL | |
|
|
|
|
|
| 2 | cluster_id | integer NOT NULL | |
|
|
|
|
|
| 3 | timestamp | timestamp with time zone NOT NULL | |
|
|
|
|
|
| 4 | cpu_avg | double precision | |
|
|
|
|
|
| 5 | mem_used_avg | double precision | |
|
|
|
|
|
| 6 | mem_free_avg | double precision | |
|
|
|
|
|
|
|
|
|
|
### clusters (集群表)
|
|
|
|
|
**表名**: `clusters` (集群表)
|
|
|
|
|
|
|
|
|
|
**字段列表**:
|
|
|
|
|
| 序号 | 字段名 | 类型 | 说明 |
|
|
|
|
|
| :--- | :--- | :--- | :--- |
|
|
|
|
|
| 1 | id | bigint NOT NULL | 主键ID |
|
|
|
|
|
| 2 | uuid | uuid NOT NULL | 集群唯一标识(UUID) |
|
|
|
|
|
| 3 | name | character varying(100) NOT NULL | 集群名称 |
|
|
|
|
|
| 4 | type | character varying(50) NOT NULL | 集群类型 |
|
|
|
|
|
| 5 | node_count | integer DEFAULT 0 NOT NULL | 集群节点数量 |
|
|
|
|
|
| 6 | health_status | character varying(20) DEFAULT 'unknown'::character varying NOT NULL | 集群健康状态(healthy/warning/error/unknown) |
|
|
|
|
|
| 7 | description | text | 集群描述 |
|
|
|
|
|
| 8 | config_info | jsonb | 集群配置信息(JSONB) |
|
|
|
|
|
| 9 | created_at | timestamp with time zone DEFAULT now() NOT NULL | 创建时间 |
|
|
|
|
|
| 10 | updated_at | timestamp with time zone DEFAULT now() NOT NULL | 更新时间 |
|
|
|
|
|
| 11 | namenode_ip | inet | |
|
|
|
|
|
| 12 | namenode_psw | character varying(255) | |
|
|
|
|
|
| 13 | rm_ip | inet | |
|
|
|
|
|
| 14 | rm_psw | character varying(255) | |
|
|
|
|
|
|
|
|
|
|
### hadoop_exec_logs (Hadoop执行日志表)
|
|
|
|
|
**表名**: `hadoop_exec_logs` (Hadoop执行日志表)
|
|
|
|
|
|
|
|
|
|
**字段列表**:
|
|
|
|
|
| 序号 | 字段名 | 类型 | 说明 |
|
|
|
|
|
| :--- | :--- | :--- | :--- |
|
|
|
|
|
| 1 | id | integer NOT NULL | |
|
|
|
|
|
| 2 | from_user_id | integer NOT NULL | |
|
|
|
|
|
| 3 | cluster_name | character varying(255) NOT NULL | |
|
|
|
|
|
| 4 | description | text | |
|
|
|
|
|
| 5 | start_time | timestamp with time zone | |
|
|
|
|
|
| 6 | end_time | timestamp with time zone | |
|
|
|
|
|
|
|
|
|
|
### hadoop_logs
|
|
|
|
|
**表名**: `hadoop_logs`
|
|
|
|
|
|
|
|
|
|
**字段列表**:
|
|
|
|
|
| 序号 | 字段名 | 类型 | 说明 |
|
|
|
|
|
| :--- | :--- | :--- | :--- |
|
|
|
|
|
| 1 | log_id | integer NOT NULL | |
|
|
|
|
|
| 2 | cluster_name | character varying(255) NOT NULL | |
|
|
|
|
|
| 3 | node_host | character varying(100) NOT NULL | |
|
|
|
|
|
| 4 | title | character varying(255) | |
|
|
|
|
|
| 5 | info | text | |
|
|
|
|
|
| 6 | log_time | timestamp with time zone NOT NULL | |
|
|
|
|
|
|
|
|
|
|
### node_metrics (节点指标表)
|
|
|
|
|
**表名**: `node_metrics` (节点指标表)
|
|
|
|
|
|
|
|
|
|
**字段列表**:
|
|
|
|
|
| 序号 | 字段名 | 类型 | 说明 |
|
|
|
|
|
| :--- | :--- | :--- | :--- |
|
|
|
|
|
| 1 | id | integer NOT NULL | |
|
|
|
|
|
| 2 | cluster_id | integer | |
|
|
|
|
|
| 3 | node_name | character varying(100) NOT NULL | |
|
|
|
|
|
| 4 | timestamp | timestamp with time zone NOT NULL | |
|
|
|
|
|
| 5 | cpu_usage | double precision | |
|
|
|
|
|
| 6 | mem_used | double precision | |
|
|
|
|
|
| 7 | mem_free | double precision | |
|
|
|
|
|
|
|
|
|
|
### nodes
|
|
|
|
|
**表名**: `nodes`
|
|
|
|
|
|
|
|
|
|
**字段列表**:
|
|
|
|
|
| 序号 | 字段名 | 类型 | 说明 |
|
|
|
|
|
| :--- | :--- | :--- | :--- |
|
|
|
|
|
| 1 | id | bigint NOT NULL | 主键ID |
|
|
|
|
|
| 2 | uuid | uuid NOT NULL | 节点唯一标识(UUID) |
|
|
|
|
|
| 3 | cluster_id | bigint NOT NULL | 所属集群ID |
|
|
|
|
|
| 4 | hostname | character varying(100) NOT NULL | 节点主机名 |
|
|
|
|
|
| 5 | ip_address | inet NOT NULL | 节点IP地址(INET, 兼容IPv4/IPv6) |
|
|
|
|
|
| 6 | status | character varying(20) DEFAULT 'unknown'::character varying NOT NULL | 节点健康状态(healthy/unhealthy/warning/unknown) |
|
|
|
|
|
| 7 | cpu_usage | numeric(5,2) | CPU使用率(%) |
|
|
|
|
|
| 8 | memory_usage | numeric(5,2) | 内存使用率(%) |
|
|
|
|
|
| 9 | disk_usage | numeric(5,2) | 磁盘使用率(%) |
|
|
|
|
|
| 10 | last_heartbeat | timestamp with time zone | 最后心跳时间 |
|
|
|
|
|
| 11 | created_at | timestamp with time zone DEFAULT now() NOT NULL | 创建时间 |
|
|
|
|
|
| 12 | updated_at | timestamp with time zone DEFAULT now() NOT NULL | 更新时间 |
|
|
|
|
|
| 13 | ssh_user | character varying(50) | |
|
|
|
|
|
| 14 | ssh_password | character varying(255) | |
|
|
|
|
|
|
|
|
|
|
### permissions
|
|
|
|
|
**表名**: `permissions`
|
|
|
|
|
|
|
|
|
|
**字段列表**:
|
|
|
|
|
| 序号 | 字段名 | 类型 | 说明 |
|
|
|
|
|
| :--- | :--- | :--- | :--- |
|
|
|
|
|
| 1 | id | bigint NOT NULL | 主键ID |
|
|
|
|
|
| 2 | permission_name | character varying(100) NOT NULL | 权限名称 |
|
|
|
|
|
| 3 | permission_key | character varying(100) NOT NULL | 权限唯一标识 |
|
|
|
|
|
| 4 | description | character varying(255) | 权限描述 |
|
|
|
|
|
| 5 | created_at | timestamp with time zone DEFAULT now() NOT NULL | 创建时间 |
|
|
|
|
|
|
|
|
|
|
### repair_templates
|
|
|
|
|
**表名**: `repair_templates`
|
|
|
|
|
|
|
|
|
|
**字段列表**:
|
|
|
|
|
| 序号 | 字段名 | 类型 | 说明 |
|
|
|
|
|
| :--- | :--- | :--- | :--- |
|
|
|
|
|
| 1 | id | bigint NOT NULL | 主键ID |
|
|
|
|
|
| 2 | template_name | character varying(100) NOT NULL | 模板名称 |
|
|
|
|
|
| 3 | fault_type | character varying(50) NOT NULL | 适用故障类型 |
|
|
|
|
|
| 4 | script_content | text NOT NULL | 脚本内容 |
|
|
|
|
|
| 5 | risk_level | character varying(20) DEFAULT 'medium'::character varying NOT NULL | 风险级别(low/medium/high) |
|
|
|
|
|
| 6 | description | text | 模板描述 |
|
|
|
|
|
| 7 | parameters | jsonb | 模板参数定义(JSONB) |
|
|
|
|
|
| 8 | created_by | character varying(50) | 创建人 |
|
|
|
|
|
| 9 | created_at | timestamp with time zone DEFAULT now() NOT NULL | 创建时间 |
|
|
|
|
|
| 10 | updated_at | timestamp with time zone DEFAULT now() NOT NULL | 更新时间 |
|
|
|
|
|
|
|
|
|
|
### role_permission_mapping (角色权限关联表)
|
|
|
|
|
**表名**: `role_permission_mapping` (角色权限关联表)
|
|
|
|
|
|
|
|
|
|
**字段列表**:
|
|
|
|
|
| 序号 | 字段名 | 类型 | 说明 |
|
|
|
|
|
| :--- | :--- | :--- | :--- |
|
|
|
|
|
| 1 | role_id | bigint NOT NULL | 角色ID |
|
|
|
|
|
| 2 | permission_id | bigint NOT NULL | 权限ID |
|
|
|
|
|
|
|
|
|
|
### roles
|
|
|
|
|
**表名**: `roles`
|
|
|
|
|
|
|
|
|
|
**字段列表**:
|
|
|
|
|
| 序号 | 字段名 | 类型 | 说明 |
|
|
|
|
|
| :--- | :--- | :--- | :--- |
|
|
|
|
|
| 1 | id | bigint NOT NULL | 主键ID |
|
|
|
|
|
| 2 | role_name | character varying(50) NOT NULL | 角色名称 |
|
|
|
|
|
| 3 | role_key | character varying(50) NOT NULL | 角色唯一标识 |
|
|
|
|
|
| 4 | description | character varying(255) | 角色描述 |
|
|
|
|
|
| 5 | is_system_role | boolean DEFAULT false NOT NULL | 是否为系统内置角色 |
|
|
|
|
|
| 6 | created_at | timestamp with time zone DEFAULT now() NOT NULL | 创建时间 |
|
|
|
|
|
| 7 | updated_at | timestamp with time zone DEFAULT now() NOT NULL | 更新时间 |
|
|
|
|
|
|
|
|
|
|
### sys_exec_logs (系统操作日志表)
|
|
|
|
|
**表名**: `sys_exec_logs` (系统操作日志表)
|
|
|
|
|
|
|
|
|
|
**字段列表**:
|
|
|
|
|
| 序号 | 字段名 | 类型 | 说明 |
|
|
|
|
|
| :--- | :--- | :--- | :--- |
|
|
|
|
|
| 1 | operation_id | uuid DEFAULT public.uuid_generate_v4() NOT NULL | |
|
|
|
|
|
| 2 | user_id | integer NOT NULL | |
|
|
|
|
|
| 3 | description | text NOT NULL | |
|
|
|
|
|
| 4 | operation_time | timestamp with time zone DEFAULT now() NOT NULL | |
|
|
|
|
|
|
|
|
|
|
### user_cluster_mapping
|
|
|
|
|
**表名**: `user_cluster_mapping`
|
|
|
|
|
|
|
|
|
|
**字段列表**:
|
|
|
|
|
| 序号 | 字段名 | 类型 | 说明 |
|
|
|
|
|
| :--- | :--- | :--- | :--- |
|
|
|
|
|
| 1 | id | bigint NOT NULL | 主键ID |
|
|
|
|
|
| 2 | user_id | bigint NOT NULL | 用户ID |
|
|
|
|
|
| 3 | cluster_id | bigint NOT NULL | 集群ID |
|
|
|
|
|
| 4 | role_id | bigint NOT NULL | 角色ID |
|
|
|
|
|
| 5 | created_at | timestamp with time zone DEFAULT now() NOT NULL | 创建时间 |
|
|
|
|
|
|
|
|
|
|
### user_role_mapping (用户角色关联表)
|
|
|
|
|
**表名**: `user_role_mapping` (用户角色关联表)
|
|
|
|
|
|
|
|
|
|
**字段列表**:
|
|
|
|
|
| 序号 | 字段名 | 类型 | 说明 |
|
|
|
|
|
| :--- | :--- | :--- | :--- |
|
|
|
|
|
| 1 | user_id | bigint NOT NULL | 用户ID |
|
|
|
|
|
| 2 | role_id | bigint NOT NULL | 角色ID |
|
|
|
|
|
|
|
|
|
|
### users (用户表)
|
|
|
|
|
**表名**: `users` (用户表)
|
|
|
|
|
|
|
|
|
|
**字段列表**:
|
|
|
|
|
| 序号 | 字段名 | 类型 | 说明 |
|
|
|
|
|
| :--- | :--- | :--- | :--- |
|
|
|
|
|
| 1 | id | bigint NOT NULL | 主键ID |
|
|
|
|
|
| 2 | username | character varying(50) NOT NULL | 用户名 |
|
|
|
|
|
| 3 | email | character varying(100) NOT NULL | 邮箱 |
|
|
|
|
|
| 4 | password_hash | character varying(255) NOT NULL | 密码哈希 |
|
|
|
|
|
| 5 | full_name | character varying(100) NOT NULL | 姓名 |
|
|
|
|
|
| 6 | is_active | boolean DEFAULT true NOT NULL | 是否激活 |
|
|
|
|
|
| 7 | last_login | timestamp with time zone | 最后登录时间 |
|
|
|
|
|
| 8 | created_at | timestamp with time zone DEFAULT now() NOT NULL | 创建时间 |
|
|
|
|
|
| 9 | updated_at | timestamp with time zone DEFAULT now() NOT NULL | 更新时间 |
|
|
|
|
|
|