Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ibtop"
version = "0.1.5"
version = "0.1.7"
edition = "2021"
authors = ["info@jannik-straube.de"]
description = "Real-time terminal monitor for InfiniBand networks"
Expand All @@ -17,6 +17,7 @@ crossterm = "0.27"
rand = "0.9.2"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
hostname = "0.4"

[lints.clippy]
pedantic = "deny"
Binary file added ibtop
Binary file not shown.
16 changes: 14 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ use std::time::{Duration, Instant};
const UI_REFRESH_INTERVAL_MS: u64 = 33;
const METRICS_UPDATE_INTERVAL_MS: u64 = 250;

fn get_hostname() -> String {
hostname::get().map_or_else(
|_| "unknown".to_string(),
|h| h.to_string_lossy().into_owned(),
)
}

fn main() -> Result<(), io::Error> {
let args: Vec<String> = env::args().collect();
let json_mode = args.contains(&String::from("--json"));
Expand All @@ -41,7 +48,11 @@ fn run_json_mode() -> Result<(), io::Error> {
}
};

let json_output = serde_json::to_string_pretty(&adapters)?;
let output = types::IbtopOutput {
hostname: get_hostname(),
adapters,
};
let json_output = serde_json::to_string_pretty(&output)?;
println!("{json_output}");

Ok(())
Expand Down Expand Up @@ -74,6 +85,7 @@ fn run_interactive_mode() -> Result<(), io::Error> {
fn run_app<B: ratatui::backend::Backend>(terminal: &mut Terminal<B>) -> io::Result<()> {
let use_fake_data = std::env::var("IBTOP_FAKE_DATA").is_ok();
let mut metrics = metrics::MetricsCollector::new();
let hostname = get_hostname();

let ui_refresh_duration = Duration::from_millis(UI_REFRESH_INTERVAL_MS);
let metrics_update_interval = Duration::from_millis(METRICS_UPDATE_INTERVAL_MS);
Expand All @@ -100,7 +112,7 @@ fn run_app<B: ratatui::backend::Backend>(terminal: &mut Terminal<B>) -> io::Resu
last_metrics_update = now;
}

terminal.draw(|f| ui::draw(f, &adapters, &metrics))?;
terminal.draw(|f| ui::draw(f, &adapters, &metrics, &hostname))?;

let timeout = ui_refresh_duration.saturating_sub(now.elapsed());
if event::poll(timeout)? {
Expand Down
6 changes: 6 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ use serde::{Deserialize, Serialize};
use std::fmt::Display;
use std::str::FromStr;

#[derive(Debug, Serialize, Deserialize)]
pub(crate) struct IbtopOutput {
pub(crate) hostname: String,
pub(crate) adapters: Vec<AdapterInfo>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
pub(crate) enum PortState {
Active,
Expand Down
14 changes: 10 additions & 4 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ use ratatui::{
use crate::metrics::MetricsCollector;
use crate::types::AdapterInfo;

pub fn draw(frame: &mut Frame, adapters: &[AdapterInfo], metrics: &MetricsCollector) {
pub fn draw(
frame: &mut Frame,
adapters: &[AdapterInfo],
metrics: &MetricsCollector,
hostname: &str,
) {
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([
Expand All @@ -18,7 +23,7 @@ pub fn draw(frame: &mut Frame, adapters: &[AdapterInfo], metrics: &MetricsCollec
])
.split(frame.size());

draw_adapters(frame, chunks[1], adapters, metrics);
draw_adapters(frame, chunks[1], adapters, metrics, hostname);
draw_help_footer(frame, chunks[2]);
}

Expand All @@ -33,6 +38,7 @@ fn draw_adapters(
area: Rect,
adapters: &[AdapterInfo],
metrics: &MetricsCollector,
hostname: &str,
) {
let mut rows: Vec<Row> = Vec::new();

Expand All @@ -45,7 +51,7 @@ fn draw_adapters(
// Add adapter header row that spans the full width
rows.push(Row::new(vec![
Cell::from("Adapter:"),
Cell::from(adapter.name.to_string()).style(
Cell::from(adapter.name.clone()).style(
Style::default()
.fg(Color::Green)
.add_modifier(Modifier::BOLD),
Expand Down Expand Up @@ -141,7 +147,7 @@ fn draw_adapters(
.block(
Block::default()
.borders(Borders::ALL)
.title("ibtop - InfiniBand Monitor"),
.title(format!("ibtop - InfiniBand Monitor @ {hostname}")),
);

frame.render_widget(table, area);
Expand Down
Loading