Added Networks and some style changes
This commit is contained in:
30
src/main.rs
30
src/main.rs
@@ -1,9 +1,9 @@
|
|||||||
extern crate rocket;
|
extern crate rocket;
|
||||||
|
use readable::byte::Byte;
|
||||||
|
use readable::up::UptimeFull;
|
||||||
use rocket::serde::Serialize;
|
use rocket::serde::Serialize;
|
||||||
use rocket::{get, launch, routes};
|
use rocket::{get, launch, routes};
|
||||||
use rocket_dyn_templates::{context, Template};
|
use rocket_dyn_templates::{context, Template};
|
||||||
use readable::byte::Byte;
|
|
||||||
use readable::up::UptimeFull;
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use reqwest;
|
use reqwest;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@@ -37,11 +37,19 @@ struct RamInfo {
|
|||||||
used_swap: String,
|
used_swap: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Debug)]
|
||||||
|
struct NetworkInfo {
|
||||||
|
name: String,
|
||||||
|
total_sent: String,
|
||||||
|
total_received: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Debug)]
|
#[derive(Serialize, Debug)]
|
||||||
struct SysInfo {
|
struct SysInfo {
|
||||||
ram: RamInfo,
|
ram: RamInfo,
|
||||||
disks: Vec<DiskInfo>,
|
disks: Vec<DiskInfo>,
|
||||||
components: Vec<ComponentInfo>,
|
components: Vec<ComponentInfo>,
|
||||||
|
network_ifs: Vec<NetworkInfo>,
|
||||||
hostname: Option<String>,
|
hostname: Option<String>,
|
||||||
operating_system: Option<String>,
|
operating_system: Option<String>,
|
||||||
uptime: String,
|
uptime: String,
|
||||||
@@ -53,7 +61,11 @@ fn get_system_info() -> SysInfo {
|
|||||||
let mut sys = System::new_all();
|
let mut sys = System::new_all();
|
||||||
sys.refresh_all();
|
sys.refresh_all();
|
||||||
let cpu_load = System::load_average();
|
let cpu_load = System::load_average();
|
||||||
let cpu_load = (format!("{:.2}", cpu_load.one), format!("{:.2}", cpu_load.five), format!("{:.2}", cpu_load.fifteen));
|
let cpu_load = (
|
||||||
|
format!("{:.2}", cpu_load.one),
|
||||||
|
format!("{:.2}", cpu_load.five),
|
||||||
|
format!("{:.2}", cpu_load.fifteen),
|
||||||
|
);
|
||||||
|
|
||||||
let disks = Disks::new_with_refreshed_list();
|
let disks = Disks::new_with_refreshed_list();
|
||||||
let mut disks_context = Vec::new();
|
let mut disks_context = Vec::new();
|
||||||
@@ -79,6 +91,15 @@ fn get_system_info() -> SysInfo {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let networks = Networks::new_with_refreshed_list();
|
||||||
|
let mut network_ifs = Vec::new();
|
||||||
|
for (interface_name, network) in &networks {
|
||||||
|
network_ifs.push(NetworkInfo {
|
||||||
|
name: interface_name.to_string(),
|
||||||
|
total_sent: Byte::from(network.total_transmitted()).to_string(),
|
||||||
|
total_received: Byte::from(network.total_received()).to_string()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
SysInfo {
|
SysInfo {
|
||||||
disks: disks_context,
|
disks: disks_context,
|
||||||
@@ -87,8 +108,9 @@ fn get_system_info() -> SysInfo {
|
|||||||
total_memory: Byte::from(sys.total_memory()).to_string(),
|
total_memory: Byte::from(sys.total_memory()).to_string(),
|
||||||
used_memory: Byte::from(sys.used_memory()).to_string(),
|
used_memory: Byte::from(sys.used_memory()).to_string(),
|
||||||
total_swap: Byte::from(sys.total_swap()).to_string(),
|
total_swap: Byte::from(sys.total_swap()).to_string(),
|
||||||
used_swap: Byte::from(sys.used_swap()).to_string()
|
used_swap: Byte::from(sys.used_swap()).to_string(),
|
||||||
},
|
},
|
||||||
|
network_ifs: network_ifs,
|
||||||
hostname: System::host_name(),
|
hostname: System::host_name(),
|
||||||
operating_system: System::long_os_version(),
|
operating_system: System::long_os_version(),
|
||||||
uptime: UptimeFull::from(System::uptime()).to_string(),
|
uptime: UptimeFull::from(System::uptime()).to_string(),
|
||||||
|
|||||||
@@ -24,6 +24,8 @@
|
|||||||
}
|
}
|
||||||
.warning {
|
.warning {
|
||||||
color: yellow;
|
color: yellow;
|
||||||
|
.node_data {
|
||||||
|
font-family: monospace, monospace;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
@@ -32,10 +34,10 @@
|
|||||||
<div class="infocards">
|
<div class="infocards">
|
||||||
<div class="infocard">
|
<div class="infocard">
|
||||||
<h2>Sys Info</h2>
|
<h2>Sys Info</h2>
|
||||||
<p>Hostname: {{ system.hostname }}</p>
|
<p>Hostname: <span class="node_data">{{ system.hostname }}</span></p>
|
||||||
<p>Uptime: {{ system.uptime }}</p>
|
<p>Uptime: <span class="node_data">{{ system.uptime }}</span></p>
|
||||||
<p>OS: {{ system.operating_system }}</p>
|
<p>OS: <span class="node_data">{{ system.operating_system }}</span></p>
|
||||||
<p>Average Load: {{ system.average_load.0 }} {{ system.average_load.1 }} {{ system.average_load.2 }}</p>
|
<p>Average Load: <span class="node_data">{{ system.average_load.0 }} {{ system.average_load.1 }} {{ system.average_load.2 }}</span></p>
|
||||||
{% if system.restart_needed %}
|
{% if system.restart_needed %}
|
||||||
<p class="restart">RESTART NEEDED</p>
|
<p class="restart">RESTART NEEDED</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -43,9 +45,10 @@
|
|||||||
<div class="infocard">
|
<div class="infocard">
|
||||||
<h2>HDD Info</h2>
|
<h2>HDD Info</h2>
|
||||||
{% for disk in system.disks %}
|
{% for disk in system.disks %}
|
||||||
<h3>{{disk.name}}</h3>
|
<h3 class="node_data">{{disk.name}}</h3>
|
||||||
<p class="subheading">Mounted at: {{disk.mount_point}}</p>
|
<p class="subheading">Mounted at: <span class="node_data">{{disk.mount_point}}</span></p>
|
||||||
<p>{{disk.available_space}} of {{disk.total_space}} available</p>
|
<p><span class="node_data">{{disk.available_space}}</span> of <span class="node_data">{{disk.total_space}}</span> available</p>
|
||||||
|
<progress class="diskspace" max="{{disk.total_space_bytes}}" value="{{disk.available_space_bytes}}"></progress>
|
||||||
{% if not loop.last %}
|
{% if not loop.last %}
|
||||||
<hr>
|
<hr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -54,7 +57,7 @@
|
|||||||
<div class="infocard">
|
<div class="infocard">
|
||||||
<h2>Temperatures</h2>
|
<h2>Temperatures</h2>
|
||||||
{% for comp in system.components %}
|
{% for comp in system.components %}
|
||||||
<p class="temperature">{{ comp.name }} - {{ comp.temperature }}°C</p>
|
<p class="temperature"><span class="node_data">{{ comp.name }}</span> - <span class="node_data">{{ comp.temperature }}°C</span></p>
|
||||||
{% if not loop.last %}
|
{% if not loop.last %}
|
||||||
<hr>
|
<hr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -62,9 +65,17 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="infocard">
|
<div class="infocard">
|
||||||
<h2>RAM</h2>
|
<h2>RAM</h2>
|
||||||
<p>{{ system.ram.used_memory }} of {{ system.ram.total_memory }} RAM current in use</p>
|
<p><span class="node_data">{{ system.ram.used_memory }}</span> of <span class="node_data">{{ system.ram.total_memory }}</span> RAM current in use</p>
|
||||||
<p>{{ system.ram.used_swap }} of {{ system.ram.total_swap }} swap currently in use</p>
|
<p><span class="node_data">{{ system.ram.used_swap }}</span> of <span class="node_data">{{ system.ram.total_swap }}</span> swap currently in use</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="infocard">
|
||||||
|
<h2>Network Interfaces</h2>
|
||||||
|
{% for network_if in system.network_ifs %}
|
||||||
|
<h3 class="node_data">{{ network_if.name }}</h3>
|
||||||
|
<p>Total Sent: <span class="node_data">{{ network_if.total_sent }}</span></p>
|
||||||
|
<p>Total Received: <span class="node_data">{{ network_if.total_received }}</span></p>
|
||||||
|
{% endfor %}
|
||||||
|
<p>
|
||||||
</div>
|
</div>
|
||||||
<h1>Monerod Status</h1>
|
<h1>Monerod Status</h1>
|
||||||
<div class="monerodstatus">
|
<div class="monerodstatus">
|
||||||
|
|||||||
Reference in New Issue
Block a user