Skip to content

Commit

Permalink
Add metrics section
Browse files Browse the repository at this point in the history
  • Loading branch information
pythops committed Jan 6, 2025
1 parent 0ed04df commit c3b5a74
Show file tree
Hide file tree
Showing 5 changed files with 345 additions and 3 deletions.
1 change: 1 addition & 0 deletions oryx-tui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub enum ActivePopup {
UpdateFilters,
PacketInfos,
NewFirewallRule,
NewMetricExplorer,
}

#[derive(Debug)]
Expand Down
34 changes: 33 additions & 1 deletion oryx-tui/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ pub fn handle_key_events(
.handle_keys(key_event, event_sender.clone())?;
app.is_editing = false;
}
ActivePopup::NewMetricExplorer => {
app.section
.metrics
.handle_popup_keys(key_event, event_sender.clone())?;
app.is_editing = false;
}
_ => {}
}
}
Expand All @@ -92,6 +98,17 @@ pub fn handle_key_events(
app.is_editing = false;
}
}
ActivePopup::NewMetricExplorer => {
if app
.section
.metrics
.handle_popup_keys(key_event, event_sender.clone())
.is_ok()
{
app.active_popup = None;
app.is_editing = false;
}
}
_ => {}
},

Expand All @@ -104,6 +121,11 @@ pub fn handle_key_events(
.firewall
.handle_keys(key_event, event_sender.clone())?;
}
ActivePopup::NewMetricExplorer => {
app.section
.metrics
.handle_popup_keys(key_event, event_sender.clone())?;
}
_ => {}
},
}
Expand Down Expand Up @@ -158,11 +180,21 @@ pub fn handle_key_events(

KeyCode::Char('n') | KeyCode::Char('e') => {
if app.section.focused_section == FocusedSection::Firewall
&& app.section.handle_keys(key_event, event_sender).is_ok()
&& app
.section
.handle_keys(key_event, event_sender.clone())
.is_ok()
{
app.is_editing = true;
app.active_popup = Some(ActivePopup::NewFirewallRule);
}

if app.section.focused_section == FocusedSection::Metrics
&& app.section.handle_keys(key_event, event_sender).is_ok()
{
app.is_editing = true;
app.active_popup = Some(ActivePopup::NewMetricExplorer);
}
}

KeyCode::Char('i') => {
Expand Down
45 changes: 43 additions & 2 deletions oryx-tui/src/section.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod alert;
pub mod firewall;
pub mod inspection;
pub mod metrics;
pub mod stats;

use std::sync::{Arc, Mutex};
Expand All @@ -10,6 +11,7 @@ use crossterm::event::{KeyCode, KeyEvent};
use firewall::{Firewall, FirewallSignal};

use inspection::Inspection;
use metrics::Metrics;
use ratatui::{
layout::{Alignment, Constraint, Direction, Layout, Margin, Rect},
style::{Color, Style, Stylize},
Expand All @@ -30,6 +32,7 @@ use crate::{
pub enum FocusedSection {
Inspection,
Stats,
Metrics,
Alerts,
Firewall,
}
Expand All @@ -39,6 +42,7 @@ pub struct Section {
pub focused_section: FocusedSection,
pub inspection: Inspection,
pub stats: Option<Stats>,
pub metrics: Metrics,
pub alert: Alert,
pub firewall: Firewall,
}
Expand All @@ -52,6 +56,7 @@ impl Section {
focused_section: FocusedSection::Inspection,
inspection: Inspection::new(packets.clone()),
stats: None,
metrics: Metrics::new(packets.clone()),
alert: Alert::new(packets.clone()),
firewall: Firewall::new(firewall_chans.ingress.sender, firewall_chans.egress.sender),
}
Expand Down Expand Up @@ -79,6 +84,16 @@ impl Section {
Span::from(" Stats 󱕍 ").fg(Color::DarkGray)
}
}
FocusedSection::Metrics => {
if is_focused {
Span::styled(
" Metrics  ",
Style::default().bg(Color::Green).fg(Color::White).bold(),
)
} else {
Span::from(" Metrics  ").fg(Color::DarkGray)
}
}
FocusedSection::Alerts => self.alert.title_span(is_focused),
FocusedSection::Firewall => {
if is_focused {
Expand Down Expand Up @@ -133,6 +148,13 @@ impl Section {
Span::from(" ").bold(),
Span::from(": Naviguate").bold(),
]),
Some(ActivePopup::NewMetricExplorer) => Line::from(vec![
Span::from("󱊷 ").bold(),
Span::from(": Discard").bold(),
Span::from(" | ").bold(),
Span::from("󱞦 ").bold(),
Span::from(": Run").bold(),
]),
Some(ActivePopup::PacketInfos) | Some(ActivePopup::Help) => Line::from(vec![
Span::from("󱊷 ").bold(),
Span::from(": Discard Popup").bold(),
Expand Down Expand Up @@ -191,6 +213,19 @@ impl Section {
Span::from(" ").bold(),
Span::from(" Nav").bold(),
]),
FocusedSection::Metrics => Line::from(vec![
Span::from("n").bold(),
Span::from(" New").bold(),
Span::from(" | ").bold(),
Span::from("d").bold(),
Span::from(" Delete").bold(),
Span::from(" | ").bold(),
Span::from("f").bold(),
Span::from(" Filters").bold(),
Span::from(" | ").bold(),
Span::from(" ").bold(),
Span::from(" Nav").bold(),
]),
_ => Line::from(vec![
Span::from("f").bold(),
Span::from(" Filters").bold(),
Expand Down Expand Up @@ -219,6 +254,7 @@ impl Section {
Line::from(vec![
self.title_span(FocusedSection::Inspection),
self.title_span(FocusedSection::Stats),
self.title_span(FocusedSection::Metrics),
self.title_span(FocusedSection::Alerts),
self.title_span(FocusedSection::Firewall),
])
Expand All @@ -232,6 +268,7 @@ impl Section {
block,
);
}

pub fn render(
&mut self,
frame: &mut Frame,
Expand Down Expand Up @@ -259,6 +296,7 @@ impl Section {
stats.render(frame, section_block, network_interace)
}
}
FocusedSection::Metrics => self.metrics.render(frame, section_block),
FocusedSection::Alerts => self.alert.render(frame, section_block),
FocusedSection::Firewall => self.firewall.render(frame, section_block),
}
Expand All @@ -272,15 +310,17 @@ impl Section {
match key_event.code {
KeyCode::Tab => match self.focused_section {
FocusedSection::Inspection => self.focused_section = FocusedSection::Stats,
FocusedSection::Stats => self.focused_section = FocusedSection::Alerts,
FocusedSection::Stats => self.focused_section = FocusedSection::Metrics,
FocusedSection::Metrics => self.focused_section = FocusedSection::Alerts,
FocusedSection::Alerts => self.focused_section = FocusedSection::Firewall,
FocusedSection::Firewall => self.focused_section = FocusedSection::Inspection,
},

KeyCode::BackTab => match self.focused_section {
FocusedSection::Inspection => self.focused_section = FocusedSection::Firewall,
FocusedSection::Stats => self.focused_section = FocusedSection::Inspection,
FocusedSection::Alerts => self.focused_section = FocusedSection::Stats,
FocusedSection::Metrics => self.focused_section = FocusedSection::Stats,
FocusedSection::Alerts => self.focused_section = FocusedSection::Metrics,
FocusedSection::Firewall => self.focused_section = FocusedSection::Alerts,
},

Expand All @@ -291,6 +331,7 @@ impl Section {
FocusedSection::Firewall => self
.firewall
.handle_keys(key_event, notification_sender.clone())?,
FocusedSection::Metrics => self.metrics.handle_keys(key_event),
_ => {}
},
}
Expand Down
Loading

0 comments on commit c3b5a74

Please sign in to comment.