Include RTT events per second tracking in the /api/stats call

This commit is contained in:
Herbert Wolverson 2024-03-15 12:18:19 -05:00
parent f44af37670
commit beda42194a
5 changed files with 12 additions and 2 deletions

View File

@ -89,6 +89,8 @@ pub enum BusResponse {
high_watermark: (u64, u64),
/// Number of flows tracked
tracked_flows: u64,
/// RTT events per second
rtt_events_per_second: u64,
},
/// The index of the new packet collection session

View File

@ -66,17 +66,19 @@ pub struct LqosStats {
pub time_to_poll_hosts_us: u64,
pub high_watermark: (u64, u64),
pub tracked_flows: u64,
pub rtt_events_per_second: u64,
}
#[get("/api/stats")]
pub async fn stats() -> NoCache<Json<LqosStats>> {
for msg in bus_request(vec![BusRequest::GetLqosStats]).await.unwrap() {
if let BusResponse::LqosdStats { bus_requests, time_to_poll_hosts, high_watermark, tracked_flows } = msg {
if let BusResponse::LqosdStats { bus_requests, time_to_poll_hosts, high_watermark, tracked_flows, rtt_events_per_second } = msg {
return NoCache::new(Json(LqosStats {
bus_requests_since_start: bus_requests,
time_to_poll_hosts_us: time_to_poll_hosts,
high_watermark,
tracked_flows,
rtt_events_per_second,
}));
}
}

View File

@ -29,6 +29,7 @@ use signal_hook::{
iterator::Signals,
};
use stats::{BUS_REQUESTS, TIME_TO_POLL_HOSTS, HIGH_WATERMARK_DOWN, HIGH_WATERMARK_UP, FLOWS_TRACKED};
use throughput_tracker::flow_data::get_rtt_events_per_second;
use tokio::join;
mod stats;
@ -200,6 +201,7 @@ fn handle_bus_requests(
HIGH_WATERMARK_UP.load(std::sync::atomic::Ordering::Relaxed),
),
tracked_flows: FLOWS_TRACKED.load(std::sync::atomic::Ordering::Relaxed),
rtt_events_per_second: get_rtt_events_per_second(),
}
}
BusRequest::GetPacketHeaderDump(id) => {

View File

@ -137,3 +137,7 @@ pub fn flowbee_rtt_map() -> FxHashMap<FlowbeeKey, RttData> {
.map(|(k, v)| (k.clone(), v.median()))
.collect()
}
pub fn get_rtt_events_per_second() -> u64 {
EVENTS_PER_SECOND.swap(0, std::sync::atomic::Ordering::Relaxed)
}

View File

@ -15,7 +15,7 @@ use std::sync::{
};
pub(crate) use flow_analysis::{setup_flow_analysis, get_asn_name_and_country,
FlowAnalysis, RECENT_FLOWS, flowbee_handle_events, get_flowbee_event_count_and_reset,
expire_rtt_flows, flowbee_rtt_map, RttData,
expire_rtt_flows, flowbee_rtt_map, RttData, get_rtt_events_per_second,
};