Include node type in tree building.

This commit is contained in:
Herbert Wolverson 2023-04-26 13:07:40 +00:00
parent 566d96e280
commit a3c7b4cc99
5 changed files with 13 additions and 1 deletions

View File

@ -10,6 +10,7 @@ pub async fn collect_tree(
totals: &Option<Vec<StatsTreeNode>>,
) -> anyhow::Result<()> {
if let Some(tree) = totals {
println!("{tree:?}");
let influx_url = format!("http://{}:8086", org.influx_host);
let client = Client::new(&influx_url, &org.influx_org, &org.influx_token);
let mut points: Vec<DataPoint> = Vec::new();

View File

@ -70,6 +70,8 @@ pub struct StatsTreeNode {
pub parents: Vec<usize>,
/// Index of immediate parent in the tree
pub immediate_parent: Option<usize>,
/// Node Type
pub node_type: Option<String>,
}
/// Collation of all stats for a given time period

View File

@ -32,6 +32,9 @@ pub struct NetworkJsonNode {
/// The immediate parent node
pub immediate_parent: Option<usize>,
/// The node type
pub node_type: Option<String>,
}
impl NetworkJsonNode {
@ -48,7 +51,7 @@ impl NetworkJsonNode {
rtts: self.rtts.iter().map(|n| *n as f32 / 100.0).collect(),
parents: self.parents.clone(),
immediate_parent: self.immediate_parent,
node_type: None,
node_type: self.node_type.clone(),
}
}
}
@ -125,6 +128,7 @@ impl NetworkJson {
parents: Vec::new(),
immediate_parent: None,
rtts: DashSet::new(),
node_type: None,
}];
if !Self::exists() {
return Err(NetworkJsonError::FileNotFound);
@ -272,6 +276,7 @@ fn recurse_node(
name: name.to_string(),
immediate_parent: Some(immediate_parent),
rtts: DashSet::new(),
node_type: json.get("type").map(|v| v.as_str().unwrap().to_string()),
};
if node.name != "children" {

View File

@ -46,6 +46,7 @@ impl From<NetworkTreeEntry> for lqos_bus::long_term_stats::StatsTreeNode {
current_throughput: value.current_throughput,
parents: value.parents,
immediate_parent: value.immediate_parent,
node_type: value.node_type,
}
}
}

View File

@ -10,6 +10,7 @@ pub(crate) struct NetworkTreeEntry {
pub(crate) current_throughput: (u32, u32),
pub(crate) parents: Vec<usize>,
pub(crate) immediate_parent: Option<usize>,
pub(crate) node_type: Option<String>,
}
impl From<&NetworkJsonNode> for NetworkTreeEntry {
@ -23,6 +24,7 @@ impl From<&NetworkJsonNode> for NetworkTreeEntry {
value.current_throughput.0.load(std::sync::atomic::Ordering::Relaxed) as u32,
value.current_throughput.1.load(std::sync::atomic::Ordering::Relaxed) as u32,
),
node_type: value.node_type.clone(),
}
}
}
@ -35,6 +37,7 @@ impl From<&NetworkTreeEntry> for StatsTreeNode {
current_throughput: value.current_throughput,
parents: value.parents.clone(),
immediate_parent: value.immediate_parent,
node_type: value.node_type.clone(),
}
}
}