mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-19 19:16:17 +00:00
Translation comment
This commit is contained in:
@@ -149,7 +149,6 @@ impl NotifierConfig {
|
|||||||
)
|
)
|
||||||
.build()
|
.build()
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
println!("Loaded config: {:?}", app_config);
|
|
||||||
match app_config.try_deserialize::<NotifierConfig>() {
|
match app_config.try_deserialize::<NotifierConfig>() {
|
||||||
Ok(app_config) => {
|
Ok(app_config) => {
|
||||||
println!("Parsed AppConfig: {:?} \n", app_config);
|
println!("Parsed AppConfig: {:?} \n", app_config);
|
||||||
|
|||||||
@@ -178,7 +178,6 @@ pub struct AppConfig {
|
|||||||
pub logger: Option<LoggerConfig>,
|
pub logger: Option<LoggerConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 为 AppConfig 实现 Default
|
|
||||||
impl AppConfig {
|
impl AppConfig {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
@@ -189,6 +188,7 @@ impl AppConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// implement default for AppConfig
|
||||||
impl Default for AppConfig {
|
impl Default for AppConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
|
|||||||
@@ -54,22 +54,22 @@ impl Collector {
|
|||||||
self.system
|
self.system
|
||||||
.refresh_processes(sysinfo::ProcessesToUpdate::Some(&[self.pid]), true);
|
.refresh_processes(sysinfo::ProcessesToUpdate::Some(&[self.pid]), true);
|
||||||
|
|
||||||
// 刷新网络接口列表和统计数据
|
// refresh the network interface list and statistics
|
||||||
self.networks.refresh(false); // 刷新网络统计数据
|
self.networks.refresh(false);
|
||||||
|
|
||||||
let process = self
|
let process = self
|
||||||
.system
|
.system
|
||||||
.process(self.pid)
|
.process(self.pid)
|
||||||
.ok_or_else(|| GlobalError::ProcessNotFound(self.pid.as_u32()))?;
|
.ok_or_else(|| GlobalError::ProcessNotFound(self.pid.as_u32()))?;
|
||||||
|
|
||||||
// CPU 指标
|
// CPU metrics
|
||||||
let cpu_usage = process.cpu_usage();
|
let cpu_usage = process.cpu_usage();
|
||||||
self.metrics.cpu_usage.record(cpu_usage as f64, &[]);
|
self.metrics.cpu_usage.record(cpu_usage as f64, &[]);
|
||||||
self.metrics
|
self.metrics
|
||||||
.cpu_utilization
|
.cpu_utilization
|
||||||
.record((cpu_usage / self.core_count as f32) as f64, &self.attributes.attributes);
|
.record((cpu_usage / self.core_count as f32) as f64, &self.attributes.attributes);
|
||||||
|
|
||||||
// 内存指标
|
// Memory metrics
|
||||||
self.metrics
|
self.metrics
|
||||||
.memory_usage
|
.memory_usage
|
||||||
.record(process.memory() as i64, &self.attributes.attributes);
|
.record(process.memory() as i64, &self.attributes.attributes);
|
||||||
@@ -77,7 +77,7 @@ impl Collector {
|
|||||||
.memory_virtual
|
.memory_virtual
|
||||||
.record(process.virtual_memory() as i64, &self.attributes.attributes);
|
.record(process.virtual_memory() as i64, &self.attributes.attributes);
|
||||||
|
|
||||||
// 磁盘I/O指标
|
// Disk I/O metrics
|
||||||
let disk_io = process.disk_usage();
|
let disk_io = process.disk_usage();
|
||||||
self.metrics.disk_io.record(
|
self.metrics.disk_io.record(
|
||||||
disk_io.read_bytes as i64,
|
disk_io.read_bytes as i64,
|
||||||
@@ -88,11 +88,11 @@ impl Collector {
|
|||||||
&[&self.attributes.attributes[..], &[KeyValue::new(DIRECTION, "write")]].concat(),
|
&[&self.attributes.attributes[..], &[KeyValue::new(DIRECTION, "write")]].concat(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// 网络I/O指标(对应 /system/network/internode)
|
// Network I/O indicators (corresponding to /system/network/internode)
|
||||||
let mut total_received: i64 = 0;
|
let mut total_received: i64 = 0;
|
||||||
let mut total_transmitted: i64 = 0;
|
let mut total_transmitted: i64 = 0;
|
||||||
|
|
||||||
// 按接口统计
|
// statistics by interface
|
||||||
for (interface_name, data) in self.networks.iter() {
|
for (interface_name, data) in self.networks.iter() {
|
||||||
total_received += data.total_received() as i64;
|
total_received += data.total_received() as i64;
|
||||||
total_transmitted += data.total_transmitted() as i64;
|
total_transmitted += data.total_transmitted() as i64;
|
||||||
@@ -122,7 +122,7 @@ impl Collector {
|
|||||||
.concat(),
|
.concat(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// 全局统计
|
// global statistics
|
||||||
self.metrics.network_io.record(
|
self.metrics.network_io.record(
|
||||||
total_received,
|
total_received,
|
||||||
&[&self.attributes.attributes[..], &[KeyValue::new(DIRECTION, "received")]].concat(),
|
&[&self.attributes.attributes[..], &[KeyValue::new(DIRECTION, "received")]].concat(),
|
||||||
@@ -132,12 +132,12 @@ impl Collector {
|
|||||||
&[&self.attributes.attributes[..], &[KeyValue::new(DIRECTION, "transmitted")]].concat(),
|
&[&self.attributes.attributes[..], &[KeyValue::new(DIRECTION, "transmitted")]].concat(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// 进程状态指标(对应 /system/process)
|
// Process status indicator (corresponding to /system/process)
|
||||||
let status_value = match process.status() {
|
let status_value = match process.status() {
|
||||||
ProcessStatus::Run => 0,
|
ProcessStatus::Run => 0,
|
||||||
ProcessStatus::Sleep => 1,
|
ProcessStatus::Sleep => 1,
|
||||||
ProcessStatus::Zombie => 2,
|
ProcessStatus::Zombie => 2,
|
||||||
_ => 3, // 其他状态
|
_ => 3, // other status
|
||||||
};
|
};
|
||||||
self.metrics.process_status.record(
|
self.metrics.process_status.record(
|
||||||
status_value,
|
status_value,
|
||||||
@@ -148,7 +148,7 @@ impl Collector {
|
|||||||
.concat(),
|
.concat(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// GPU 指标(可选)
|
// GPU Metrics (Optional) Non-MacOS
|
||||||
self.gpu_collector.collect(&self.metrics, &self.attributes)?;
|
self.gpu_collector.collect(&self.metrics, &self.attributes)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
+3
-12
@@ -451,17 +451,9 @@ async fn run(opt: config::Opt) -> Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
worker_state_manager.update(ServiceState::Stopping);
|
worker_state_manager.update(ServiceState::Stopping);
|
||||||
// tokio::select! {
|
|
||||||
// () = graceful.shutdown() => {
|
|
||||||
// debug!("Gracefully shutdown!");
|
|
||||||
// },
|
|
||||||
// () = tokio::time::sleep(std::time::Duration::from_secs(10)) => {
|
|
||||||
// debug!("Waited 10 seconds for graceful shutdown, aborting...");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
match Arc::try_unwrap(graceful) {
|
match Arc::try_unwrap(graceful) {
|
||||||
Ok(g) => {
|
Ok(g) => {
|
||||||
// 成功获取唯一所有权,可以调用 shutdown
|
// Successfully obtaining unique ownership, you can call shutdown
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
() = g.shutdown() => {
|
() = g.shutdown() => {
|
||||||
debug!("Gracefully shutdown!");
|
debug!("Gracefully shutdown!");
|
||||||
@@ -472,10 +464,9 @@ async fn run(opt: config::Opt) -> Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(arc_graceful) => {
|
Err(arc_graceful) => {
|
||||||
// 还有其他引用存在,无法获取唯一所有权
|
// There are other references that cannot be obtained for unique ownership
|
||||||
debug!("Cannot perform graceful shutdown, other references exist");
|
|
||||||
error!("Cannot perform graceful shutdown, other references exist err: {:?}", arc_graceful);
|
error!("Cannot perform graceful shutdown, other references exist err: {:?}", arc_graceful);
|
||||||
// 在这种情况下,我们只能等待超时
|
// In this case, we can only wait for the timeout
|
||||||
tokio::time::sleep(Duration::from_secs(10)).await;
|
tokio::time::sleep(Duration::from_secs(10)).await;
|
||||||
debug!("Timeout reached, forcing shutdown");
|
debug!("Timeout reached, forcing shutdown");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user