优化: ssh/mongo/redis-proxy 超时分级与日志默认开

- ssh: exec_timeout_secs 600s(408断会话)/idle 300→1800s/日志级别规则/截断500→2000
- mongo/redis: query_timeout 60s + idle_timeout 落配置
- 四代理: 日志默认开启(default_log_path exe同目录logs/),未设env也记录
- mysql: default_log_path 共享实现注释同步
This commit is contained in:
lxy committed 2026-10-28 22:56:02 +08:00
1 parent ecdebdd6c0
commit 95dfe8504d
20 files changed
+3494 -121

No files matched your search

+58 -9
View File
@@ -8,6 +8,17 @@ use axum::{routing::{get, post}, Router};
use clap::{Parser, Subcommand};
use std::sync::Arc;
// ⚠ 共享实现,修改需同步至 mysql/mongo/ssh-proxy/src/main.rs
/// 默认请求日志路径(未设置 REDIS_PROXY_LOG 时): exe同目录 logs/redis-proxy.log
fn default_log_path(name: &str) -> String {
match std::env::current_exe() {
Ok(exe) => exe.parent()
.map(|d| d.join("logs").join(format!("{}.log", name)).to_string_lossy().into_owned())
.unwrap_or_else(|| format!("{}.log", name)),
Err(_) => format!("{}.log", name),
}
}
#[derive(Parser, Debug)]
#[command(name = "redis-proxy")]
#[command(about = "Redis HTTP proxy with connection pooling")]
@@ -31,18 +42,55 @@ enum Commands {
Connections,
}
// ⚠ 共享实现,修改需同步至 mysql/ssh/mongo-proxy/src/main.rs
/// 将相对路径基于可执行文件所在目录解析为绝对路径
fn resolve_config_path(path: &str) -> String {
if std::path::Path::new(path).is_absolute() || path.starts_with('~') {
return path.to_string();
}
match std::env::current_exe() {
Ok(exe) => {
if let Some(dir) = exe.parent() {
dir.join(path).to_string_lossy().into_owned()
} else {
path.to_string()
}
}
Err(_) => path.to_string(),
}
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let args = Args::parse();
let config_path = resolve_config_path(&args.config);
match args.command {
Some(Commands::Server { port, host }) => run_server(&args.config, port, host).await,
Some(Commands::Run { conn, command, args: ref keys }) => { let c = get_cli(&args.server)?; Ok(c.run(&conn, &command, keys)?) },
Some(Commands::Get { conn, key }) => { let c = get_cli(&args.server)?; Ok(c.get(&conn, &key)?) },
Some(Commands::Set { conn, key, value, ttl }) => { let c = get_cli(&args.server)?; Ok(c.set(&conn, &key, &value, ttl)?) },
Some(Commands::Del { conn, key: ref keys }) => { let c = get_cli(&args.server)?; Ok(c.del(&conn, keys)?) },
Some(Commands::Keys { conn, pattern }) => { let c = get_cli(&args.server)?; Ok(c.keys(&conn, &pattern)?) },
Some(Commands::Connections) => { let c = get_cli(&args.server)?; Ok(c.list_connections()?) },
None => run_server(&args.config, None, None).await,
Some(Commands::Server { port, host }) => run_server(&config_path, port, host).await,
Some(Commands::Run { conn, command, args: ref keys }) => {
let c = get_cli(&args.server)?;
Ok(c.run(&conn, &command, keys)?)
}
Some(Commands::Get { conn, key }) => {
let c = get_cli(&args.server)?;
Ok(c.get(&conn, &key)?)
}
Some(Commands::Set { conn, key, value, ttl }) => {
let c = get_cli(&args.server)?;
Ok(c.set(&conn, &key, &value, ttl)?)
}
Some(Commands::Del { conn, key: ref keys }) => {
let c = get_cli(&args.server)?;
Ok(c.del(&conn, keys)?)
}
Some(Commands::Keys { conn, pattern }) => {
let c = get_cli(&args.server)?;
Ok(c.keys(&conn, &pattern)?)
}
Some(Commands::Connections) => {
let c = get_cli(&args.server)?;
Ok(c.list_connections()?)
}
None => run_server(&config_path, None, None).await,
}
}
@@ -61,7 +109,8 @@ async fn run_server(config_path: &str, port: Option<u16>, host: Option<String>)
if let Some(port) = port { config.server.port = port; }
if let Some(host) = host { config.server.host = host; }
let log_path = std::env::var("REDIS_PROXY_LOG").ok();
let log_path = std::env::var("REDIS_PROXY_LOG").ok()
.or_else(|| Some(default_log_path("redis-proxy")));
let logger = Arc::new(logger::RequestLogger::new(log_path.as_deref()));
if logger.is_enabled() { println!("Request logging: enabled"); }