forge
Explore
Log in

Don't you dare go Hollow

Health page has a status line, a storage card in GiB and a quiet services list instead of equal tiles

Browse files at this commit

9d4e224b6ddf4142cf8009b3f969977ed0ed185aAhmet Kaan GümüşParent: 12e6ee0
  • style
    • health page has a status line, a storage card in GiB and a quiet services list instead of equal tiles
Show full message
💄 style: health page has a status line, a storage card in GiB and a quiet services list instead of equal tiles
crates/forge-web/src/i18n/accounts.rsmodified+40 -15
@@ -37,10 +37,8 @@ pub enum A {
37 AccountSuspended,37 AccountSuspended,
38 Dismiss,38 Dismiss,
39 Health,39 Health,
40- DataDirectory,
41 BackupDirectory,40 BackupDirectory,
42 DatabaseFile,41 DatabaseFile,
43- RepoStorage,
44 Free,42 Free,
45 CiQueue,43 CiQueue,
46 QueuedJobs,44 QueuedJobs,
@@ -50,8 +48,6 @@ pub enum A {
50 Failed,48 Failed,
51 LastBackup,49 LastBackup,
52 Replication,50 Replication,
53- Uptime,
54- Version,
55 NotConfigured,51 NotConfigured,
56 Unavailable,52 Unavailable,
57 Never,53 Never,
@@ -59,6 +55,10 @@ pub enum A {
59 Error,55 Error,
60 Lagging,56 Lagging,
61 HealthIntro,57 HealthIntro,
58+ Storage,
59+ Services,
60+ Fine,
61+ DiskUsed,
62 }62 }
63 63
64 pub fn t(lang: Lang, key: A) -> &'static str {64 pub fn t(lang: Lang, key: A) -> &'static str {
@@ -141,20 +141,16 @@ pub fn t(lang: Lang, key: A) -> &'static str {
141 (Dismiss, Tr) => "Kapat",141 (Dismiss, Tr) => "Kapat",
142 (Health, En) => "Health",142 (Health, En) => "Health",
143 (Health, Tr) => "Sağlık",143 (Health, Tr) => "Sağlık",
144- (DataDirectory, En) => "Data directory",
145- (DataDirectory, Tr) => "Veri dizini",
146 (BackupDirectory, En) => "Backup directory",144 (BackupDirectory, En) => "Backup directory",
147 (BackupDirectory, Tr) => "Yedek dizini",145 (BackupDirectory, Tr) => "Yedek dizini",
148 (DatabaseFile, En) => "Database file",146 (DatabaseFile, En) => "Database file",
149 (DatabaseFile, Tr) => "Veritabanı dosyası",147 (DatabaseFile, Tr) => "Veritabanı dosyası",
150- (RepoStorage, En) => "Repositories on disk",
151- (RepoStorage, Tr) => "Diskteki depolar",
152 (Free, En) => "free of",148 (Free, En) => "free of",
153 (Free, Tr) => "boş, toplam",149 (Free, Tr) => "boş, toplam",
154 (CiQueue, En) => "CI queue",150 (CiQueue, En) => "CI queue",
155 (CiQueue, Tr) => "CI kuyruğu",151 (CiQueue, Tr) => "CI kuyruğu",
156- (QueuedJobs, En) => "queued jobs",152+ (QueuedJobs, En) => "queued",
157- (QueuedJobs, Tr) => "bekleyen iş",153+ (QueuedJobs, Tr) => "bekleyen",
158 (RunnersOnline, En) => "runners online",154 (RunnersOnline, En) => "runners online",
159 (RunnersOnline, Tr) => "çalıştırıcı çevrim içi",155 (RunnersOnline, Tr) => "çalıştırıcı çevrim içi",
160 (MailQueue, En) => "Mail queue",156 (MailQueue, En) => "Mail queue",
@@ -167,10 +163,6 @@ pub fn t(lang: Lang, key: A) -> &'static str {
167 (LastBackup, Tr) => "Son yedek",163 (LastBackup, Tr) => "Son yedek",
168 (Replication, En) => "Replication",164 (Replication, En) => "Replication",
169 (Replication, Tr) => "Çoğaltma",165 (Replication, Tr) => "Çoğaltma",
170- (Uptime, En) => "Uptime",
171- (Uptime, Tr) => "Çalışma süresi",
172- (Version, En) => "Version",
173- (Version, Tr) => "Sürüm",
174 (NotConfigured, En) => "Not configured",166 (NotConfigured, En) => "Not configured",
175 (NotConfigured, Tr) => "Ayarlanmamış",167 (NotConfigured, Tr) => "Ayarlanmamış",
176 (Unavailable, En) => "Unavailable",168 (Unavailable, En) => "Unavailable",
@@ -185,6 +177,14 @@ pub fn t(lang: Lang, key: A) -> &'static str {
185 (Lagging, Tr) => "Geride",177 (Lagging, Tr) => "Geride",
186 (HealthIntro, En) => "Read when the page loads. Reload the page for fresh numbers.",178 (HealthIntro, En) => "Read when the page loads. Reload the page for fresh numbers.",
187 (HealthIntro, Tr) => "Sayfa açılırken okunur. Güncel değerler için sayfayı yenileyin.",179 (HealthIntro, Tr) => "Sayfa açılırken okunur. Güncel değerler için sayfayı yenileyin.",
180+ (Storage, En) => "Storage",
181+ (Storage, Tr) => "Depolama",
182+ (Services, En) => "Services",
183+ (Services, Tr) => "Hizmetler",
184+ (Fine, En) => "Everything looks fine",
185+ (Fine, Tr) => "Her şey yolunda",
186+ (DiskUsed, En) => "used",
187+ (DiskUsed, Tr) => "kullanıldı",
188 }188 }
189 }189 }
190 190
@@ -201,7 +201,32 @@ pub fn suspended_message(lang: Lang, reason: &str) -> String {
201 }201 }
202 }202 }
203 203
204-/// `3d 4h`, `5h 2m` or `7m`, for the uptime tile.204+/// The health summary when items need attention: "1 needs attention", "2 need attention".
205+pub fn needs_attention(lang: Lang, n: usize) -> String {
206+ match lang {
207+ Lang::En if n == 1 => "1 needs attention".to_owned(),
208+ Lang::En => format!("{n} need attention"),
209+ Lang::Tr => format!("{n} öğe dikkat istiyor"),
210+ }
211+}
212+
213+/// A repository tree's size, as "{size} on disk".
214+pub fn on_disk(lang: Lang, size: &str) -> String {
215+ match lang {
216+ Lang::En => format!("{size} on disk"),
217+ Lang::Tr => format!("{size} diskte"),
218+ }
219+}
220+
221+/// The health page footer: uptime, version, build and build date.
222+pub fn meta_line(lang: Lang, uptime: &str, version: &str, build: &str, date: &str) -> String {
223+ match lang {
224+ Lang::En => format!("Up {uptime} · Version {version} ({build}, {date})"),
225+ Lang::Tr => format!("Çalışma süresi {uptime} · Sürüm {version} ({build}, {date})"),
226+ }
227+}
228+
229+/// `3d 4h`, `5h 2m` or `7m`, for the uptime.
205 pub fn duration_short(secs: u64) -> String {230 pub fn duration_short(secs: u64) -> String {
206 let (d, h, m) = (secs / 86_400, secs % 86_400 / 3_600, secs % 3_600 / 60);231 let (d, h, m) = (secs / 86_400, secs % 86_400 / 3_600, secs % 3_600 / 60);
207 if d > 0 {232 if d > 0 {
crates/forge-web/src/pages/admin_health.rsmodified+296 -158
@@ -1,6 +1,7 @@
1-//! Page: instance health for admins (`/admin/health`). A compact grid of tiles, read when the page1+//! Page: instance health for admins (`/admin/health`). A summary line, a storage card with the data
2-//! loads. Every number is a cheap query or a short external probe (`df`, `du`), so there is no2+//! disk's usage bar, and a services card. Every number is a cheap query or a short external probe
3-//! polling; reloading the page, or opening it again, reads fresh values. Non-admins get 404.3+//! (`df`, `du`), so there is no polling; reloading the page, or opening it again, reads fresh values.
4+//! Non-admins get 404.
4 5
5 use std::path::Path;6 use std::path::Path;
6 use std::time::Duration;7 use std::time::Duration;
@@ -17,7 +18,7 @@ use topcoat::router::response::Response;
17 use topcoat::router::{page, route};18 use topcoat::router::{page, route};
18 use topcoat::view::{View, component, view};19 use topcoat::view::{View, component, view};
19 20
20-use crate::i18n::accounts::{A, duration_short, t as at};21+use crate::i18n::accounts::{A, duration_short, meta_line, needs_attention, on_disk, t as at};
21 use crate::i18n::alerts as alert_text;22 use crate::i18n::alerts as alert_text;
22 use crate::i18n::{self, Lang};23 use crate::i18n::{self, Lang};
23 use crate::live::{Topic, stream_changes};24 use crate::live::{Topic, stream_changes};
@@ -25,28 +26,90 @@ use crate::pages::admin_users::admin_only;
25 use crate::state::AppState;26 use crate::state::AppState;
26 use crate::views::{human_size, now_unix, rel_time, shell};27 use crate::views::{human_size, now_unix, rel_time, shell};
27 28
28-/// One cell of the grid.29+/// How a dot or a value is drawn: a bad outcome, a good one, a plain count, or a feature that is
29-struct Tile {30+/// not set up.
30- title: &'static str,31+#[derive(Clone, Copy, PartialEq, Eq)]
31- big: String,32+enum Dot {
32- sub: String,33+ Ok,
33- /// A stamp shown after `sub` as a live relative time.34+ Bad,
35+ Neutral,
36+ /// Not configured: a hollow dot, and a muted value.
37+ Off,
38+}
39+
40+impl Dot {
41+ fn class(self) -> &'static str {
42+ match self {
43+ Dot::Ok => "ok",
44+ Dot::Bad => "bad",
45+ Dot::Neutral => "neutral",
46+ Dot::Off => "off",
47+ }
48+ }
49+
50+ /// The class for a value cell: bad values are red, off ones muted.
51+ fn value_class(self) -> &'static str {
52+ match self {
53+ Dot::Bad => "bad",
54+ Dot::Off => "muted",
55+ Dot::Ok | Dot::Neutral => "",
56+ }
57+ }
58+}
59+
60+/// The data directory's disk: the usage bar and its numbers.
61+struct Usage {
62+ used: String,
63+ /// "{free} free of {total}".
64+ free_of_total: String,
65+ path: String,
66+ /// Percent used, the bar's fill.
67+ pct: u8,
68+ /// At least 90% used.
69+ bad: bool,
70+}
71+
72+/// One fact in the storage card's row of columns.
73+struct Fact {
74+ label: &'static str,
75+ value: String,
76+ detail: String,
77+ dot: Dot,
78+}
79+
80+/// One row of the services card.
81+struct Service {
82+ label: &'static str,
83+ dot: Dot,
84+ value: String,
85+ detail: String,
86+ /// A stamp shown after `detail` as a live relative time.
34 stamp: Option<String>,87 stamp: Option<String>,
35- /// `""`, `ok` or `bad`.
36- tone: &'static str,
37- /// Percent of a meter to fill, for disk tiles.
38- meter: Option<u8>,
39 }88 }
40 89
41-fn tile(title: &'static str, big: impl Into<String>, sub: impl Into<String>) -> Tile {90+/// Everything the page shows, and how many items need attention.
42- Tile {91+struct Health {
43- title,92+ usage: Option<Usage>,
44- big: big.into(),93+ facts: Vec<Fact>,
45- sub: sub.into(),94+ services: Vec<Service>,
46- stamp: None,95+ meta: String,
47- tone: "",96+ attention: usize,
48- meter: None,
49 }97 }
98+
99+/// `(percent used, "{free} free of {total}")` for a disk's `(total, available)` bytes.
100+fn space(lang: Lang, total: u64, avail: u64) -> (u8, String) {
101+ let used = total.saturating_sub(avail);
102+ let pct = used
103+ .saturating_mul(100)
104+ .checked_div(total)
105+ .map_or(0, |p| u8::try_from(p).unwrap_or(100));
106+ let text = format!(
107+ "{} {} {}",
108+ human_size(lang, avail),
109+ at(lang, A::Free),
110+ human_size(lang, total)
111+ );
112+ (pct, text)
50 }113 }
51 114
52 /// `(total, available)` bytes from `df -Pk <path>` output.115 /// `(total, available)` bytes from `df -Pk <path>` output.
@@ -100,32 +163,7 @@ fn uptime_secs() -> Option<u64> {
100 Some((system - start_ticks / 100.0).max(0.0) as u64)163 Some((system - start_ticks / 100.0).max(0.0) as u64)
101 }164 }
102 165
103-fn disk_tile(lang: Lang, title: &'static str, space: Option<(u64, u64)>, label: &str) -> Tile {166+async fn gather(state: &AppState, lang: Lang, tz: &str) -> Result<Health> {
104- match space {
105- Some((total, avail)) => {
106- let used = total.saturating_sub(avail);
107- let pct = used
108- .saturating_mul(100)
109- .checked_div(total)
110- .map_or(0, |p| u8::try_from(p).unwrap_or(100));
111- Tile {
112- title,
113- big: human_size(lang, avail),
114- sub: format!(
115- "{} {} - {label}",
116- at(lang, A::Free),
117- human_size(lang, total)
118- ),
119- stamp: None,
120- tone: if pct >= 90 { "bad" } else { "" },
121- meter: Some(pct),
122- }
123- }
124- None => tile(title, at(lang, A::Unavailable), label),
125- }
126-}
127-
128-async fn tiles(state: &AppState, lang: Lang, tz: &str) -> Result<Vec<Tile>> {
129 let live = state.live();167 let live = state.live();
130 let now = now_unix();168 let now = now_unix();
131 let data_dir = live.data_dir.clone();169 let data_dir = live.data_dir.clone();
@@ -156,136 +194,191 @@ async fn tiles(state: &AppState, lang: Lang, tz: &str) -> Result<Vec<Tile>> {
156 let failed = mail_n(&[MailState::Failed]);194 let failed = mail_n(&[MailState::Failed]);
157 let db_bytes = std::fs::metadata(&database).map(|m| m.len()).ok();195 let db_bytes = std::fs::metadata(&database).map(|m| m.len()).ok();
158 196
159- let mut out = Vec::new();197+ let usage = data_space.map(|(total, avail)| {
160- out.push(disk_tile(198+ let (pct, free_of_total) = space(lang, total, avail);
161- lang,199+ Usage {
162- at(lang, A::DataDirectory),200+ used: human_size(lang, total.saturating_sub(avail)),
163- data_space,201+ free_of_total,
164- &data_dir.to_string_lossy(),202+ path: data_dir.to_string_lossy().into_owned(),
165- ));203+ pct,
166- out.push(if backup_on {204+ bad: pct >= 90,
167- disk_tile(205+ }
168- lang,
169- at(lang, A::BackupDirectory),
170- backup_space,
171- &backup_dir.to_string_lossy(),
172- )
173- } else {
174- tile(at(lang, A::BackupDirectory), at(lang, A::NotConfigured), "")
175 });206 });
176- out.push(tile(207+
177- at(lang, A::DatabaseFile),208+ let mut facts = vec![Fact {
178- db_bytes.map_or_else(209+ label: at(lang, A::DatabaseFile),
210+ value: db_bytes.map_or_else(
179 || at(lang, A::Unavailable).to_owned(),211 || at(lang, A::Unavailable).to_owned(),
180 |b| human_size(lang, b),212 |b| human_size(lang, b),
181 ),213 ),
182- database.to_string_lossy(),214+ detail: database.to_string_lossy().into_owned(),
183- ));215+ dot: Dot::Neutral,
184- out.push(tile(216+ }];
185- at(lang, A::Repositories),217+ facts.push(Fact {
186- counts.repos.to_string(),218+ label: at(lang, A::Repositories),
187- match repo_bytes {219+ value: counts.repos.to_string(),
188- Some(b) => format!("{}: {}", at(lang, A::RepoStorage), human_size(lang, b)),220+ detail: match repo_bytes {
221+ Some(b) => on_disk(lang, &human_size(lang, b)),
189 None => at(lang, A::Unavailable).to_owned(),222 None => at(lang, A::Unavailable).to_owned(),
190 },223 },
191- ));224+ dot: Dot::Neutral,
192- out.push(tile(225+ });
193- at(lang, A::CiQueue),226+ facts.push(if backup_on {
194- format!("{} {}", counts.queued_jobs, at(lang, A::QueuedJobs)),227+ let backup = backup_dir.to_string_lossy().into_owned();
195- format!(228+ match backup_space {
229+ Some((total, avail)) => {
230+ let (pct, text) = space(lang, total, avail);
231+ Fact {
232+ label: at(lang, A::BackupDirectory),
233+ value: text,
234+ detail: backup,
235+ dot: if pct >= 90 { Dot::Bad } else { Dot::Neutral },
236+ }
237+ }
238+ None => Fact {
239+ label: at(lang, A::BackupDirectory),
240+ value: at(lang, A::Unavailable).to_owned(),
241+ detail: backup,
242+ dot: Dot::Neutral,
243+ },
244+ }
245+ } else {
246+ Fact {
247+ label: at(lang, A::BackupDirectory),
248+ value: at(lang, A::NotConfigured).to_owned(),
249+ detail: String::new(),
250+ dot: Dot::Off,
251+ }
252+ });
253+
254+ let mut services = vec![
255+ Service {
256+ label: at(lang, A::CiQueue),
257+ dot: Dot::Neutral,
258+ value: format!("{} {}", counts.queued_jobs, at(lang, A::QueuedJobs)),
259+ detail: format!(
196 "{} / {} {}",260 "{} / {} {}",
197 counts.runners_online,261 counts.runners_online,
198 counts.runners_total,262 counts.runners_total,
199 at(lang, A::RunnersOnline)263 at(lang, A::RunnersOnline)
200 ),264 ),
201- ));265+ stamp: None,
202- let mut mail_tile = tile(266+ },
203- at(lang, A::MailQueue),267+ Service {
204- format!("{pending} {}", at(lang, A::Pending)),268+ label: at(lang, A::MailQueue),
205- format!("{failed} {}", at(lang, A::Failed)),269+ dot: if failed > 0 { Dot::Bad } else { Dot::Neutral },
206- );270+ value: format!("{pending} {}", at(lang, A::Pending)),
207- if failed > 0 {271+ detail: format!("{failed} {}", at(lang, A::Failed)),
208- mail_tile.tone = "bad";272+ stamp: None,
209- }273+ },
210- out.push(mail_tile);274+ ];
211 275
212 let backup = if backup_on {276 let backup = if backup_on {
213 state.store.last_run(RunKind::Backup).await?277 state.store.last_run(RunKind::Backup).await?
214 } else {278 } else {
215 None279 None
216 };280 };
217- out.push(match backup {281+ services.push(match backup {
218 Some(run) => {282 Some(run) => {
219 let at_unix = stamp_to_unix(&run.started_at).unwrap_or(0);283 let at_unix = stamp_to_unix(&run.started_at).unwrap_or(0);
220- let mut t = tile(284+ let (value, dot) = match run.ok {
221- at(lang, A::LastBackup),285+ Some(true) => (at(lang, A::Ok), Dot::Ok),
222- match run.ok {286+ Some(false) => (at(lang, A::Failed), Dot::Bad),
223- Some(true) => at(lang, A::Ok),287+ None => (at(lang, A::Pending), Dot::Neutral),
224- Some(false) => at(lang, A::Failed),
225- None => at(lang, A::Pending),
226- },
227- format_in_tz(at_unix, tz),
228- );
229- t.stamp = Some(run.started_at.clone());
230- t.tone = match run.ok {
231- Some(true) => "ok",
232- Some(false) => "bad",
233- None => "",
234 };288 };
235- t289+ Service {
236- }290+ label: at(lang, A::LastBackup),
237- None if backup_on => tile(at(lang, A::LastBackup), at(lang, A::Never), ""),291+ dot,
238- None => tile(at(lang, A::LastBackup), at(lang, A::NotConfigured), ""),292+ value: value.to_owned(),
293+ detail: format_in_tz(at_unix, tz),
294+ stamp: Some(run.started_at.clone()),
295+ }
296+ }
297+ None if backup_on => Service {
298+ label: at(lang, A::LastBackup),
299+ dot: Dot::Neutral,
300+ value: at(lang, A::Never).to_owned(),
301+ detail: String::new(),
302+ stamp: None,
303+ },
304+ None => Service {
305+ label: at(lang, A::LastBackup),
306+ dot: Dot::Off,
307+ value: at(lang, A::NotConfigured).to_owned(),
308+ detail: String::new(),
309+ stamp: None,
310+ },
239 });311 });
240 312
241 let replicating = !live.replication.target.trim().is_empty();313 let replicating = !live.replication.target.trim().is_empty();
242- out.push(if replicating {314+ services.push(if replicating {
243 match state.store.replication_status(DB_SUBJECT).await? {315 match state.store.replication_status(DB_SUBJECT).await? {
244 Some(status) => {316 Some(status) => {
245 let ok_unix = status.last_ok_at.as_deref().and_then(stamp_to_unix);317 let ok_unix = status.last_ok_at.as_deref().and_then(stamp_to_unix);
246 let window = live.replication.db_snapshot_minutes.saturating_mul(120);318 let window = live.replication.db_snapshot_minutes.saturating_mul(120);
247 let lagging = ok_unix.is_none_or(|t| (now - t).max(0) as u64 > window);319 let lagging = ok_unix.is_none_or(|t| (now - t).max(0) as u64 > window);
248 let errored = status.last_error.is_some();320 let errored = status.last_error.is_some();
249- let mut t = tile(321+ let (value, dot) = if errored {
250- at(lang, A::Replication),322+ (at(lang, A::Error), Dot::Bad)
251- if errored {
252- at(lang, A::Error)
253 } else if lagging {323 } else if lagging {
254- at(lang, A::Lagging)324+ (at(lang, A::Lagging), Dot::Bad)
255 } else {325 } else {
256- at(lang, A::Ok)326+ (at(lang, A::Ok), Dot::Ok)
257- },327+ };
258- if ok_unix.is_some() {328+ Service {
259- ""329+ label: at(lang, A::Replication),
330+ dot,
331+ value: value.to_owned(),
332+ detail: if ok_unix.is_some() {
333+ String::new()
260 } else {334 } else {
261- at(lang, A::Never)335+ at(lang, A::Never).to_owned()
262 },336 },
263- );337+ stamp: status.last_ok_at.clone(),
264- t.stamp = status.last_ok_at.clone();338+ }
265- t.tone = if errored || lagging { "bad" } else { "ok" };
266- t
267 }339 }
268- None => tile(at(lang, A::Replication), at(lang, A::Never), ""),340+ None => Service {
341+ label: at(lang, A::Replication),
342+ dot: Dot::Neutral,
343+ value: at(lang, A::Never).to_owned(),
344+ detail: String::new(),
345+ stamp: None,
346+ },
269 }347 }
270 } else {348 } else {
271- tile(at(lang, A::Replication), at(lang, A::NotConfigured), "")349+ Service {
350+ label: at(lang, A::Replication),
351+ dot: Dot::Off,
352+ value: at(lang, A::NotConfigured).to_owned(),
353+ detail: String::new(),
354+ stamp: None,
355+ }
272 });356 });
273- out.push(tile(357+
274- at(lang, A::Uptime),358+ let uptime = uptime_secs().map_or_else(|| at(lang, A::Unavailable).to_owned(), duration_short);
275- uptime_secs().map_or_else(|| at(lang, A::Unavailable).to_owned(), duration_short),359+ let build = format!(
276- "",360+ "{}{}",
277- ));
278- out.push(tile(
279- at(lang, A::Version),
280- forge_ci::build::VERSION,
281- format!(
282- "{}{}, {}",
283 forge_ci::build::COMMIT,361 forge_ci::build::COMMIT,
284- if forge_ci::build::DIRTY { "-dirty" } else { "" },362+ if forge_ci::build::DIRTY { "-dirty" } else { "" }
285- forge_ci::build::DATE363+ );
286- ),364+ let meta = meta_line(
287- ));365+ lang,
288- Ok(out)366+ &uptime,
367+ forge_ci::build::VERSION,
368+ &build,
369+ forge_ci::build::DATE,
370+ );
371+
372+ let attention = usize::from(usage.as_ref().is_some_and(|u| u.bad))
373+ + facts.iter().filter(|f| f.dot == Dot::Bad).count()
374+ + services.iter().filter(|s| s.dot == Dot::Bad).count();
375+ Ok(Health {
376+ usage,
377+ facts,
378+ services,
379+ meta,
380+ attention,
381+ })
289 }382 }
290 383
291 /// One active alert in the banner.384 /// One active alert in the banner.
@@ -330,13 +423,30 @@ async fn since_line(lang: Lang, date: &str, stamp: &str) -> Result<impl View> {
330 }423 }
331 424
332 #[component]425 #[component]
333-async fn health_view(lang: Lang, tiles: Vec<Tile>, alerts: Vec<AlertRow>) -> Result<impl View> {426+async fn health_view(lang: Lang, health: Health, alerts: Vec<AlertRow>) -> Result<impl View> {
334 let count = alerts.len();427 let count = alerts.len();
428+ let Health {
429+ usage,
430+ facts,
431+ services,
432+ meta,
433+ attention,
434+ } = health;
435+ let summary_dot = if attention > 0 { Dot::Bad } else { Dot::Ok };
436+ let summary = if attention > 0 {
437+ needs_attention(lang, attention)
438+ } else {
439+ at(lang, A::Fine).to_owned()
440+ };
335 Ok(view! {441 Ok(view! {
336 <div data-live="/admin/health/events">442 <div data-live="/admin/health/events">
337 <section class="page-head">443 <section class="page-head">
338 <h1>(at(lang, A::Health))</h1>444 <h1>(at(lang, A::Health))</h1>
339- <p class="muted">(at(lang, A::HealthIntro))</p>445+ <p class="health-summary">
446+ <span class=(format!("health-dot {}", summary_dot.class()))></span>
447+ (summary)
448+ </p>
449+ <p class="muted small">(at(lang, A::HealthIntro))</p>
340 </section>450 </section>
341 if count > 0 {451 if count > 0 {
342 <section class="admin-alerts" role="alert">452 <section class="admin-alerts" role="alert">
@@ -355,28 +465,56 @@ async fn health_view(lang: Lang, tiles: Vec<Tile>, alerts: Vec<AlertRow>) -> Res
355 <a class="small" href="/admin/server?tab=alerts">(alert_text::settings_link(lang))</a>465 <a class="small" href="/admin/server?tab=alerts">(alert_text::settings_link(lang))</a>
356 </section>466 </section>
357 }467 }
358- <div class="health-grid">468+ <section class="card health-storage">
359- for t in tiles.into_iter() {469+ <h2>(at(lang, A::Storage))</h2>
360- <section class=(format!("tile {}", t.tone))>470+ if let Some(u) = usage {
361- <h2>(t.title)</h2>471+ <div class="health-usage-head">
362- <div class="big">(t.big.as_str())</div>472+ <span><strong>(u.used.as_str())</strong> " " (at(lang, A::DiskUsed))</span>
363- if !t.sub.is_empty() || t.stamp.is_some() {473+ <span class="muted">(u.free_of_total.as_str())</span>
364- <div class="sub">474+ </div>
365- (t.sub.as_str())475+ <progress class=(if u.bad { "meter bad" } else { "meter" }) max="100" value=(u.pct.to_string())></progress>
366- if let Some(stamp) = t.stamp.as_deref() {476+ <div class="muted small health-path">(u.path.as_str())</div>
367- if !t.sub.is_empty() {477+ } else {
478+ <p class="muted">(at(lang, A::Unavailable))</p>
479+ }
480+ <div class="health-facts">
481+ for f in facts.into_iter() {
482+ <div class="health-fact">
483+ <div class="muted small">(f.label)</div>
484+ <div class=(format!("health-fact-value {}", f.dot.value_class()))>(f.value.as_str())</div>
485+ if !f.detail.is_empty() {
486+ <div class="muted small health-path">(f.detail.as_str())</div>
487+ }
488+ </div>
489+ }
490+ </div>
491+ </section>
492+ <section class="card health-status">
493+ <h2>(at(lang, A::Services))</h2>
494+ <ul class="health-rows">
495+ for s in services.into_iter() {
496+ <li class="health-row">
497+ <span class=(format!("health-dot {}", s.dot.class()))></span>
498+ <div class="health-row-text">
499+ <div>(s.label)</div>
500+ if !s.detail.is_empty() || s.stamp.is_some() {
501+ <div class="muted small">
502+ (s.detail.as_str())
503+ if let Some(stamp) = s.stamp.as_deref() {
504+ if !s.detail.is_empty() {
368 " · "505 " · "
369 }506 }
370 rel_time(lang: lang, stamp: stamp)507 rel_time(lang: lang, stamp: stamp)
371 }508 }
372 </div>509 </div>
373 }510 }
374- if let Some(pct) = t.meter {511+ </div>
375- <progress class="meter" max="100" value=(pct.to_string())></progress>512+ <div class=(format!("health-row-value {}", s.dot.value_class()))>(s.value.as_str())</div>
513+ </li>
376 }514 }
515+ </ul>
377 </section>516 </section>
378- }517+ <p class="muted small health-meta">(meta.as_str())</p>
379- </div>
380 </div>518 </div>
381 })519 })
382 }520 }
@@ -386,11 +524,11 @@ async fn health_page(cx: &Cx) -> Result<impl View> {
386 let viewer = admin_only(cx).await?;524 let viewer = admin_only(cx).await?;
387 let lang = i18n::lang(cx, Some(&viewer.0));525 let lang = i18n::lang(cx, Some(&viewer.0));
388 let state = app_context::<AppState>(cx);526 let state = app_context::<AppState>(cx);
389- let tiles = tiles(state, lang, &viewer.0.timezone).await?;527+ let health = gather(state, lang, &viewer.0.timezone).await?;
390 let alerts = alert_rows(state, lang, &viewer.0.timezone).await?;528 let alerts = alert_rows(state, lang, &viewer.0.timezone).await?;
391 let title = at(lang, A::Health);529 let title = at(lang, A::Health);
392 Ok(view! {530 Ok(view! {
393- shell(title: title, viewer: Some(&viewer), health_view(lang: lang, tiles: tiles, alerts: alerts))531+ shell(title: title, viewer: Some(&viewer), health_view(lang: lang, health: health, alerts: alerts))
394 })532 })
395 }533 }
396 534
crates/forge-web/src/views/mod.rsmodified+8 -1
@@ -1076,8 +1076,15 @@ pub fn human_size(lang: Lang, bytes: u64) -> String {
1076 }1076 }
1077 } else if bytes < 1024 * 1024 {1077 } else if bytes < 1024 * 1024 {
1078 format!("{} KiB", decimal(bytes as f64 / 1024.0))1078 format!("{} KiB", decimal(bytes as f64 / 1024.0))
1079- } else {1079+ } else if bytes < 1024 * 1024 * 1024 {
1080 format!("{} MiB", decimal(bytes as f64 / (1024.0 * 1024.0)))1080 format!("{} MiB", decimal(bytes as f64 / (1024.0 * 1024.0)))
1081+ } else if bytes < 1024 * 1024 * 1024 * 1024 {
1082+ format!("{} GiB", decimal(bytes as f64 / (1024.0 * 1024.0 * 1024.0)))
1083+ } else {
1084+ format!(
1085+ "{} TiB",
1086+ decimal(bytes as f64 / (1024.0 * 1024.0 * 1024.0 * 1024.0))
1087+ )
1081 }1088 }
1082 }1089 }
1083 1090
style/_account_admin.scssmodified+117 -36
@@ -1,4 +1,4 @@
1-// Site banner, admin user detail and the health grid.1+// Site banner, admin user detail and the health page.
2 2
3 .site-banner {3 .site-banner {
4 display: flex;4 display: flex;
@@ -95,49 +95,65 @@
95 user-select: all;95 user-select: all;
96 }96 }
97 97
98-.health-grid {98+.health-summary {
99- display: grid;99+ display: flex;
100- grid-template-columns: repeat(auto-fit, minmax(min(100%, 165px), 1fr));100+ align-items: center;
101- gap: 12px;101+ gap: 8px;
102- margin-bottom: 16px;102+ margin: 0 0 4px;
103+ font-weight: 500;
104+}
103 105
104- .tile {106+// A status dot: the summary's, and each service row's.
105- background: var(--surface);107+.health-dot {
106- border: 1px solid var(--border);108+ display: inline-block;
107- border-radius: var(--radius-lg);109+ flex: none;
108- padding: 14px 16px;110+ width: 8px;
109- min-width: 0;111+ height: 8px;
112+ border-radius: var(--radius-full);
113+ background: var(--muted);
110 114
111- h2 {115+ &.ok {
112- margin: 0 0 8px;116+ background: var(--ok);
113- font-size: 0.8125rem;
114- font-weight: 600;
115- color: var(--muted);
116- text-transform: none;
117 }117 }
118 118
119- .big {119+ &.bad {
120- font-size: 1.5rem;120+ background: var(--bad);
121- font-weight: 600;
122- line-height: 1.2;
123- overflow-wrap: anywhere;
124 }121 }
125 122
126- .sub {123+ &.off {
127- color: var(--muted);124+ box-sizing: border-box;
128- font-size: 0.8125rem;125+ background: transparent;
129- margin-top: 4px;126+ border: 1.5px solid var(--border-strong);
130- overflow-wrap: anywhere;
131 }127 }
128+}
129+
130+.health-storage,
131+.health-status {
132+ margin-bottom: 16px;
132 133
133- .meter {134+ h2 {
135+ margin: 0 0 12px;
136+ font-size: 0.9375rem;
137+ }
138+}
139+
140+.health-usage-head {
141+ display: flex;
142+ flex-wrap: wrap;
143+ justify-content: space-between;
144+ align-items: baseline;
145+ gap: 4px 16px;
146+ margin-bottom: 8px;
147+}
148+
149+// The data directory's usage bar: 8px tall, the fill turns red at 90%.
150+.health-storage .meter {
134 display: block;151 display: block;
135 width: 100%;152 width: 100%;
136- height: 6px;153+ height: 8px;
137- margin-top: 8px;
138 appearance: none;154 appearance: none;
139 border: 0;155 border: 0;
140- border-radius: var(--radius-full);156+ border-radius: 4px;
141 background: var(--surface-2);157 background: var(--surface-2);
142 overflow: hidden;158 overflow: hidden;
143 159
@@ -152,16 +168,81 @@
152 &::-moz-progress-bar {168 &::-moz-progress-bar {
153 background: var(--accent);169 background: var(--accent);
154 }170 }
171+
172+ &.bad::-webkit-progress-value {
173+ background: var(--bad);
155 }174 }
156 175
157- &.bad .big {176+ &.bad::-moz-progress-bar {
177+ background: var(--bad);
178+ }
179+}
180+
181+.health-path {
182+ margin-top: 4px;
183+ overflow-wrap: anywhere;
184+}
185+
186+.health-facts {
187+ display: grid;
188+ grid-template-columns: repeat(3, minmax(0, 1fr));
189+ gap: 16px;
190+ margin-top: 16px;
191+
192+ @media (max-width: 640px) {
193+ grid-template-columns: minmax(0, 1fr);
194+ }
195+}
196+
197+.health-fact-value {
198+ margin-top: 2px;
199+ font-size: 0.9375rem;
200+ font-weight: 600;
201+ overflow-wrap: anywhere;
202+
203+ &.bad {
158 color: var(--bad);204 color: var(--bad);
159 }205 }
160 206
161- &.ok .big {207+ &.muted {
162- color: var(--ok);208+ font-weight: 400;
209+ }
210+}
211+
212+.health-rows {
213+ list-style: none;
214+ margin: 0;
215+ padding: 0;
163 }216 }
217+
218+.health-row {
219+ display: grid;
220+ grid-template-columns: 16px minmax(0, 1fr) auto;
221+ align-items: center;
222+ gap: 8px;
223+ padding: 10px 0;
224+
225+ & + .health-row {
226+ border-top: 1px solid var(--border);
164 }227 }
228+
229+ .health-dot {
230+ justify-self: center;
231+ }
232+}
233+
234+.health-row-value {
235+ text-align: right;
236+ font-variant-numeric: tabular-nums;
237+ overflow-wrap: anywhere;
238+
239+ &.muted {
240+ color: var(--muted);
241+ }
242+}
243+
244+.health-meta {
245+ margin: 0 0 16px;
165 }246 }
166 247
167 .link-row {248 .link-row {
@@ -171,7 +252,7 @@
171 margin: 16px 0 0;252 margin: 16px 0 0;
172 }253 }
173 254
174-// Active admin alerts, above the health tiles.255+// Active admin alerts, above the health cards.
175 .admin-alerts {256 .admin-alerts {
176 background: var(--danger-bg);257 background: var(--danger-bg);
177 border: 1px solid var(--danger);258 border: 1px solid var(--danger);