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;
|
||||
use readable::byte::Byte;
|
||||
use readable::up::UptimeFull;
|
||||
use rocket::serde::Serialize;
|
||||
use rocket::{get, launch, routes};
|
||||
use rocket_dyn_templates::{context, Template};
|
||||
use readable::byte::Byte;
|
||||
use readable::up::UptimeFull;
|
||||
use std::path::Path;
|
||||
use reqwest;
|
||||
use std::collections::HashMap;
|
||||
@@ -37,11 +37,19 @@ struct RamInfo {
|
||||
used_swap: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
struct NetworkInfo {
|
||||
name: String,
|
||||
total_sent: String,
|
||||
total_received: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
struct SysInfo {
|
||||
ram: RamInfo,
|
||||
disks: Vec<DiskInfo>,
|
||||
components: Vec<ComponentInfo>,
|
||||
network_ifs: Vec<NetworkInfo>,
|
||||
hostname: Option<String>,
|
||||
operating_system: Option<String>,
|
||||
uptime: String,
|
||||
@@ -53,7 +61,11 @@ fn get_system_info() -> SysInfo {
|
||||
let mut sys = System::new_all();
|
||||
sys.refresh_all();
|
||||
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 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 {
|
||||
disks: disks_context,
|
||||
@@ -87,8 +108,9 @@ fn get_system_info() -> SysInfo {
|
||||
total_memory: Byte::from(sys.total_memory()).to_string(),
|
||||
used_memory: Byte::from(sys.used_memory()).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(),
|
||||
operating_system: System::long_os_version(),
|
||||
uptime: UptimeFull::from(System::uptime()).to_string(),
|
||||
|
||||
@@ -24,48 +24,59 @@
|
||||
}
|
||||
.warning {
|
||||
color: yellow;
|
||||
.node_data {
|
||||
font-family: monospace, monospace;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Node Device Info</h1>
|
||||
<div class="infocards">
|
||||
<div class="infocard">
|
||||
<h2>Sys Info</h2>
|
||||
<p>Hostname: {{ system.hostname }}</p>
|
||||
<p>Uptime: {{ system.uptime }}</p>
|
||||
<p>OS: {{ system.operating_system }}</p>
|
||||
<p>Average Load: {{ system.average_load.0 }} {{ system.average_load.1 }} {{ system.average_load.2 }}</p>
|
||||
{% if system.restart_needed %}
|
||||
<p class="restart">RESTART NEEDED</p>
|
||||
{% endif %}
|
||||
<div class="infocards">
|
||||
<div class="infocard">
|
||||
<h2>Sys Info</h2>
|
||||
<p>Hostname: <span class="node_data">{{ system.hostname }}</span></p>
|
||||
<p>Uptime: <span class="node_data">{{ system.uptime }}</span></p>
|
||||
<p>OS: <span class="node_data">{{ system.operating_system }}</span></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 %}
|
||||
<p class="restart">RESTART NEEDED</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="infocard">
|
||||
<h2>HDD Info</h2>
|
||||
{% for disk in system.disks %}
|
||||
<h3 class="node_data">{{disk.name}}</h3>
|
||||
<p class="subheading">Mounted at: <span class="node_data">{{disk.mount_point}}</span></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 %}
|
||||
<hr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="infocard">
|
||||
<h2>Temperatures</h2>
|
||||
{% for comp in system.components %}
|
||||
<p class="temperature"><span class="node_data">{{ comp.name }}</span> - <span class="node_data">{{ comp.temperature }}°C</span></p>
|
||||
{% if not loop.last %}
|
||||
<hr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="infocard">
|
||||
<h2>RAM</h2>
|
||||
<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><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 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 class="infocard">
|
||||
<h2>HDD Info</h2>
|
||||
{% for disk in system.disks %}
|
||||
<h3>{{disk.name}}</h3>
|
||||
<p class="subheading">Mounted at: {{disk.mount_point}}</p>
|
||||
<p>{{disk.available_space}} of {{disk.total_space}} available</p>
|
||||
{% if not loop.last %}
|
||||
<hr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="infocard">
|
||||
<h2>Temperatures</h2>
|
||||
{% for comp in system.components %}
|
||||
<p class="temperature">{{ comp.name }} - {{ comp.temperature }}°C</p>
|
||||
{% if not loop.last %}
|
||||
<hr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="infocard">
|
||||
<h2>RAM</h2>
|
||||
<p>{{ system.ram.used_memory }} of {{ system.ram.total_memory }} RAM current in use</p>
|
||||
<p>{{ system.ram.used_swap }} of {{ system.ram.total_swap }} swap currently in use</p>
|
||||
</div>
|
||||
</div>
|
||||
<h1>Monerod Status</h1>
|
||||
<div class="monerodstatus">
|
||||
<div class="monerodinfocard">
|
||||
|
||||
Reference in New Issue
Block a user