Added uptime metrics for radarr
This commit is contained in:
+35
-13
@@ -1,9 +1,11 @@
|
||||
use std::ops::Sub;
|
||||
use chrono::{Duration, Utc};
|
||||
use tui::backend::Backend;
|
||||
use tui::layout::{Alignment, Constraint, Direction, Layout, Rect};
|
||||
use tui::layout::{Alignment, Constraint, Rect};
|
||||
use tui::style::Color::Cyan;
|
||||
use tui::style::{Color, Style};
|
||||
use tui::style::Style;
|
||||
use tui::text::{Spans, Text};
|
||||
use tui::widgets::{Block, Borders, Gauge, LineGauge, Paragraph};
|
||||
use tui::widgets::{Block, Borders, LineGauge, Paragraph};
|
||||
use tui::{symbols, Frame};
|
||||
|
||||
use crate::app::radarr::RadarrData;
|
||||
@@ -51,6 +53,7 @@ fn draw_stats<B: Backend>(f: &mut Frame<'_, B>, app: &App, area: Rect) {
|
||||
let RadarrData {
|
||||
free_space,
|
||||
total_space,
|
||||
start_time,
|
||||
..
|
||||
} = app.data.radarr_data;
|
||||
let ratio = if total_space == 0 {
|
||||
@@ -63,22 +66,40 @@ fn draw_stats<B: Backend>(f: &mut Frame<'_, B>, app: &App, area: Rect) {
|
||||
f.render_widget(base_block, area);
|
||||
|
||||
let chunks =
|
||||
vertical_chunks_with_margin(vec![Constraint::Length(1), Constraint::Min(2)], area, 1);
|
||||
vertical_chunks_with_margin(vec![
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(1),
|
||||
Constraint::Min(2)], area, 1);
|
||||
|
||||
let version = Paragraph::new(Text::from(format!(
|
||||
"Version: {}",
|
||||
let version_paragraph = Paragraph::new(Text::from(format!(
|
||||
"Radarr Version: {}",
|
||||
app.data.radarr_data.version
|
||||
)))
|
||||
.block(Block::default());
|
||||
f.render_widget(version, chunks[0]);
|
||||
|
||||
let uptime = Utc::now().sub(start_time);
|
||||
let days = uptime.num_days();
|
||||
let day_difference = uptime.sub(Duration::days(days));
|
||||
let hours = day_difference.num_hours();
|
||||
let hour_difference = day_difference.sub(Duration::hours(hours));
|
||||
let minutes = hour_difference.num_minutes();
|
||||
let seconds = hour_difference.sub(Duration::minutes(minutes)).num_seconds();
|
||||
|
||||
let uptime_paragraph = Paragraph::new(Text::from(format!(
|
||||
"Uptime: {}d {}:{}:{}",
|
||||
days, hours, minutes, seconds
|
||||
))).block(Block::default());
|
||||
|
||||
let space_gauge = LineGauge::default()
|
||||
.block(Block::default().title("Storage:"))
|
||||
.gauge_style(Style::default().fg(Cyan))
|
||||
.line_set(symbols::line::THICK)
|
||||
.ratio(ratio)
|
||||
.label(Spans::from(format!("{:.0}%", ratio * 100.0)));
|
||||
f.render_widget(space_gauge, chunks[1]);
|
||||
.block(Block::default().title("Storage:"))
|
||||
.gauge_style(Style::default().fg(Cyan))
|
||||
.line_set(symbols::line::THICK)
|
||||
.ratio(ratio)
|
||||
.label(Spans::from(format!("{:.0}%", ratio * 100.0)));
|
||||
|
||||
f.render_widget(version_paragraph, chunks[0]);
|
||||
f.render_widget(uptime_paragraph, chunks[1]);
|
||||
f.render_widget(space_gauge, chunks[2]);
|
||||
}
|
||||
|
||||
fn draw_logo<B: Backend>(f: &mut Frame<'_, B>, area: Rect) {
|
||||
@@ -89,5 +110,6 @@ fn draw_logo<B: Backend>(f: &mut Frame<'_, B>, area: Rect) {
|
||||
let logo = Paragraph::new(Text::from(RADARR_LOGO))
|
||||
.block(Block::default())
|
||||
.alignment(Alignment::Center);
|
||||
|
||||
f.render_widget(logo, chunks[0]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user