优化: 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:
1 parent
ecdebdd6c0
commit
95dfe8504d
20 files changed
+3494
-121
No files matched your search
+34
-3
@@ -11,6 +11,17 @@ use axum::{
|
||||
use clap::{Parser, Subcommand};
|
||||
use std::sync::Arc;
|
||||
|
||||
// ⚠ 共享实现,修改需同步至 mysql/ssh/redis-proxy/src/main.rs
|
||||
/// 默认请求日志路径(未设置 MONGO_PROXY_LOG 时): exe同目录 logs/mongo-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 = "mongo-proxy")]
|
||||
#[command(about = "MongoDB HTTP proxy with connection pooling")]
|
||||
@@ -154,13 +165,32 @@ enum Commands {
|
||||
Connections,
|
||||
}
|
||||
|
||||
// ⚠ 共享实现,修改需同步至 mysql/ssh/redis-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
|
||||
run_server(&config_path, port, host).await
|
||||
}
|
||||
Some(Commands::Find { conn, collection, filter, projection, limit, skip, format }) => {
|
||||
run_find(&args.server, &conn, &collection, &filter, &format, projection.as_deref(), limit, skip)
|
||||
@@ -184,7 +214,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
list_connections(&args.server)
|
||||
}
|
||||
None => {
|
||||
run_server(&args.config, None, None).await
|
||||
run_server(&config_path, None, None).await
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -201,7 +231,8 @@ async fn run_server(config_path: &str, port: Option<u16>, host: Option<String>)
|
||||
config.server.host = host;
|
||||
}
|
||||
|
||||
let log_path = std::env::var("MONGO_PROXY_LOG").ok();
|
||||
let log_path = std::env::var("MONGO_PROXY_LOG").ok()
|
||||
.or_else(|| Some(default_log_path("mongo-proxy")));
|
||||
let logger = Arc::new(logger::RequestLogger::new(log_path.as_deref()));
|
||||
if logger.is_enabled() {
|
||||
println!("Request logging: enabled");
|
||||
|
||||
Reference in new issue
Block a user