Skip to content

Commit 1f3bcdc

Browse files
Test: Support Freebsd
1 parent 986603c commit 1f3bcdc

File tree

5 files changed

+34
-44
lines changed

5 files changed

+34
-44
lines changed

src/args.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::process::exit;
21
use crate::get_info::get_hostname;
32
use clap::Parser;
3+
use std::process::exit;
44

55
/// Akile Monitor Rust Client
66
#[derive(Parser, Debug, Clone)]
@@ -59,14 +59,14 @@ impl Args_cli {
5959
None => {
6060
eprintln!("请输入 --server 参数");
6161
exit(1);
62-
},
62+
}
6363
};
6464
let auth_secret = match self.auth_secret {
6565
Some(s) => s,
6666
None => {
6767
eprintln!("请输入 --auth_secret 参数");
6868
exit(1);
69-
},
69+
}
7070
};
7171
let interval = self.interval.unwrap_or(1000);
7272
let fake_times = self.fake_times.unwrap_or(1);
@@ -99,4 +99,4 @@ pub struct Args {
9999
pub monitor_path: String,
100100
pub install: bool,
101101
pub uninstall: bool,
102-
}
102+
}

src/get_info.rs

+23-22
Original file line numberDiff line numberDiff line change
@@ -40,39 +40,40 @@ pub async fn get_cpu_info() -> (Vec<String>, String, String) {
4040

4141
#[cfg(target_os = "linux")]
4242
{
43-
let get_arch_linux = async || -> (Vec<String>, String, String) {
44-
let virt = heim_virt::detect().await.unwrap_or(heim_virt::Virtualization::Unknown);
45-
46-
let mut cpu_name: Vec<String> = Vec::new();
47-
if virt.is_vm() || virt.is_container() {
48-
for (cpu, count) in cpu_counts {
49-
cpu_name.push(format!("{} @ {} Virtual Core", cpu, count))
50-
}
51-
} else {
52-
for (cpu, count) in cpu_counts {
53-
cpu_name.push(format!("{} @ {} Core", cpu, count))
54-
}
43+
let virt = {
44+
heim_virt::detect()
45+
.await
46+
.unwrap_or(heim_virt::Virtualization::Unknown)
47+
};
48+
let mut cpu_name: Vec<String> = Vec::new();
49+
if virt.is_vm() || virt.is_container() {
50+
for (cpu, count) in cpu_counts {
51+
cpu_name.push(format!("{} @ {} Virtual Core", cpu, count))
5552
}
56-
57-
if virt == heim_virt::Virtualization::Unknown {
58-
(cpu_name, arch, "Physical".to_string())
59-
} else {
60-
(cpu_name, arch, virt.as_str().to_string())
53+
} else {
54+
for (cpu, count) in cpu_counts {
55+
// cpu_name.push(format!("{} @ {} Core", cpu, count))
56+
cpu_name.push(format!("{} @ {} Virtual Core", cpu, count))
6157
}
62-
};
58+
}
6359

64-
get_arch_linux().await
60+
if virt == heim_virt::Virtualization::Unknown {
61+
(cpu_name, arch, "Physical".to_string())
62+
} else {
63+
(cpu_name, arch, virt.as_str().to_string())
64+
}
6565
}
6666

6767
#[cfg(target_os = "freebsd")]
6868
{
69-
let virt = String::from("Unknown - FreeBSD");
7069
let mut cpu_name: Vec<String> = Vec::new();
7170
for (cpu, count) in cpu_counts {
72-
cpu_name.push(format!("{} @ {} Core", cpu, count))
71+
cpu_name.push(format!("{} @ {} Virtual Core", cpu, count))
7372
}
74-
(cpu_name, arch, virt)
73+
(cpu_name, arch, "Unknown".to_string())
7574
}
75+
76+
7677
}
7778

7879
pub fn get_boot_time() -> u64 {

src/install.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
use crate::manage_utils;
21
use crate::args::Args;
2+
use crate::manage_utils;
33
use log::{error, info, warn};
44
use std::fs::File;
55
use std::io::Write;
66
use std::process::{exit, Command};
77
use std::{fs, io};
88

99
pub fn install_to_systemd(args: Args) {
10-
1110
manage_utils::check_installed("/etc/systemd/system/akile_monitor_client.service");
1211
manage_utils::copy_binary();
1312

@@ -223,10 +222,7 @@ pub fn install_to_openrc(args: Args) {
223222
}
224223
}
225224

226-
match Command::new("rc-update")
227-
.arg("-u")
228-
.output()
229-
{
225+
match Command::new("rc-update").arg("-u").output() {
230226
Ok(tmp) => {
231227
if tmp.status.success() {
232228
info!("成功重载 OpenRC 服务");
@@ -235,10 +231,7 @@ pub fn install_to_openrc(args: Args) {
235231
}
236232
}
237233
Err(e) => {
238-
warn!(
239-
"无法重载 OpenRC 服务: {}",
240-
e
241-
);
234+
warn!("无法重载 OpenRC 服务: {}", e);
242235
}
243236
}
244237

src/main.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use tokio_tungstenite::{
1515

1616
use crate::args::*;
1717
use crate::build_message::{build_host, build_host_state, build_post_gziped_json};
18-
use sysinfo::System;
1918
use crate::manage_utils::{check_pid1, PID1};
19+
use sysinfo::System;
2020

2121
#[tokio::main]
2222
async fn main() {
@@ -41,7 +41,6 @@ async fn main() {
4141
install::install_to_openrc(args.clone().to_args());
4242
}
4343
}
44-
4544
} else if args.uninstall {
4645
simple_logger::init_with_level(log::Level::Debug).unwrap();
4746
info!("检测到 --uninstall 参数, 正在进入卸载模式");

src/manage_utils.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,13 @@ pub fn copy_binary() {
112112
}
113113
}
114114

115-
pub fn delete_binary () {
115+
pub fn delete_binary() {
116116
match fs::remove_file("/usr/bin/ak_monitor_client_rs") {
117117
Ok(_) => {
118118
info!("成功删除 /usr/bin/ak_monitor_client_rs");
119119
}
120120
Err(e) => {
121-
warn!(
122-
"无法删除 /usr/bin/ak_monitor_client_rs: {}",
123-
e
124-
);
121+
warn!("无法删除 /usr/bin/ak_monitor_client_rs: {}", e);
125122
}
126123
}
127-
}
124+
}

0 commit comments

Comments
 (0)