docs: metrics (tmp)
parent
15bb446aa4
commit
174779bfcb
|
|
@ -14,18 +14,18 @@ use crate::utils::get_container_id;
|
|||
|
||||
// type PacketBuffer = Arc<Mutex<Vec<PacketInfo>>>;
|
||||
|
||||
/// # Fn init_metrics_grubber
|
||||
/// # Fn `init_metrics_grubber`
|
||||
/// ## for initializing process of unstoppable grubbing metrics.
|
||||
///
|
||||
/// *input* : `Result<()>`
|
||||
/// *input* : `Arc<Mutex<UnixSocket>>` ??
|
||||
///
|
||||
/// *output* : `Err` if it cant create grubbers | `Ok` on finish
|
||||
///
|
||||
/// *initiator* : main thread
|
||||
/// *initiator* : main thread ??
|
||||
///
|
||||
/// *managing* : object of unix-socket reader
|
||||
///
|
||||
/// *depends on* : network activity
|
||||
/// *depends on* : -
|
||||
///
|
||||
pub async fn init_metrics_grubber() {
|
||||
let mut system = System::new();
|
||||
|
|
@ -79,8 +79,19 @@ async fn gather_metrics(proc: Arc<Process>) {
|
|||
// }
|
||||
|
||||
|
||||
// !!!
|
||||
// for container (whole system metrics)
|
||||
/// # Fn `get_all_container_metrics`
|
||||
/// ## for gathering all container (whole system metrics)
|
||||
///
|
||||
/// *input* : `Arc<System>`, `Arc<Vec<TrackingProcess>>`
|
||||
///
|
||||
/// *output* : `ContainerMetrics`
|
||||
///
|
||||
/// *initiator* : main thread ??
|
||||
///
|
||||
/// *managing* : ref counter to `System` object, ref counter to list of processes
|
||||
///
|
||||
/// *depends on* : `TrackingProcess`
|
||||
///
|
||||
async fn get_all_container_metrics(sys: Arc<System>, prcs: Arc<Vec<TrackingProcess>>) -> ContainerMetrics {
|
||||
let metrics = join!(
|
||||
get_cpu_metrics_container(sys.clone()),
|
||||
|
|
@ -94,22 +105,74 @@ async fn get_all_container_metrics(sys: Arc<System>, prcs: Arc<Vec<TrackingProce
|
|||
metrics.2
|
||||
)
|
||||
}
|
||||
|
||||
/// # Fn `get_cpu_metrics_container`
|
||||
/// ## for gathering container cpu metrics
|
||||
///
|
||||
/// *input* : `Arc<System>`
|
||||
///
|
||||
/// *output* : `f32`
|
||||
///
|
||||
/// *initiator* : main thread ??
|
||||
///
|
||||
/// *managing* : ref counter to `System` object
|
||||
///
|
||||
/// *depends on* : -
|
||||
///
|
||||
async fn get_cpu_metrics_container(sys: Arc<System>) -> f32 {
|
||||
sys.global_cpu_usage()
|
||||
}
|
||||
|
||||
/// # Fn `get_ram_metrics_container`
|
||||
/// ## for gathering container ram metrics
|
||||
///
|
||||
/// *input* : `Arc<System>`
|
||||
///
|
||||
/// *output* : `f32`
|
||||
///
|
||||
/// *initiator* : main thread ??
|
||||
///
|
||||
/// *managing* : ref counter to `System` object
|
||||
///
|
||||
/// *depends on* : -
|
||||
///
|
||||
async fn get_ram_metrics_container(sys: Arc<System>) -> f32 {
|
||||
(sys.used_memory() / sys.total_memory()) as f32 * 100.0
|
||||
}
|
||||
// async fn get_mem_metrics_container(sys: Arc<System>) -> f32 {
|
||||
// sys.
|
||||
// }
|
||||
|
||||
/// # Fn `get_subsystems`
|
||||
/// ## for gathering info about container subsystems (processes)
|
||||
///
|
||||
/// *input* : `Arc<Vec<TrackingProcess>>`
|
||||
///
|
||||
/// *output* : `Vec<String>`
|
||||
///
|
||||
/// *initiator* : main thread ??
|
||||
///
|
||||
/// *managing* : ref counter to list of `TrackingProcess`
|
||||
///
|
||||
/// *depends on* : `TrackingProcess`
|
||||
///
|
||||
async fn get_subsystems(prcs: Arc<Vec<TrackingProcess>>) -> Vec<String> {
|
||||
prcs.iter().map(|process| process.name.clone()).collect()
|
||||
}
|
||||
|
||||
// !!!
|
||||
// for process (process metrics)
|
||||
// %
|
||||
/// # Fn `get_all_metrics_process`
|
||||
/// ## for gathering all process' metrics
|
||||
///
|
||||
/// *input* : `Arc<Process>`, `Arc<System>`
|
||||
///
|
||||
/// *output* : `ProcessMetrics`
|
||||
///
|
||||
/// *initiator* : main thread ??
|
||||
///
|
||||
/// *managing* : two ref counters to `Process` and `System`
|
||||
///
|
||||
/// *depends on* : -
|
||||
///
|
||||
async fn get_all_metrics_process(proc: Arc<Process>, sys: Arc<System>) -> ProcessMetrics {
|
||||
let metrics = join!(
|
||||
get_cpu_metrics_process(proc.clone()),
|
||||
|
|
@ -121,10 +184,37 @@ async fn get_all_metrics_process(proc: Arc<Process>, sys: Arc<System>) -> Proces
|
|||
metrics.1
|
||||
)
|
||||
}
|
||||
|
||||
/// # Fn `get_cpu_metrics_process`
|
||||
/// ## for gathering process cpu metrics
|
||||
///
|
||||
/// *input* : `Arc<Process>`
|
||||
///
|
||||
/// *output* : `f32`
|
||||
///
|
||||
/// *initiator* : main thread ??
|
||||
///
|
||||
/// *managing* : ref counter to `Process` object
|
||||
///
|
||||
/// *depends on* : -
|
||||
///
|
||||
async fn get_cpu_metrics_process(proc: Arc<Process>) -> f32 {
|
||||
proc.cpu_usage()
|
||||
}
|
||||
// %
|
||||
|
||||
/// # Fn `get_ram_metrics_process`
|
||||
/// ## for gathering process ram metrics
|
||||
///
|
||||
/// *input* : `Arc<Process>`
|
||||
///
|
||||
/// *output* : `f32`
|
||||
///
|
||||
/// *initiator* : main thread ??
|
||||
///
|
||||
/// *managing* : ref counter to `Process` object
|
||||
///
|
||||
/// *depends on* : -
|
||||
///
|
||||
async fn get_ram_metrics_process(proc: Arc<Process>, sys: Arc<System>) -> f32 {
|
||||
(proc.memory() as f64 / sys.total_memory() as f64) as f32 * 100.0 as f32
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue