mirror of
https://github.com/LibreQoE/LibreQoS.git
synced 2025-02-25 18:55:32 -06:00
Include shaped device and unknown IP counts in UI2 template.
This commit is contained in:
parent
ebe7391b92
commit
e6d75c9cd0
@ -37,4 +37,13 @@ function initDayNightMode() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
initDayNightMode();
|
function getDeviceCounts() {
|
||||||
|
$.get("/local-api/deviceCount", (data) => {
|
||||||
|
console.log(data);
|
||||||
|
$("#shapedDeviceCount").text(data.shaped_devices);
|
||||||
|
$("#unknownIpCount").text(data.unknown_ips);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
initDayNightMode();
|
||||||
|
getDeviceCounts();
|
@ -1,5 +1,6 @@
|
|||||||
mod dashboard_themes;
|
mod dashboard_themes;
|
||||||
mod version_check;
|
mod version_check;
|
||||||
|
mod device_counts;
|
||||||
|
|
||||||
use axum::Router;
|
use axum::Router;
|
||||||
use axum::routing::{get, post};
|
use axum::routing::{get, post};
|
||||||
@ -11,4 +12,5 @@ pub fn local_api() -> Router {
|
|||||||
.route("/dashletDelete", post(dashboard_themes::delete_theme))
|
.route("/dashletDelete", post(dashboard_themes::delete_theme))
|
||||||
.route("/dashletGet", post(dashboard_themes::get_theme))
|
.route("/dashletGet", post(dashboard_themes::get_theme))
|
||||||
.route("/versionCheck", get(version_check::version_check))
|
.route("/versionCheck", get(version_check::version_check))
|
||||||
|
.route("/deviceCount", get(device_counts::count_users))
|
||||||
}
|
}
|
42
src/rust/lqosd/src/node_manager/local_api/device_counts.rs
Normal file
42
src/rust/lqosd/src/node_manager/local_api/device_counts.rs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
use std::net::IpAddr;
|
||||||
|
use axum::Json;
|
||||||
|
use serde::Serialize;
|
||||||
|
use lqos_bus::{bus_request, BusRequest, BusResponse, IpStats};
|
||||||
|
use crate::shaped_devices_tracker::SHAPED_DEVICES;
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct DeviceCount {
|
||||||
|
pub shaped_devices: usize,
|
||||||
|
pub unknown_ips: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn unknown_device_count() -> usize {
|
||||||
|
if let BusResponse::AllUnknownIps(unknowns) = crate::throughput_tracker::all_unknown_ips() {
|
||||||
|
let cfg = SHAPED_DEVICES.read().unwrap();
|
||||||
|
let really_unknown: Vec<IpStats> = unknowns
|
||||||
|
.iter()
|
||||||
|
.filter(|ip| {
|
||||||
|
if let Ok(ip) = ip.ip_address.parse::<IpAddr>() {
|
||||||
|
let lookup = match ip {
|
||||||
|
IpAddr::V4(ip) => ip.to_ipv6_mapped(),
|
||||||
|
IpAddr::V6(ip) => ip,
|
||||||
|
};
|
||||||
|
cfg.trie.longest_match(lookup).is_none()
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.cloned()
|
||||||
|
.collect();
|
||||||
|
return really_unknown.len();
|
||||||
|
}
|
||||||
|
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn count_users() -> Json<DeviceCount> {
|
||||||
|
Json(DeviceCount{
|
||||||
|
shaped_devices: SHAPED_DEVICES.read().unwrap().devices.len(),
|
||||||
|
unknown_ips: unknown_device_count(),
|
||||||
|
})
|
||||||
|
}
|
@ -56,13 +56,13 @@
|
|||||||
<!-- Shaped Devices -->
|
<!-- Shaped Devices -->
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link">
|
<a class="nav-link">
|
||||||
<i class="fa fa-user-circle nav-icon"></i> <span id="shapedDeviceCount" class="badge">0</span> Devices
|
<i class="fa fa-user-circle nav-icon"></i> <span id="shapedDeviceCount" class="badge">?</span> Devices
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<!-- Unknown IPs -->
|
<!-- Unknown IPs -->
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link">
|
<a class="nav-link">
|
||||||
<i class="fa fa-address-card nav-icon"></i> <span id="unknownIpCount" class="badge">0</span> Unknown IP
|
<i class="fa fa-address-card nav-icon"></i> <span id="unknownIpCount" class="badge">?</span> Unknown IP
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<!-- Statistics -->
|
<!-- Statistics -->
|
||||||
|
Loading…
Reference in New Issue
Block a user