-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Simon Yen
committed
Nov 26, 2024
1 parent
1888118
commit a36163a
Showing
4 changed files
with
85 additions
and
28 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters