Skip to content

Commit

Permalink
OK,项目完结!撒花
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Yen committed Nov 26, 2024
1 parent 1888118 commit a36163a
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 28 deletions.
32 changes: 32 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ tracing-subscriber = "0.3"
sysinfo = "0.32.0"
serde = "1.0.213"
lazy_static = "1.5.0"
tera = "1"
tera = "1"
argh = "0.1.12"
66 changes: 45 additions & 21 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,58 @@
mod router;
mod handler;
mod router;

use tera::Tera;
use salvo::prelude::*;
use salvo::logging::Logger;
use sysinfo::{System,Disks,Networks};
use lazy_static::lazy_static;
use std::sync::{Arc,Mutex};
use salvo::logging::Logger;
use salvo::prelude::*;
use std::sync::{Arc, Mutex};
use sysinfo::{Disks, Networks, System};
use tera::Tera;

lazy_static!{
static ref SYSTEM:Arc<Mutex<System>> = Arc::new(Mutex::new(System::new()));
static ref DISKS:Arc<Mutex<Disks>> = Arc::new(Mutex::new(Disks::new()));
static ref NETWORKS:Arc<Mutex<Networks>> = Arc::new(Mutex::new(Networks::new()));
static ref TEMPLATES:Tera={
let mut tera=Tera::new("templates/**/*.html").unwrap();
lazy_static! {
static ref SYSTEM: Arc<Mutex<System>> = Arc::new(Mutex::new(System::new()));
static ref DISKS: Arc<Mutex<Disks>> = Arc::new(Mutex::new(Disks::new()));
static ref NETWORKS: Arc<Mutex<Networks>> = Arc::new(Mutex::new(Networks::new()));
static ref TEMPLATES: Tera = {
let mut tera = Tera::new("templates/**/*.html").unwrap();
tera.full_reload().unwrap();
tera
};
}



//解析命令行参数
use argh::FromArgs;

#[derive(FromArgs)]
/// A System monitor written in Rust!
struct Args {
/// enable logging
#[argh(switch, short = 'l')]
log: bool,
/// address
#[argh(option, short = 'a')]
address: Option<String>,
/// port
#[argh(option, short = 'p')]
port: Option<u32>,
}

#[tokio::main]
async fn main() {
tracing_subscriber::fmt().init();

//获取命令行参数
let args: Args = argh::from_env();
let router = router::get_router();
let service=Service::new(router).hoop(Logger::new());
let acceptor = TcpListener::new("0.0.0.0:19999").bind().await;

Server::new(acceptor).serve(service).await;
}
let ip = format!(
"{}:{}",
args.address.unwrap_or("127.0.0.1".to_string()),
args.port.unwrap_or(9999)
);
if args.log {
tracing_subscriber::fmt().init();
let service = Service::new(router).hoop(Logger::new());
let acceptor = TcpListener::new(&ip).bind().await;
Server::new(acceptor).serve(service).await;
} else {
let acceptor = TcpListener::new(&ip).bind().await;
Server::new(acceptor).serve(router).await;
}
}
12 changes: 6 additions & 6 deletions templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
{% block side_content %}
<div class="paper">
<div class="row">
<p>System Name: {{system_name}}</p>
<p>Hostname: {{hostname}}</p>
<p>OS Version: {{os_version}}</p>
<p>Kernel Version: {{kernel_version}}</p>
<p>Distribution ID: {{distribution_id}}</p>
<p>CPU Architecture: {{cpu_arch}}</p>
<p ><span class="badge">System Name: {{system_name}}</span></p>
<p><span class="badge secondary">Hostname: {{hostname}}</span></p>
<p><span class="badge success">OS Version: {{os_version}}</span></p>
<p><span class="badge warning">Kernel Version: {{kernel_version}}</span></p>
<p><span class="badge danger">Distribution ID: {{distribution_id}}</span></p>
<p><span class="badge">CPU Architecture: {{cpu_arch}}</span></p>
</div>
</div>
<div class="paper">
Expand Down

0 comments on commit a36163a

Please sign in to comment.