From 24f9af9e0ff25300cb51ecddc50ee0efd44430e6 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Sun, 14 Nov 2021 18:49:29 +0100 Subject: [PATCH] add missing file from previous commit Signed-off-by: Dietmar Maurer --- src/api2/admin/traffic_control.rs | 59 +++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/api2/admin/traffic_control.rs diff --git a/src/api2/admin/traffic_control.rs b/src/api2/admin/traffic_control.rs new file mode 100644 index 00000000..2b9424e6 --- /dev/null +++ b/src/api2/admin/traffic_control.rs @@ -0,0 +1,59 @@ +use anyhow::Error; +use serde_json::{json, Value}; + +use proxmox_router::{Router, Permission}; +use proxmox_schema::api; + +use pbs_api_types::{ + TRAFFIC_CONTROL_ID_SCHEMA, PRIV_SYS_AUDIT, +}; + +use crate::TRAFFIC_CONTROL_CACHE; + +#[api( + input: { + properties: {}, + }, + returns: { + description: "Show current traffic control rates.", + type: Array, + items: { + description: "Current rates per rule.", + properties: { + name: { + schema: TRAFFIC_CONTROL_ID_SCHEMA, + }, + "rate-in": { + description: "Current ingress rate in bytes/second", + type: u64, + }, + "rate-out": { + description: "Current egress rate in bytes/second", + type: u64, + }, + }, + }, + }, + access: { + permission: &Permission::Privilege(&[], PRIV_SYS_AUDIT, false), + }, +)] +/// Show current traffic for all traffic control rules. +pub fn show_current_traffic() -> Result { + + let mut list = Vec::new(); + + let cache = TRAFFIC_CONTROL_CACHE.lock().unwrap(); + for (rule, stat) in cache.current_rate_map().iter() { + list.push(json!({ + "name": rule, + "rate-in": stat.rate_in, + "rate-out": stat.rate_out, + })); + } + + Ok(list.into()) +} + +pub const ROUTER: Router = Router::new() + .get(&API_METHOD_SHOW_CURRENT_TRAFFIC);