refactor: remove pointless clone()'s & variable declarations
This commit is contained in:
@@ -318,7 +318,6 @@ impl fmt::Display for ByteStats {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub type MemTuple = (Vec<(f64, f64)>, ByteStats, State);
|
pub type MemTuple = (Vec<(f64, f64)>, ByteStats, State);
|
||||||
pub type CpuTuple = (Vec<(f64, f64)>, CpuStats, State);
|
pub type CpuTuple = (Vec<(f64, f64)>, CpuStats, State);
|
||||||
|
|
||||||
@@ -398,20 +397,12 @@ impl ContainerItem {
|
|||||||
|
|
||||||
/// Get all cpu chart data
|
/// Get all cpu chart data
|
||||||
fn get_cpu_chart_data(&self) -> CpuTuple {
|
fn get_cpu_chart_data(&self) -> CpuTuple {
|
||||||
(
|
(self.get_cpu_dataset(), self.max_cpu_stats(), self.state)
|
||||||
self.get_cpu_dataset(),
|
|
||||||
self.max_cpu_stats(),
|
|
||||||
self.state,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get all mem chart data
|
/// Get all mem chart data
|
||||||
fn get_mem_chart_data(&self) -> MemTuple {
|
fn get_mem_chart_data(&self) -> MemTuple {
|
||||||
(
|
(self.get_mem_dataset(), self.max_mem_stats(), self.state)
|
||||||
self.get_mem_dataset(),
|
|
||||||
self.max_mem_stats(),
|
|
||||||
self.state,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get chart info for cpu & memory in one function
|
/// Get chart info for cpu & memory in one function
|
||||||
|
|||||||
+25
-24
@@ -33,6 +33,7 @@ enum SpawnId {
|
|||||||
/// Cpu & Mem stats take twice as long as the update interval to get a value, so will have two being executed at the same time
|
/// Cpu & Mem stats take twice as long as the update interval to get a value, so will have two being executed at the same time
|
||||||
/// SpawnId::Stats takes container_id and binate value to enable both cycles of the same container_id to be inserted into the hashmap
|
/// SpawnId::Stats takes container_id and binate value to enable both cycles of the same container_id to be inserted into the hashmap
|
||||||
/// Binate value is toggled when all join handles have been spawned off
|
/// Binate value is toggled when all join handles have been spawned off
|
||||||
|
/// Also effectively means that if the docker_update interval minimum will be 1000ms
|
||||||
#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)]
|
#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)]
|
||||||
enum Binate {
|
enum Binate {
|
||||||
One,
|
One,
|
||||||
@@ -113,22 +114,20 @@ impl DockerData {
|
|||||||
let mem_stat = stats.memory_stats.usage.unwrap_or(0);
|
let mem_stat = stats.memory_stats.usage.unwrap_or(0);
|
||||||
let mem_limit = stats.memory_stats.limit.unwrap_or(0);
|
let mem_limit = stats.memory_stats.limit.unwrap_or(0);
|
||||||
|
|
||||||
let some_key = stats
|
let op_key = stats
|
||||||
.networks
|
.networks
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|networks| networks.keys().next().cloned());
|
.and_then(|networks| networks.keys().next().cloned());
|
||||||
|
|
||||||
let cpu_stats = Self::calculate_usage(&stats);
|
let cpu_stats = Self::calculate_usage(&stats);
|
||||||
|
|
||||||
let no_bytes = || (0, 0);
|
let (rx, tx) = if let Some(key) = op_key {
|
||||||
|
|
||||||
let (rx, tx) = if let Some(key) = some_key {
|
|
||||||
match stats.networks.unwrap_or_default().get(&key) {
|
match stats.networks.unwrap_or_default().get(&key) {
|
||||||
Some(data) => (data.rx_bytes, data.tx_bytes),
|
Some(data) => (data.rx_bytes, data.tx_bytes),
|
||||||
None => no_bytes(),
|
None => (0, 0),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
no_bytes()
|
(0, 0)
|
||||||
};
|
};
|
||||||
|
|
||||||
if is_running {
|
if is_running {
|
||||||
@@ -155,8 +154,6 @@ impl DockerData {
|
|||||||
let docker = Arc::clone(&self.docker);
|
let docker = Arc::clone(&self.docker);
|
||||||
let app_data = Arc::clone(&self.app_data);
|
let app_data = Arc::clone(&self.app_data);
|
||||||
let spawns = Arc::clone(&self.spawns);
|
let spawns = Arc::clone(&self.spawns);
|
||||||
let id = id.clone();
|
|
||||||
|
|
||||||
let key = SpawnId::Stats((id.clone(), self.binate));
|
let key = SpawnId::Stats((id.clone(), self.binate));
|
||||||
|
|
||||||
let spawn_key = key.clone();
|
let spawn_key = key.clone();
|
||||||
@@ -228,19 +225,18 @@ impl DockerData {
|
|||||||
docker: Arc<Docker>,
|
docker: Arc<Docker>,
|
||||||
id: String,
|
id: String,
|
||||||
timestamps: bool,
|
timestamps: bool,
|
||||||
since: i64,
|
since: u64,
|
||||||
app_data: Arc<Mutex<AppData>>,
|
app_data: Arc<Mutex<AppData>>,
|
||||||
spawns: Arc<Mutex<HashMap<SpawnId, JoinHandle<()>>>>,
|
spawns: Arc<Mutex<HashMap<SpawnId, JoinHandle<()>>>>,
|
||||||
) {
|
) {
|
||||||
let options = Some(LogsOptions::<String> {
|
let options = Some(LogsOptions::<String> {
|
||||||
stdout: true,
|
stdout: true,
|
||||||
timestamps,
|
timestamps,
|
||||||
since,
|
since: since as i64,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut logs = docker.logs(&id, options);
|
let mut logs = docker.logs(&id, options);
|
||||||
|
|
||||||
let mut output = vec![];
|
let mut output = vec![];
|
||||||
|
|
||||||
while let Some(value) = logs.next().await {
|
while let Some(value) = logs.next().await {
|
||||||
@@ -259,15 +255,18 @@ impl DockerData {
|
|||||||
fn init_all_logs(&mut self, all_ids: &[(bool, String)]) {
|
fn init_all_logs(&mut self, all_ids: &[(bool, String)]) {
|
||||||
for (_, id) in all_ids.iter() {
|
for (_, id) in all_ids.iter() {
|
||||||
let docker = Arc::clone(&self.docker);
|
let docker = Arc::clone(&self.docker);
|
||||||
let timestamps = self.timestamps;
|
|
||||||
let id = id.clone();
|
|
||||||
let app_data = Arc::clone(&self.app_data);
|
let app_data = Arc::clone(&self.app_data);
|
||||||
let spawns = Arc::clone(&self.spawns);
|
let spawns = Arc::clone(&self.spawns);
|
||||||
let key = SpawnId::Log(id.clone());
|
let key = SpawnId::Log(id.clone());
|
||||||
self.spawns.lock().insert(
|
self.spawns.lock().insert(
|
||||||
key,
|
key,
|
||||||
tokio::spawn(Self::update_log(
|
tokio::spawn(Self::update_log(
|
||||||
docker, id, timestamps, 0, app_data, spawns,
|
docker,
|
||||||
|
id.clone(),
|
||||||
|
self.timestamps,
|
||||||
|
0,
|
||||||
|
app_data,
|
||||||
|
spawns,
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -278,20 +277,24 @@ impl DockerData {
|
|||||||
let all_ids = self.update_all_containers().await;
|
let all_ids = self.update_all_containers().await;
|
||||||
let optional_index = self.app_data.lock().get_selected_log_index();
|
let optional_index = self.app_data.lock().get_selected_log_index();
|
||||||
if let Some(index) = optional_index {
|
if let Some(index) = optional_index {
|
||||||
// this could be neater
|
if let Some(container) = self.app_data.lock().containers.items.get(index) {
|
||||||
let id = self.app_data.lock().containers.items[index].id.clone();
|
self.spawns
|
||||||
let key = SpawnId::Log(id.clone());
|
.lock()
|
||||||
|
.entry(SpawnId::Log(container.id.clone()))
|
||||||
self.spawns.lock().entry(key).or_insert_with(|| {
|
.or_insert_with(|| {
|
||||||
let since = self.app_data.lock().containers.items[index].last_updated as i64;
|
|
||||||
let docker = Arc::clone(&self.docker);
|
let docker = Arc::clone(&self.docker);
|
||||||
let timestamps = self.timestamps;
|
|
||||||
let app_data = Arc::clone(&self.app_data);
|
let app_data = Arc::clone(&self.app_data);
|
||||||
let spawns = Arc::clone(&self.spawns);
|
let spawns = Arc::clone(&self.spawns);
|
||||||
tokio::spawn(Self::update_log(
|
tokio::spawn(Self::update_log(
|
||||||
docker, id, timestamps, since, app_data, spawns,
|
docker,
|
||||||
|
container.id.clone(),
|
||||||
|
self.timestamps,
|
||||||
|
container.last_updated,
|
||||||
|
app_data,
|
||||||
|
spawns,
|
||||||
))
|
))
|
||||||
});
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
self.update_all_container_stats(&all_ids);
|
self.update_all_container_stats(&all_ids);
|
||||||
}
|
}
|
||||||
@@ -391,8 +394,6 @@ impl DockerData {
|
|||||||
.lock()
|
.lock()
|
||||||
.set_error(AppError::DockerCommand(DockerControls::Unpause));
|
.set_error(AppError::DockerCommand(DockerControls::Unpause));
|
||||||
};
|
};
|
||||||
// loading sping take uuid to remove
|
|
||||||
// stop_loading_sping(uuid)
|
|
||||||
self.stop_loading_spin(&loading_spin, loading_uuid);
|
self.stop_loading_spin(&loading_spin, loading_uuid);
|
||||||
self.update_everything().await;
|
self.update_everything().await;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-5
@@ -46,8 +46,7 @@ async fn main() {
|
|||||||
|
|
||||||
// Create docker daemon handler, and only spawn up the docker data handler if ping returns non-error
|
// Create docker daemon handler, and only spawn up the docker data handler if ping returns non-error
|
||||||
match Docker::connect_with_socket_defaults() {
|
match Docker::connect_with_socket_defaults() {
|
||||||
Ok(docker) => {
|
Ok(docker) => match docker.ping().await {
|
||||||
match docker.ping().await {
|
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let docker = Arc::new(docker);
|
let docker = Arc::new(docker);
|
||||||
let is_running = Arc::clone(&is_running);
|
let is_running = Arc::clone(&is_running);
|
||||||
@@ -61,8 +60,7 @@ async fn main() {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
Err(_) => app_data.lock().set_error(AppError::DockerConnect),
|
Err(_) => app_data.lock().set_error(AppError::DockerConnect),
|
||||||
}
|
},
|
||||||
}
|
|
||||||
Err(_) => app_data.lock().set_error(AppError::DockerConnect),
|
Err(_) => app_data.lock().set_error(AppError::DockerConnect),
|
||||||
}
|
}
|
||||||
let input_app_data = Arc::clone(&app_data);
|
let input_app_data = Arc::clone(&app_data);
|
||||||
@@ -82,7 +80,6 @@ async fn main() {
|
|||||||
input_is_running,
|
input_is_running,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
if args.gui {
|
if args.gui {
|
||||||
let update_duration = std::time::Duration::from_millis(u64::from(args.docker_interval));
|
let update_duration = std::time::Duration::from_millis(u64::from(args.docker_interval));
|
||||||
create_ui(
|
create_ui(
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use tracing::error;
|
|||||||
// #[command(help_template = FULL_TEMPLATE)]
|
// #[command(help_template = FULL_TEMPLATE)]
|
||||||
#[command(version, about)]
|
#[command(version, about)]
|
||||||
pub struct CliArgs {
|
pub struct CliArgs {
|
||||||
/// Docker update interval in ms, minimum 1, reccomended 500+
|
/// Docker update interval in ms, minimum effectively 1000
|
||||||
#[clap(short = 'd', value_name = "ms", default_value_t = 1000)]
|
#[clap(short = 'd', value_name = "ms", default_value_t = 1000)]
|
||||||
pub docker_interval: u32,
|
pub docker_interval: u32,
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ const DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION");
|
|||||||
const ORANGE: Color = Color::Rgb(255, 178, 36);
|
const ORANGE: Color = Color::Rgb(255, 178, 36);
|
||||||
const MARGIN: &str = " ";
|
const MARGIN: &str = " ";
|
||||||
const ARROW: &str = "▶ ";
|
const ARROW: &str = "▶ ";
|
||||||
const CIRCLE: &str ="⚪ ";
|
const CIRCLE: &str = "⚪ ";
|
||||||
|
|
||||||
/// Generate block, add a border if is the selected panel,
|
/// Generate block, add a border if is the selected panel,
|
||||||
/// add custom title based on state of each panel
|
/// add custom title based on state of each panel
|
||||||
|
|||||||
Reference in New Issue
Block a user