fmt
parent
1c1252ecfe
commit
c59ac23997
|
|
@ -9,47 +9,28 @@ pub struct Cli {
|
|||
help = "explicit specify of NOXIS Socket file"
|
||||
)]
|
||||
pub socket: String,
|
||||
#[command(
|
||||
subcommand,
|
||||
help = "to manage Noxis work",
|
||||
)]
|
||||
#[command(subcommand, help = "to manage Noxis work")]
|
||||
pub command: Commands,
|
||||
}
|
||||
|
||||
#[derive(Debug, Subcommand, serde::Serialize, serde::Deserialize)]
|
||||
pub enum Commands {
|
||||
#[command(
|
||||
about = "To get info about current Noxis status",
|
||||
)]
|
||||
#[command(about = "To get info about current Noxis status")]
|
||||
Status,
|
||||
#[command(
|
||||
about = "To start Noxis process",
|
||||
)]
|
||||
#[command(about = "To start Noxis process")]
|
||||
Start(StartAction),
|
||||
#[command(
|
||||
about = "To stop Noxis process",
|
||||
)]
|
||||
#[command(about = "To stop Noxis process")]
|
||||
Stop,
|
||||
#[command(
|
||||
about = "To restart Noxis process",
|
||||
)]
|
||||
#[command(about = "To restart Noxis process")]
|
||||
Restart(StartAction),
|
||||
#[command(
|
||||
about = "To get list of processes that are being monitoring",
|
||||
)]
|
||||
#[command(about = "To get list of processes that are being monitoring")]
|
||||
Processes,
|
||||
// process command
|
||||
#[command(
|
||||
about = "To manage current process that is being monitoring",
|
||||
)]
|
||||
#[command(about = "To manage current process that is being monitoring")]
|
||||
Process(ProcessCommand),
|
||||
#[command(
|
||||
about = "To manage config settings",
|
||||
)]
|
||||
#[command(about = "To manage config settings")]
|
||||
Config(ConfigCommand),
|
||||
#[command(
|
||||
about = "To inspect system metrics in restricted mode",
|
||||
)]
|
||||
#[command(about = "To inspect system metrics in restricted mode")]
|
||||
Inspect(MetricsCommand),
|
||||
}
|
||||
|
||||
|
|
@ -77,139 +58,81 @@ pub struct ConfigCommand {
|
|||
|
||||
#[derive(Debug, Subcommand, serde::Serialize, serde::Deserialize)]
|
||||
pub enum ConfigAction {
|
||||
#[command(
|
||||
about = "To change current Noxis configuration",
|
||||
)]
|
||||
#[command(about = "To change current Noxis configuration")]
|
||||
Local(LocalConfig),
|
||||
#[command(
|
||||
about = "To change credentials of the remote config server",
|
||||
)]
|
||||
#[command(about = "To change credentials of the remote config server")]
|
||||
Remote,
|
||||
#[command(
|
||||
about = "To reset all config settings",
|
||||
)]
|
||||
#[command(about = "To reset all config settings")]
|
||||
Reset,
|
||||
#[command(
|
||||
about = "To get current Noxis configuration",
|
||||
name = "ls"
|
||||
)]
|
||||
#[command(about = "To get current Noxis configuration", name = "ls")]
|
||||
Show(EnvConfig),
|
||||
}
|
||||
#[derive(Debug, Parser, serde::Serialize, serde::Deserialize)]
|
||||
pub struct EnvConfig {
|
||||
// flag
|
||||
#[arg(
|
||||
long = "env",
|
||||
action,
|
||||
help = "to read environment vars configuration",
|
||||
)]
|
||||
#[arg(long = "env", action, help = "to read environment vars configuration")]
|
||||
pub is_env: bool,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Parser, serde::Serialize, serde::Deserialize)]
|
||||
pub struct LocalConfig {
|
||||
// flag
|
||||
#[arg(
|
||||
long = "json",
|
||||
action,
|
||||
help = "to read following input as JSON",
|
||||
)]
|
||||
#[arg(long = "json", action, help = "to read following input as JSON")]
|
||||
pub is_json: bool,
|
||||
// value
|
||||
#[arg(
|
||||
help = "path to config file or config String (with --json flag)",
|
||||
)]
|
||||
#[arg(help = "path to config file or config String (with --json flag)")]
|
||||
pub config: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser, serde::Serialize, serde::Deserialize)]
|
||||
pub struct ProcessCommand {
|
||||
#[arg(
|
||||
help = "name of needed process",
|
||||
)]
|
||||
#[arg(help = "name of needed process")]
|
||||
pub process: String,
|
||||
#[command(
|
||||
subcommand,
|
||||
help = "To get current process's status",
|
||||
)]
|
||||
#[command(subcommand, help = "To get current process's status")]
|
||||
pub action: ProcessAction,
|
||||
}
|
||||
|
||||
#[derive(Debug, Subcommand, serde::Serialize, serde::Deserialize)]
|
||||
pub enum ProcessAction {
|
||||
#[command(
|
||||
about = "To get info about current process status",
|
||||
)]
|
||||
#[command(about = "To get info about current process status")]
|
||||
Status,
|
||||
#[command(
|
||||
about = "To start current process",
|
||||
)]
|
||||
#[command(about = "To start current process")]
|
||||
Start,
|
||||
#[command(
|
||||
about = "To stop current process",
|
||||
)]
|
||||
#[command(about = "To stop current process")]
|
||||
Stop,
|
||||
#[command(
|
||||
about = "To freeze (hybernaze) current process",
|
||||
)]
|
||||
#[command(about = "To freeze (hybernaze) current process")]
|
||||
Freeze,
|
||||
#[command(
|
||||
about = "To unfreeze (unhybernaze) current process",
|
||||
)]
|
||||
#[command(about = "To unfreeze (unhybernaze) current process")]
|
||||
Unfreeze,
|
||||
#[command(
|
||||
about = "To restart current process",
|
||||
)]
|
||||
#[command(about = "To restart current process")]
|
||||
Restart,
|
||||
#[command(
|
||||
about = "To get info about current process's dependencies",
|
||||
)]
|
||||
#[command(about = "To get info about current process's dependencies")]
|
||||
Deps,
|
||||
#[command(
|
||||
about = "To get info about current process's files-dependencies",
|
||||
)]
|
||||
#[command(about = "To get info about current process's files-dependencies")]
|
||||
Files,
|
||||
#[command(
|
||||
about = "To get info about current process's services-dependencies",
|
||||
)]
|
||||
#[command(about = "To get info about current process's services-dependencies")]
|
||||
Services,
|
||||
}
|
||||
|
||||
pub mod metrics_models {
|
||||
#[derive(Debug, clap::Parser, serde::Serialize, serde::Deserialize)]
|
||||
pub enum MetricsMode {
|
||||
#[command(
|
||||
about = "To capture all metrics about undercontrolled system",
|
||||
)]
|
||||
#[command(about = "To capture all metrics about undercontrolled system")]
|
||||
Full,
|
||||
// system
|
||||
#[command(
|
||||
about = "To capture general host info",
|
||||
)]
|
||||
#[command(about = "To capture general host info")]
|
||||
Host,
|
||||
#[command(
|
||||
about = "To capture detailed CPU metrics",
|
||||
)]
|
||||
#[command(about = "To capture detailed CPU metrics")]
|
||||
Cpu,
|
||||
#[command(
|
||||
about = "To capture RAM metrics",
|
||||
)]
|
||||
#[command(about = "To capture RAM metrics")]
|
||||
Ram,
|
||||
#[command(
|
||||
about = "To capture disk environment metrics",
|
||||
)]
|
||||
#[command(about = "To capture disk environment metrics")]
|
||||
Rom,
|
||||
#[command(
|
||||
about = "To capture system net interfaces metrics",
|
||||
)]
|
||||
#[command(about = "To capture system net interfaces metrics")]
|
||||
Network,
|
||||
// processes
|
||||
#[command(
|
||||
about = "To capture monitoring processes metrics",
|
||||
)]
|
||||
Processes
|
||||
// Config
|
||||
#[command(about = "To capture monitoring processes metrics")]
|
||||
Processes, // Config
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,5 +11,5 @@ pub enum NoxisCliError {
|
|||
#[error("Can't parse CLI struct and send as byte stream")]
|
||||
ToStringCliParsingParsing,
|
||||
#[error("Can't read Noxis response due to {0}")]
|
||||
CliResponseReadError(String)
|
||||
CliResponseReadError(String),
|
||||
}
|
||||
|
|
@ -1,26 +1,30 @@
|
|||
use tokio::net::UnixStream;
|
||||
use tokio::io::{AsyncWriteExt, AsyncReadExt};
|
||||
use anyhow::Result;
|
||||
use super::Cli;
|
||||
use super::cli_error::NoxisCliError;
|
||||
use super::Cli;
|
||||
use anyhow::Result;
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::net::UnixStream;
|
||||
|
||||
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()))?)
|
||||
Ok(UnixStream::connect(&cli.socket).await.map_err(|er| {
|
||||
NoxisCliError::NoxisDaemonMissing((&cli.socket).to_string(), er.to_string())
|
||||
})?)
|
||||
}
|
||||
|
||||
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)?;
|
||||
let msg = serde_json::to_vec(&cli).map_err(|_| NoxisCliError::ToStringCliParsingParsing)?;
|
||||
|
||||
stream.write_all(&msg)
|
||||
stream
|
||||
.write_all(&msg)
|
||||
.await
|
||||
.map_err(|_| NoxisCliError::CliPromptCanNotBeSent)?;
|
||||
|
||||
let mut response = Vec::new();
|
||||
stream.read_to_end(&mut response).await
|
||||
stream
|
||||
.read_to_end(&mut response)
|
||||
.await
|
||||
.map_err(|er| NoxisCliError::CliResponseReadError(er.to_string()))?;
|
||||
|
||||
let response = String::from_utf8_lossy(&response);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
mod cli;
|
||||
mod cli_net;
|
||||
mod cli_error;
|
||||
mod cli_net;
|
||||
|
||||
pub use cli::*;
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
mod cli;
|
||||
mod cli_net;
|
||||
mod cli_error;
|
||||
mod cli_net;
|
||||
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use cli::Cli;
|
||||
use cli_net::try_send;
|
||||
use anyhow::Result;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
|
|
|
|||
|
|
@ -278,7 +278,8 @@ pub mod v2 {
|
|||
&self.prcs,
|
||||
&self.files,
|
||||
&self.services,
|
||||
).await;
|
||||
)
|
||||
.await;
|
||||
let _ = self.bus.1.clone().send(BusMessage::Response(
|
||||
crate::options::structs::bus::BusMessageDirection::ToMetrics,
|
||||
BusMessageContentType::ProcessQuery,
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ pub async fn init_metrics_grubber(
|
|||
// inspect processes
|
||||
MetricsMode::Processes => {
|
||||
todo!();
|
||||
},
|
||||
}
|
||||
};
|
||||
// let metric: Box<dyn BusContent> = Box::new(metric);
|
||||
let metric = metric.serialze_into_output();
|
||||
|
|
@ -125,25 +125,19 @@ pub async fn init_metrics_grubber(
|
|||
.send(BusMessage::Response(
|
||||
BusMessageDirection::ToCli,
|
||||
BusMessageContentType::Result,
|
||||
Box::<anyhow::Result<String>>::new(
|
||||
Ok(serde_json::to_string_pretty(&procs)?)
|
||||
)
|
||||
),
|
||||
)
|
||||
Box::<anyhow::Result<String>>::new(Ok(serde_json::to_string_pretty(
|
||||
&procs,
|
||||
)?)),
|
||||
))
|
||||
.await;
|
||||
} else {
|
||||
let _ = bus_sender
|
||||
.send(BusMessage::Response(
|
||||
BusMessageDirection::ToCli,
|
||||
BusMessageContentType::Result,
|
||||
Box::new(
|
||||
Err(
|
||||
anyhow::Error::msg(format!(
|
||||
Box::new(Err(anyhow::Error::msg(format!(
|
||||
"Unknown type was send by the Supervisor"
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
)))),
|
||||
))
|
||||
.await;
|
||||
}
|
||||
|
|
@ -152,14 +146,9 @@ pub async fn init_metrics_grubber(
|
|||
.send(BusMessage::Response(
|
||||
BusMessageDirection::ToCli,
|
||||
BusMessageContentType::Result,
|
||||
Box::new(
|
||||
Err(
|
||||
anyhow::Error::msg(format!(
|
||||
Box::new(Err(anyhow::Error::msg(format!(
|
||||
"Unknown type was send by the Supervisor"
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
)))),
|
||||
))
|
||||
.await;
|
||||
}
|
||||
|
|
@ -552,10 +541,7 @@ impl ProcessExtended {
|
|||
self.virtual_mem_usage = prc.virtual_memory();
|
||||
}
|
||||
}
|
||||
pub fn from_process_query_all(
|
||||
system: &mut System,
|
||||
proc : processes::ProcessesAll
|
||||
) -> Self {
|
||||
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()) {
|
||||
let disk_usage = prc.disk_usage();
|
||||
|
|
@ -582,7 +568,7 @@ impl ProcessExtended {
|
|||
disks_usage_read_bytes: 0,
|
||||
disks_usage_write_bytes: 0,
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue