blob: 78f592a9b00fef4f0be6f9ad1527c96f2f785e10 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
use rocket::response::content;
use rocket::{State, get, post, request::Form, routes};
use rocket::response::NamedFile;
use rocket_contrib::json::Json;
// use std::sync::Arc;
use crate::webserver::model::*;
use sysinfo::{
ProcessExt,
SystemExt,
System,
get_current_pid
};
pub async fn start_rocket() -> WispResult { // ctx: WispData
rocket::ignite()
.mount("/", routes![
icon, index
]).launch();
Ok(())
}
#[get("/favicon.ico")]
pub fn icon() -> Option<NamedFile> {
NamedFile::open("static/favicon.ico").ok()
}
#[get("/")]
pub fn index() -> content::Json<&'static str> {
content::Json("{\"message\": \"online\"}")
}
#[get("/")]
pub fn memory_usage() -> Json<&'static str> {
let sys = System::new();
let mut response;
if let Some(process) = sys.get_process(get_current_pid()) {
// response = format!("{{\"message\": \"{}\"}}", process.memory()/1000);
} else {
response = "{\"message\": \"null\"}".to_string();
}
Json(Json(&response))
}
|