Health page has a status line, a storage card in GiB and a quiet services list instead of equal tiles
Browse files at this commit9d4e224b6ddf4142cf8009b3f969977ed0ed185aParent: 12e6ee0- style
- health page has a status line, a storage card in GiB and a quiet services list instead of equal tiles
4 changed files +498 -247
- crates/forge-web/src/i18n/accounts.rs +40 -15
- crates/forge-web/src/pages/admin_health.rs +309 -171
- crates/forge-web/src/views/mod.rs +8 -1
- style/_account_admin.scss +141 -60
crates/forge-web/src/i18n/accounts.rsmodified+40 -15
| @@ -37,10 +37,8 @@ pub enum A { | ||
| 37 | 37 | AccountSuspended, |
| 38 | 38 | Dismiss, |
| 39 | 39 | Health, |
| 40 | - DataDirectory, | |
| 41 | 40 | BackupDirectory, |
| 42 | 41 | DatabaseFile, |
| 43 | - RepoStorage, | |
| 44 | 42 | Free, |
| 45 | 43 | CiQueue, |
| 46 | 44 | QueuedJobs, |
| @@ -50,8 +48,6 @@ pub enum A { | ||
| 50 | 48 | Failed, |
| 51 | 49 | LastBackup, |
| 52 | 50 | Replication, |
| 53 | - Uptime, | |
| 54 | - Version, | |
| 55 | 51 | NotConfigured, |
| 56 | 52 | Unavailable, |
| 57 | 53 | Never, |
| @@ -59,6 +55,10 @@ pub enum A { | ||
| 59 | 55 | Error, |
| 60 | 56 | Lagging, |
| 61 | 57 | HealthIntro, |
| 58 | + Storage, | |
| 59 | + Services, | |
| 60 | + Fine, | |
| 61 | + DiskUsed, | |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | pub fn t(lang: Lang, key: A) -> &'static str { |
| @@ -141,20 +141,16 @@ pub fn t(lang: Lang, key: A) -> &'static str { | ||
| 141 | 141 | (Dismiss, Tr) => "Kapat", |
| 142 | 142 | (Health, En) => "Health", |
| 143 | 143 | (Health, Tr) => "Sağlık", |
| 144 | - (DataDirectory, En) => "Data directory", | |
| 145 | - (DataDirectory, Tr) => "Veri dizini", | |
| 146 | 144 | (BackupDirectory, En) => "Backup directory", |
| 147 | 145 | (BackupDirectory, Tr) => "Yedek dizini", |
| 148 | 146 | (DatabaseFile, En) => "Database file", |
| 149 | 147 | (DatabaseFile, Tr) => "Veritabanı dosyası", |
| 150 | - (RepoStorage, En) => "Repositories on disk", | |
| 151 | - (RepoStorage, Tr) => "Diskteki depolar", | |
| 152 | 148 | (Free, En) => "free of", |
| 153 | 149 | (Free, Tr) => "boş, toplam", |
| 154 | 150 | (CiQueue, En) => "CI queue", |
| 155 | 151 | (CiQueue, Tr) => "CI kuyruğu", |
| 156 | - (QueuedJobs, En) => "queued jobs", | |
| 157 | - (QueuedJobs, Tr) => "bekleyen iş", | |
| 152 | + (QueuedJobs, En) => "queued", | |
| 153 | + (QueuedJobs, Tr) => "bekleyen", | |
| 158 | 154 | (RunnersOnline, En) => "runners online", |
| 159 | 155 | (RunnersOnline, Tr) => "çalıştırıcı çevrim içi", |
| 160 | 156 | (MailQueue, En) => "Mail queue", |
| @@ -167,10 +163,6 @@ pub fn t(lang: Lang, key: A) -> &'static str { | ||
| 167 | 163 | (LastBackup, Tr) => "Son yedek", |
| 168 | 164 | (Replication, En) => "Replication", |
| 169 | 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 | 166 | (NotConfigured, En) => "Not configured", |
| 175 | 167 | (NotConfigured, Tr) => "Ayarlanmamış", |
| 176 | 168 | (Unavailable, En) => "Unavailable", |
| @@ -185,6 +177,14 @@ pub fn t(lang: Lang, key: A) -> &'static str { | ||
| 185 | 177 | (Lagging, Tr) => "Geride", |
| 186 | 178 | (HealthIntro, En) => "Read when the page loads. Reload the page for fresh numbers.", |
| 187 | 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 | 230 | pub fn duration_short(secs: u64) -> String { |
| 206 | 231 | let (d, h, m) = (secs / 86_400, secs % 86_400 / 3_600, secs % 3_600 / 60); |
| 207 | 232 | if d > 0 { |
crates/forge-web/src/pages/admin_health.rsmodified+309 -171
| @@ -1,6 +1,7 @@ | ||
| 1 | -//! Page: instance health for admins (`/admin/health`). A compact grid of tiles, read when the page | |
| 2 | -//! loads. Every number is a cheap query or a short external probe (`df`, `du`), so there is no | |
| 3 | -//! polling; reloading the page, or opening it again, reads fresh values. Non-admins get 404. | |
| 1 | +//! Page: instance health for admins (`/admin/health`). A summary line, a storage card with the data | |
| 2 | +//! disk's usage bar, and a services card. Every number is a cheap query or a short external probe | |
| 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 | 6 | use std::path::Path; |
| 6 | 7 | use std::time::Duration; |
| @@ -17,7 +18,7 @@ use topcoat::router::response::Response; | ||
| 17 | 18 | use topcoat::router::{page, route}; |
| 18 | 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 | 22 | use crate::i18n::alerts as alert_text; |
| 22 | 23 | use crate::i18n::{self, Lang}; |
| 23 | 24 | use crate::live::{Topic, stream_changes}; |
| @@ -25,30 +26,92 @@ use crate::pages::admin_users::admin_only; | ||
| 25 | 26 | use crate::state::AppState; |
| 26 | 27 | use crate::views::{human_size, now_unix, rel_time, shell}; |
| 27 | 28 | |
| 28 | -/// One cell of the grid. | |
| 29 | -struct Tile { | |
| 30 | - title: &'static str, | |
| 31 | - big: String, | |
| 32 | - sub: String, | |
| 33 | - /// A stamp shown after `sub` as a live relative time. | |
| 34 | - 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>, | |
| 29 | +/// How a dot or a value is drawn: a bad outcome, a good one, a plain count, or a feature that is | |
| 30 | +/// not set up. | |
| 31 | +#[derive(Clone, Copy, PartialEq, Eq)] | |
| 32 | +enum Dot { | |
| 33 | + Ok, | |
| 34 | + Bad, | |
| 35 | + Neutral, | |
| 36 | + /// Not configured: a hollow dot, and a muted value. | |
| 37 | + Off, | |
| 39 | 38 | } |
| 40 | 39 | |
| 41 | -fn tile(title: &'static str, big: impl Into<String>, sub: impl Into<String>) -> Tile { | |
| 42 | - Tile { | |
| 43 | - title, | |
| 44 | - big: big.into(), | |
| 45 | - sub: sub.into(), | |
| 46 | - stamp: None, | |
| 47 | - tone: "", | |
| 48 | - meter: None, | |
| 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 | + } | |
| 49 | 57 | } |
| 50 | 58 | } |
| 51 | 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. | |
| 87 | + stamp: Option<String>, | |
| 88 | +} | |
| 89 | + | |
| 90 | +/// Everything the page shows, and how many items need attention. | |
| 91 | +struct Health { | |
| 92 | + usage: Option<Usage>, | |
| 93 | + facts: Vec<Fact>, | |
| 94 | + services: Vec<Service>, | |
| 95 | + meta: String, | |
| 96 | + attention: usize, | |
| 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) | |
| 113 | +} | |
| 114 | + | |
| 52 | 115 | /// `(total, available)` bytes from `df -Pk <path>` output. |
| 53 | 116 | fn parse_df(output: &str) -> Option<(u64, u64)> { |
| 54 | 117 | let line = output.lines().nth(1)?; |
| @@ -100,32 +163,7 @@ fn uptime_secs() -> Option<u64> { | ||
| 100 | 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 { | |
| 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>> { | |
| 166 | +async fn gather(state: &AppState, lang: Lang, tz: &str) -> Result<Health> { | |
| 129 | 167 | let live = state.live(); |
| 130 | 168 | let now = now_unix(); |
| 131 | 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 | 194 | let failed = mail_n(&[MailState::Failed]); |
| 157 | 195 | let db_bytes = std::fs::metadata(&database).map(|m| m.len()).ok(); |
| 158 | 196 | |
| 159 | - let mut out = Vec::new(); | |
| 160 | - out.push(disk_tile( | |
| 161 | - lang, | |
| 162 | - at(lang, A::DataDirectory), | |
| 163 | - data_space, | |
| 164 | - &data_dir.to_string_lossy(), | |
| 165 | - )); | |
| 166 | - out.push(if backup_on { | |
| 167 | - disk_tile( | |
| 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), "") | |
| 197 | + let usage = data_space.map(|(total, avail)| { | |
| 198 | + let (pct, free_of_total) = space(lang, total, avail); | |
| 199 | + Usage { | |
| 200 | + used: human_size(lang, total.saturating_sub(avail)), | |
| 201 | + free_of_total, | |
| 202 | + path: data_dir.to_string_lossy().into_owned(), | |
| 203 | + pct, | |
| 204 | + bad: pct >= 90, | |
| 205 | + } | |
| 175 | 206 | }); |
| 176 | - out.push(tile( | |
| 177 | - at(lang, A::DatabaseFile), | |
| 178 | - db_bytes.map_or_else( | |
| 207 | + | |
| 208 | + let mut facts = vec![Fact { | |
| 209 | + label: at(lang, A::DatabaseFile), | |
| 210 | + value: db_bytes.map_or_else( | |
| 179 | 211 | || at(lang, A::Unavailable).to_owned(), |
| 180 | 212 | |b| human_size(lang, b), |
| 181 | 213 | ), |
| 182 | - database.to_string_lossy(), | |
| 183 | - )); | |
| 184 | - out.push(tile( | |
| 185 | - at(lang, A::Repositories), | |
| 186 | - counts.repos.to_string(), | |
| 187 | - match repo_bytes { | |
| 188 | - Some(b) => format!("{}: {}", at(lang, A::RepoStorage), human_size(lang, b)), | |
| 214 | + detail: database.to_string_lossy().into_owned(), | |
| 215 | + dot: Dot::Neutral, | |
| 216 | + }]; | |
| 217 | + facts.push(Fact { | |
| 218 | + label: at(lang, A::Repositories), | |
| 219 | + value: counts.repos.to_string(), | |
| 220 | + detail: match repo_bytes { | |
| 221 | + Some(b) => on_disk(lang, &human_size(lang, b)), | |
| 189 | 222 | None => at(lang, A::Unavailable).to_owned(), |
| 190 | 223 | }, |
| 191 | - )); | |
| 192 | - out.push(tile( | |
| 193 | - at(lang, A::CiQueue), | |
| 194 | - format!("{} {}", counts.queued_jobs, at(lang, A::QueuedJobs)), | |
| 195 | - format!( | |
| 196 | - "{} / {} {}", | |
| 197 | - counts.runners_online, | |
| 198 | - counts.runners_total, | |
| 199 | - at(lang, A::RunnersOnline) | |
| 200 | - ), | |
| 201 | - )); | |
| 202 | - let mut mail_tile = tile( | |
| 203 | - at(lang, A::MailQueue), | |
| 204 | - format!("{pending} {}", at(lang, A::Pending)), | |
| 205 | - format!("{failed} {}", at(lang, A::Failed)), | |
| 206 | - ); | |
| 207 | - if failed > 0 { | |
| 208 | - mail_tile.tone = "bad"; | |
| 209 | - } | |
| 210 | - out.push(mail_tile); | |
| 224 | + dot: Dot::Neutral, | |
| 225 | + }); | |
| 226 | + facts.push(if backup_on { | |
| 227 | + let backup = backup_dir.to_string_lossy().into_owned(); | |
| 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!( | |
| 260 | + "{} / {} {}", | |
| 261 | + counts.runners_online, | |
| 262 | + counts.runners_total, | |
| 263 | + at(lang, A::RunnersOnline) | |
| 264 | + ), | |
| 265 | + stamp: None, | |
| 266 | + }, | |
| 267 | + Service { | |
| 268 | + label: at(lang, A::MailQueue), | |
| 269 | + dot: if failed > 0 { Dot::Bad } else { Dot::Neutral }, | |
| 270 | + value: format!("{pending} {}", at(lang, A::Pending)), | |
| 271 | + detail: format!("{failed} {}", at(lang, A::Failed)), | |
| 272 | + stamp: None, | |
| 273 | + }, | |
| 274 | + ]; | |
| 211 | 275 | |
| 212 | 276 | let backup = if backup_on { |
| 213 | 277 | state.store.last_run(RunKind::Backup).await? |
| 214 | 278 | } else { |
| 215 | 279 | None |
| 216 | 280 | }; |
| 217 | - out.push(match backup { | |
| 281 | + services.push(match backup { | |
| 218 | 282 | Some(run) => { |
| 219 | 283 | let at_unix = stamp_to_unix(&run.started_at).unwrap_or(0); |
| 220 | - let mut t = tile( | |
| 221 | - at(lang, A::LastBackup), | |
| 222 | - match run.ok { | |
| 223 | - Some(true) => at(lang, A::Ok), | |
| 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 => "", | |
| 284 | + let (value, dot) = match run.ok { | |
| 285 | + Some(true) => (at(lang, A::Ok), Dot::Ok), | |
| 286 | + Some(false) => (at(lang, A::Failed), Dot::Bad), | |
| 287 | + None => (at(lang, A::Pending), Dot::Neutral), | |
| 234 | 288 | }; |
| 235 | - t | |
| 289 | + Service { | |
| 290 | + label: at(lang, A::LastBackup), | |
| 291 | + dot, | |
| 292 | + value: value.to_owned(), | |
| 293 | + detail: format_in_tz(at_unix, tz), | |
| 294 | + stamp: Some(run.started_at.clone()), | |
| 295 | + } | |
| 236 | 296 | } |
| 237 | - None if backup_on => tile(at(lang, A::LastBackup), at(lang, A::Never), ""), | |
| 238 | - None => tile(at(lang, A::LastBackup), at(lang, A::NotConfigured), ""), | |
| 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 | 313 | let replicating = !live.replication.target.trim().is_empty(); |
| 242 | - out.push(if replicating { | |
| 314 | + services.push(if replicating { | |
| 243 | 315 | match state.store.replication_status(DB_SUBJECT).await? { |
| 244 | 316 | Some(status) => { |
| 245 | 317 | let ok_unix = status.last_ok_at.as_deref().and_then(stamp_to_unix); |
| 246 | 318 | let window = live.replication.db_snapshot_minutes.saturating_mul(120); |
| 247 | 319 | let lagging = ok_unix.is_none_or(|t| (now - t).max(0) as u64 > window); |
| 248 | 320 | let errored = status.last_error.is_some(); |
| 249 | - let mut t = tile( | |
| 250 | - at(lang, A::Replication), | |
| 251 | - if errored { | |
| 252 | - at(lang, A::Error) | |
| 253 | - } else if lagging { | |
| 254 | - at(lang, A::Lagging) | |
| 255 | - } else { | |
| 256 | - at(lang, A::Ok) | |
| 257 | - }, | |
| 258 | - if ok_unix.is_some() { | |
| 259 | - "" | |
| 321 | + let (value, dot) = if errored { | |
| 322 | + (at(lang, A::Error), Dot::Bad) | |
| 323 | + } else if lagging { | |
| 324 | + (at(lang, A::Lagging), Dot::Bad) | |
| 325 | + } else { | |
| 326 | + (at(lang, A::Ok), Dot::Ok) | |
| 327 | + }; | |
| 328 | + Service { | |
| 329 | + label: at(lang, A::Replication), | |
| 330 | + dot, | |
| 331 | + value: value.to_owned(), | |
| 332 | + detail: if ok_unix.is_some() { | |
| 333 | + String::new() | |
| 260 | 334 | } else { |
| 261 | - at(lang, A::Never) | |
| 335 | + at(lang, A::Never).to_owned() | |
| 262 | 336 | }, |
| 263 | - ); | |
| 264 | - t.stamp = status.last_ok_at.clone(); | |
| 265 | - t.tone = if errored || lagging { "bad" } else { "ok" }; | |
| 266 | - t | |
| 337 | + stamp: status.last_ok_at.clone(), | |
| 338 | + } | |
| 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 | 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( | |
| 274 | - at(lang, A::Uptime), | |
| 275 | - uptime_secs().map_or_else(|| at(lang, A::Unavailable).to_owned(), duration_short), | |
| 276 | - "", | |
| 277 | - )); | |
| 278 | - out.push(tile( | |
| 279 | - at(lang, A::Version), | |
| 357 | + | |
| 358 | + let uptime = uptime_secs().map_or_else(|| at(lang, A::Unavailable).to_owned(), duration_short); | |
| 359 | + let build = format!( | |
| 360 | + "{}{}", | |
| 361 | + forge_ci::build::COMMIT, | |
| 362 | + if forge_ci::build::DIRTY { "-dirty" } else { "" } | |
| 363 | + ); | |
| 364 | + let meta = meta_line( | |
| 365 | + lang, | |
| 366 | + &uptime, | |
| 280 | 367 | forge_ci::build::VERSION, |
| 281 | - format!( | |
| 282 | - "{}{}, {}", | |
| 283 | - forge_ci::build::COMMIT, | |
| 284 | - if forge_ci::build::DIRTY { "-dirty" } else { "" }, | |
| 285 | - forge_ci::build::DATE | |
| 286 | - ), | |
| 287 | - )); | |
| 288 | - Ok(out) | |
| 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 | 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 | 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 | 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 | 441 | Ok(view! { |
| 336 | 442 | <div data-live="/admin/health/events"> |
| 337 | 443 | <section class="page-head"> |
| 338 | 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 | 450 | </section> |
| 341 | 451 | if count > 0 { |
| 342 | 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 | 465 | <a class="small" href="/admin/server?tab=alerts">(alert_text::settings_link(lang))</a> |
| 356 | 466 | </section> |
| 357 | 467 | } |
| 358 | - <div class="health-grid"> | |
| 359 | - for t in tiles.into_iter() { | |
| 360 | - <section class=(format!("tile {}", t.tone))> | |
| 361 | - <h2>(t.title)</h2> | |
| 362 | - <div class="big">(t.big.as_str())</div> | |
| 363 | - if !t.sub.is_empty() || t.stamp.is_some() { | |
| 364 | - <div class="sub"> | |
| 365 | - (t.sub.as_str()) | |
| 366 | - if let Some(stamp) = t.stamp.as_deref() { | |
| 367 | - if !t.sub.is_empty() { | |
| 368 | - " · " | |
| 369 | - } | |
| 370 | - rel_time(lang: lang, stamp: stamp) | |
| 468 | + <section class="card health-storage"> | |
| 469 | + <h2>(at(lang, A::Storage))</h2> | |
| 470 | + if let Some(u) = usage { | |
| 471 | + <div class="health-usage-head"> | |
| 472 | + <span><strong>(u.used.as_str())</strong> " " (at(lang, A::DiskUsed))</span> | |
| 473 | + <span class="muted">(u.free_of_total.as_str())</span> | |
| 474 | + </div> | |
| 475 | + <progress class=(if u.bad { "meter bad" } else { "meter" }) max="100" value=(u.pct.to_string())></progress> | |
| 476 | + <div class="muted small health-path">(u.path.as_str())</div> | |
| 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() { | |
| 505 | + " · " | |
| 506 | + } | |
| 507 | + rel_time(lang: lang, stamp: stamp) | |
| 508 | + } | |
| 509 | + </div> | |
| 371 | 510 | } |
| 372 | 511 | </div> |
| 373 | - } | |
| 374 | - if let Some(pct) = t.meter { | |
| 375 | - <progress class="meter" max="100" value=(pct.to_string())></progress> | |
| 376 | - } | |
| 377 | - </section> | |
| 378 | - } | |
| 379 | - </div> | |
| 512 | + <div class=(format!("health-row-value {}", s.dot.value_class()))>(s.value.as_str())</div> | |
| 513 | + </li> | |
| 514 | + } | |
| 515 | + </ul> | |
| 516 | + </section> | |
| 517 | + <p class="muted small health-meta">(meta.as_str())</p> | |
| 380 | 518 | </div> |
| 381 | 519 | }) |
| 382 | 520 | } |
| @@ -386,11 +524,11 @@ async fn health_page(cx: &Cx) -> Result<impl View> { | ||
| 386 | 524 | let viewer = admin_only(cx).await?; |
| 387 | 525 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 388 | 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 | 528 | let alerts = alert_rows(state, lang, &viewer.0.timezone).await?; |
| 391 | 529 | let title = at(lang, A::Health); |
| 392 | 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 | 1077 | } else if bytes < 1024 * 1024 { |
| 1078 | 1078 | format!("{} KiB", decimal(bytes as f64 / 1024.0)) |
| 1079 | - } else { | |
| 1079 | + } else if bytes < 1024 * 1024 * 1024 { | |
| 1080 | 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+141 -60
| @@ -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 | 3 | .site-banner { |
| 4 | 4 | display: flex; |
| @@ -95,75 +95,156 @@ | ||
| 95 | 95 | user-select: all; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | -.health-grid { | |
| 99 | - display: grid; | |
| 100 | - grid-template-columns: repeat(auto-fit, minmax(min(100%, 165px), 1fr)); | |
| 101 | - gap: 12px; | |
| 98 | +.health-summary { | |
| 99 | + display: flex; | |
| 100 | + align-items: center; | |
| 101 | + gap: 8px; | |
| 102 | + margin: 0 0 4px; | |
| 103 | + font-weight: 500; | |
| 104 | +} | |
| 105 | + | |
| 106 | +// A status dot: the summary's, and each service row's. | |
| 107 | +.health-dot { | |
| 108 | + display: inline-block; | |
| 109 | + flex: none; | |
| 110 | + width: 8px; | |
| 111 | + height: 8px; | |
| 112 | + border-radius: var(--radius-full); | |
| 113 | + background: var(--muted); | |
| 114 | + | |
| 115 | + &.ok { | |
| 116 | + background: var(--ok); | |
| 117 | + } | |
| 118 | + | |
| 119 | + &.bad { | |
| 120 | + background: var(--bad); | |
| 121 | + } | |
| 122 | + | |
| 123 | + &.off { | |
| 124 | + box-sizing: border-box; | |
| 125 | + background: transparent; | |
| 126 | + border: 1.5px solid var(--border-strong); | |
| 127 | + } | |
| 128 | +} | |
| 129 | + | |
| 130 | +.health-storage, | |
| 131 | +.health-status { | |
| 102 | 132 | margin-bottom: 16px; |
| 103 | 133 | |
| 104 | - .tile { | |
| 105 | - background: var(--surface); | |
| 106 | - border: 1px solid var(--border); | |
| 107 | - border-radius: var(--radius-lg); | |
| 108 | - padding: 14px 16px; | |
| 109 | - min-width: 0; | |
| 134 | + h2 { | |
| 135 | + margin: 0 0 12px; | |
| 136 | + font-size: 0.9375rem; | |
| 137 | + } | |
| 138 | +} | |
| 110 | 139 | |
| 111 | - h2 { | |
| 112 | - margin: 0 0 8px; | |
| 113 | - font-size: 0.8125rem; | |
| 114 | - font-weight: 600; | |
| 115 | - color: var(--muted); | |
| 116 | - text-transform: none; | |
| 117 | - } | |
| 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 | +} | |
| 118 | 148 | |
| 119 | - .big { | |
| 120 | - font-size: 1.5rem; | |
| 121 | - font-weight: 600; | |
| 122 | - line-height: 1.2; | |
| 123 | - overflow-wrap: anywhere; | |
| 124 | - } | |
| 149 | +// The data directory's usage bar: 8px tall, the fill turns red at 90%. | |
| 150 | +.health-storage .meter { | |
| 151 | + display: block; | |
| 152 | + width: 100%; | |
| 153 | + height: 8px; | |
| 154 | + appearance: none; | |
| 155 | + border: 0; | |
| 156 | + border-radius: 4px; | |
| 157 | + background: var(--surface-2); | |
| 158 | + overflow: hidden; | |
| 125 | 159 | |
| 126 | - .sub { | |
| 127 | - color: var(--muted); | |
| 128 | - font-size: 0.8125rem; | |
| 129 | - margin-top: 4px; | |
| 130 | - overflow-wrap: anywhere; | |
| 131 | - } | |
| 160 | + &::-webkit-progress-bar { | |
| 161 | + background: var(--surface-2); | |
| 162 | + } | |
| 132 | 163 | |
| 133 | - .meter { | |
| 134 | - display: block; | |
| 135 | - width: 100%; | |
| 136 | - height: 6px; | |
| 137 | - margin-top: 8px; | |
| 138 | - appearance: none; | |
| 139 | - border: 0; | |
| 140 | - border-radius: var(--radius-full); | |
| 141 | - background: var(--surface-2); | |
| 142 | - overflow: hidden; | |
| 143 | - | |
| 144 | - &::-webkit-progress-bar { | |
| 145 | - background: var(--surface-2); | |
| 146 | - } | |
| 147 | - | |
| 148 | - &::-webkit-progress-value { | |
| 149 | - background: var(--accent); | |
| 150 | - } | |
| 151 | - | |
| 152 | - &::-moz-progress-bar { | |
| 153 | - background: var(--accent); | |
| 154 | - } | |
| 155 | - } | |
| 164 | + &::-webkit-progress-value { | |
| 165 | + background: var(--accent); | |
| 166 | + } | |
| 156 | 167 | |
| 157 | - &.bad .big { | |
| 158 | - color: var(--bad); | |
| 159 | - } | |
| 168 | + &::-moz-progress-bar { | |
| 169 | + background: var(--accent); | |
| 170 | + } | |
| 160 | 171 | |
| 161 | - &.ok .big { | |
| 162 | - color: var(--ok); | |
| 163 | - } | |
| 172 | + &.bad::-webkit-progress-value { | |
| 173 | + background: var(--bad); | |
| 174 | + } | |
| 175 | + | |
| 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 { | |
| 204 | + color: var(--bad); | |
| 205 | + } | |
| 206 | + | |
| 207 | + &.muted { | |
| 208 | + font-weight: 400; | |
| 209 | + } | |
| 210 | +} | |
| 211 | + | |
| 212 | +.health-rows { | |
| 213 | + list-style: none; | |
| 214 | + margin: 0; | |
| 215 | + padding: 0; | |
| 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); | |
| 227 | + } | |
| 228 | + | |
| 229 | + .health-dot { | |
| 230 | + justify-self: center; | |
| 164 | 231 | } |
| 165 | 232 | } |
| 166 | 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; | |
| 246 | +} | |
| 247 | + | |
| 167 | 248 | .link-row { |
| 168 | 249 | display: flex; |
| 169 | 250 | flex-wrap: wrap; |
| @@ -171,7 +252,7 @@ | ||
| 171 | 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 | 256 | .admin-alerts { |
| 176 | 257 | background: var(--danger-bg); |
| 177 | 258 | border: 1px solid var(--danger); |