| Crates.io | oor |
| lib.rs | oor |
| version | 1.1.0 |
| created_at | 2025-12-04 09:37:32.99993+00 |
| updated_at | 2025-12-05 02:35:01.53443+00 |
| description | System operations and monitoring CLI for Optima infrastructure |
| homepage | https://github.com/Optima-Chat/optima-ops-cli-rust |
| repository | https://github.com/Optima-Chat/optima-ops-cli-rust |
| max_upload_size | |
| id | 1966252 |
| size | 327,775 |
Rust 重写版本的 Optima 基础设施运维监控工具
这是 optima-ops-cli 的 Rust 实现版本,旨在提供更高的性能、更好的类型安全性和更小的二进制体积。
| 特性 | TypeScript 版本 | Rust 版本 |
|---|---|---|
| 性能 | Node.js 运行时 | 原生编译,更快 |
| 内存占用 | ~50-100MB | ~5-10MB |
| 启动时间 | ~200-500ms | ~10-50ms |
| 二进制大小 | N/A (需要 Node) | ~10-15MB (独立) |
| 类型安全 | TypeScript | Rust (编译期检查) |
| 并发模型 | 单线程异步 | 多线程异步 (Tokio) |
# 安装 Rust (如果还没有)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
cd optima-ops-cli-rust
# 开发构建
cargo build
# 发布构建 (优化版本)
cargo build --release
# 运行
./target/release/optima-ops-rust --help
# 或使用短别名
./target/release/oor --help
cargo install --path .
# 现在可以直接使用
optima-ops-rust --help
oor --help
目前实现的命令模块:
# 检查服务健康状态
oor services health [--env prod] [--service user-auth] [--type core|mcp|all] [--json]
# 获取容器状态
oor services status [--env prod] [--service user-auth] [--type core|mcp|all] [--json]
# EC2 实例信息
oor infra ec2 [--env prod] [--json]
# Docker 容器资源使用
oor infra docker [--env prod] [--json]
# 磁盘使用情况
oor infra disk [--env prod] [--details] [--json]
# 显示环境配置
oor env [--json]
# 显示版本信息
oor version [--json]
# 设置环境
export OPTIMA_OPS_ENV=production # 或 stage, development
# 自定义 SSH 密钥路径
export OPTIMA_SSH_KEY=~/.ssh/custom-key
# JSON 输出
export OPTIMA_OUTPUT=json
# 启用命令计时
export OPTIMA_TIMING=1
# 调试模式
export DEBUG=1
# Rust 日志级别
export RUST_LOG=debug
配置文件位置: ~/.config/optima-ops-cli/config.json
{
"environment": "production",
"ec2": {
"production": {
"host": "ec2-prod.optima.shop",
"user": "ec2-user",
"keyPath": "~/.ssh/optima-ec2-key"
}
},
"aws": {
"region": "ap-southeast-1"
}
}
服务配置: services-config.json (与可执行文件同目录)
src/
├── main.rs # 程序入口
├── config.rs # 配置管理和类型定义
├── error.rs # 错误类型和处理
├── output.rs # 输出格式化 (表格, JSON, 美化)
├── ssh.rs # SSH 客户端和命令白名单
├── utils.rs # 工具函数
└── commands/ # 命令模块
├── mod.rs
├── env.rs # 环境信息
├── version.rs # 版本信息
├── services.rs # 服务管理
└── infra.rs # 基础设施监控
与 TypeScript 版本相同的 SSH 命令白名单:
docker ps, docker logs, docker inspect, cat, grep, ls 等docker restart, systemctl restart (需确认)rm, docker rm, kill, shutdown, 管道符 |, 重定向 >初步性能对比 (相同操作):
| 操作 | TypeScript 版本 | Rust 版本 | 提升 |
|---|---|---|---|
| 启动时间 | ~300ms | ~20ms | 15x |
| 内存占用 | ~80MB | ~8MB | 10x |
| services health | ~4s | ~3.2s | 1.25x |
| infra ec2 | ~3.4s | ~2.8s | 1.2x |
| 二进制大小 | N/A | ~12MB | N/A |
注: 网络延迟占主要时间,纯计算任务提升更明显
cargo test
# 检查编译错误
cargo check
# 运行 clippy (Rust linter)
cargo clippy
# 格式化代码
cargo fmt
src/commands/ 创建新模块clap::Args)execute() 方法main.rs 注册命令示例:
// src/commands/mycommand.rs
use clap::Args;
use crate::config::AppConfig;
use crate::error::Result;
#[derive(Args)]
pub struct MyCommand {
#[arg(long)]
option: Option<String>,
}
impl MyCommand {
pub async fn execute(&self, config: &AppConfig) -> Result<()> {
// 实现逻辑
Ok(())
}
}
当你需要处理大量服务、频繁 SSH 连接或实时监控时,Rust 的性能优势明显。
在容器或嵌入式环境中,Rust 的低内存占用是巨大优势。
单个二进制文件,无需安装运行时,简化部署。
编译期捕获所有类型错误,减少运行时故障。
Tokio 的异步运行时在高并发场景下表现出色。
欢迎贡献代码! 请遵循:
cargo fmt, cargo clippy)MIT
Status: 🚧 Alpha (核心功能可用)
Last Updated: 2025-11-18