lint fix and refactor
parent
c59ac23997
commit
99b1d14dba
|
|
@ -1,6 +1,7 @@
|
|||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
#[allow(dead_code)]
|
||||
pub enum NoxisCliError {
|
||||
#[error("Can't find socket `{0}`. {1}")]
|
||||
NoxisDaemonMissing(String, String),
|
||||
|
|
|
|||
|
|
@ -4,14 +4,15 @@ use anyhow::Result;
|
|||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::net::UnixStream;
|
||||
|
||||
#[allow(dead_code)]
|
||||
async fn create_us_stream(cli: &Cli) -> Result<UnixStream> {
|
||||
Ok(UnixStream::connect(&cli.socket).await.map_err(|er| {
|
||||
NoxisCliError::NoxisDaemonMissing((&cli.socket).to_string(), er.to_string())
|
||||
})?)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub async fn try_send(cli: Cli) -> Result<()> {
|
||||
// let stream = create_us_stream(&cli).await;
|
||||
let mut stream = create_us_stream(&cli).await?;
|
||||
|
||||
let msg = serde_json::to_vec(&cli).map_err(|_| NoxisCliError::ToStringCliParsingParsing)?;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ pub mod bus {
|
|||
use std::fmt::Debug;
|
||||
|
||||
use super::*;
|
||||
use crate::utils::metrics::processes::{ProcessesAll, ProcessesGeneral, ProcessesQuery};
|
||||
use crate::utils::metrics::processes::ProcessesQuery;
|
||||
use crate::utils::metrics::MetricsExportable;
|
||||
use noxis_cli::{metrics_models::MetricsMode, Cli};
|
||||
pub type BusMessageContent = Box<dyn BusContent>;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use std::sync::Arc;
|
|||
|
||||
use crate::options::structs::bus::{BusMessage, BusMessageDirection};
|
||||
use crate::options::structs::ProcessUnit;
|
||||
use log::{debug, error, trace};
|
||||
use log::{error, trace};
|
||||
use tokio::sync::mpsc::{Receiver, Sender};
|
||||
|
||||
type Inner = Receiver<BusMessage>;
|
||||
|
|
|
|||
|
|
@ -1,18 +1,16 @@
|
|||
// submodule needed to get metrics such as
|
||||
// cpu load, ram/rom load and net activity
|
||||
///! Submodule needed to get metrics such as
|
||||
///! cpu load, ram/rom load and net activity
|
||||
|
||||
use crate::{
|
||||
options::structs::{ProcessState, TrackingProcess},
|
||||
utils::metrics::processes::{ProcessesAll, ProcessesGeneral, ProcessesQuery},
|
||||
options::structs::ProcessState,
|
||||
utils::metrics::processes::{ProcessesGeneral, ProcessesQuery},
|
||||
};
|
||||
use futures::lock::Mutex;
|
||||
use log::warn;
|
||||
use noxis_cli::metrics_models::MetricsMode;
|
||||
use std::{any::Any, collections::BTreeMap, sync::Arc};
|
||||
// use chrono::Duration;
|
||||
use super::prcs::v2::Pid;
|
||||
use crate::options::structs::bus::{BusMessage, BusMessageContentType, BusMessageDirection};
|
||||
use crate::options::structs::Dependencies;
|
||||
use serde::Serialize;
|
||||
use std::fmt::Debug;
|
||||
use sysinfo::{Disks as DisksList, Networks, System};
|
||||
|
|
@ -113,7 +111,6 @@ pub async fn init_metrics_grubber(
|
|||
}
|
||||
}
|
||||
} else if let Ok(BusMessage::Response(_, _, cont)) = msg {
|
||||
dbg!(&cont);
|
||||
let cont: Box<dyn Any + Send> = cont;
|
||||
if let Ok(info) = cont.downcast::<ProcessesQuery>() {
|
||||
if let ProcessesQuery::All(info) = *info {
|
||||
|
|
@ -293,9 +290,6 @@ async fn get_all_ifaces_metrics(networks: &Networks) -> Ifaces {
|
|||
ifaces
|
||||
}
|
||||
|
||||
async fn get_all_processes_metrics(system: &mut System) { /* TODO */
|
||||
}
|
||||
|
||||
pub mod processes {
|
||||
use crate::options::structs::ProcessState;
|
||||
use crate::utils::prcs::v2::Pid;
|
||||
|
|
@ -308,17 +302,6 @@ pub mod processes {
|
|||
QueryAll,
|
||||
}
|
||||
|
||||
impl ProcessesQuery {
|
||||
pub fn serialze_to_bus(&self) -> Option<String> {
|
||||
match self {
|
||||
ProcessesQuery::General(prc) => serde_json::to_string_pretty(prc).ok(),
|
||||
ProcessesQuery::All(prc) => serde_json::to_string_pretty(prc).ok(),
|
||||
ProcessesQuery::QueryGeneral => None,
|
||||
ProcessesQuery::QueryAll => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize)]
|
||||
pub struct ProcessesGeneral {
|
||||
pub name: String,
|
||||
|
|
@ -361,16 +344,6 @@ pub mod processes {
|
|||
}
|
||||
}
|
||||
|
||||
pub enum MetricType {
|
||||
FullMetrics,
|
||||
HostInfo,
|
||||
Cpu,
|
||||
Ram,
|
||||
Disks,
|
||||
Ifaces,
|
||||
Processes,
|
||||
}
|
||||
|
||||
pub trait MetricsExportable: Send + Sync + 'static + Debug + Any {
|
||||
fn serialze_into_output(&self) -> anyhow::Result<String>;
|
||||
}
|
||||
|
|
@ -532,15 +505,6 @@ pub struct ProcessExtended {
|
|||
}
|
||||
|
||||
impl ProcessExtended {
|
||||
fn add_metrics(&mut self, system: &mut System) {
|
||||
if let Some(prc) = system.process(self.pid.new_sysinfo_pid()) {
|
||||
self.cpu_usage = prc.cpu_usage() / system.cpus().len() as f32;
|
||||
self.ram_usage = system.total_memory() / prc.memory();
|
||||
self.disks_usage_read_bytes = prc.disk_usage().total_read_bytes;
|
||||
self.disks_usage_write_bytes = prc.disk_usage().total_written_bytes;
|
||||
self.virtual_mem_usage = prc.virtual_memory();
|
||||
}
|
||||
}
|
||||
pub fn from_process_query_all(system: &mut System, proc: processes::ProcessesAll) -> Self {
|
||||
system.refresh_processes(sysinfo::ProcessesToUpdate::All, true);
|
||||
return if let Some(prc) = system.process(proc.pid.new_sysinfo_pid()) {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use tokio::time::Duration;
|
|||
|
||||
pub mod v2 {
|
||||
use crate::options::structs::DependencyType;
|
||||
use crate::utils::metrics::processes::{ProcessesAll, ProcessesGeneral, ProcessesQuery};
|
||||
use crate::utils::metrics::processes::ProcessesGeneral;
|
||||
use log::info;
|
||||
use std::path::Path;
|
||||
use tokio::time::sleep;
|
||||
|
|
|
|||
Loading…
Reference in New Issue