fixed hagent work

pull/6/head
prplV 2024-11-12 12:28:46 +03:00
parent 4b897c0063
commit 7677fa1f55
2 changed files with 21 additions and 7 deletions

View File

@ -84,7 +84,7 @@ pub struct FIleTriggers {
/// ///
/// ///
#[derive(Debug, Clone)] #[derive(Debug, Clone, Serialize,)]
pub struct Metrics { pub struct Metrics {
pub container_metrics : ContainerMetrics, pub container_metrics : ContainerMetrics,
pub processes_metrics : Vec<ProcessMetrics>, pub processes_metrics : Vec<ProcessMetrics>,
@ -103,7 +103,7 @@ impl Metrics {
/// ///
/// ///
#[derive(Debug, Clone)] #[derive(Debug, Clone, Serialize)]
pub struct ContainerMetrics { pub struct ContainerMetrics {
container_id : String, container_id : String,
cpu_load : f32, cpu_load : f32,
@ -125,9 +125,9 @@ impl ContainerMetrics {
/// ///
/// ///
#[derive(Debug, Clone)] #[derive(Debug, Clone, Serialize)]
pub struct ProcessMetrics { pub struct ProcessMetrics {
process_name : String, pub process_name : String,
cpu_load : f32, cpu_load : f32,
ram_load : f32, ram_load : f32,
} }
@ -142,7 +142,7 @@ impl ProcessMetrics {
} }
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone, Serialize)]
pub struct PacketInfo { pub struct PacketInfo {
protocol : String, protocol : String,
dst_ip : Ipv4Addr, dst_ip : Ipv4Addr,

View File

@ -35,6 +35,10 @@ async fn ha_send_data(socket: &UnixStream, data: &str) -> Result<(), std::io::Er
#[cfg(test)] #[cfg(test)]
mod hagent_unittets { mod hagent_unittets {
use log::info;
use crate::utils::metrics;
use super::*; use super::*;
#[tokio::test] #[tokio::test]
// maybe bool : true -> alive, false -> dead // maybe bool : true -> alive, false -> dead
@ -46,10 +50,20 @@ mod hagent_unittets {
assert!(ha_healthcheck(&sock).await.is_ok()); assert!(ha_healthcheck(&sock).await.is_ok());
} }
#[tokio::test] #[tokio::test]
// Result<maybe Response> // --Result<maybe Response>
// one-shot func // one-shot func
async fn send_metrics_to_hagent() { async fn send_metrics_to_hagent() {
assert!(true); let procm = crate::options::structs::ProcessMetrics::new("test-prc", 15.0, 5.0);
let contm = crate::options::structs::ContainerMetrics::new("test", 32.0, 12.0, vec![procm.process_name.clone()]);
let metrics = crate::options::structs::Metrics::new(contm, vec![procm]);
let metrics = &serde_json::to_string_pretty(&metrics).unwrap();
let sock = open_unix_socket().await;
assert!(sock.is_ok());
let sock = sock.unwrap();
assert!(ha_healthcheck(&sock).await.is_ok());
assert!(ha_send_data(&sock, &metrics).await.is_ok());
} }
#[tokio::test] #[tokio::test]
async fn open_unixsocket_test() { async fn open_unixsocket_test() {