fedimint_server_ui/latency.rs
1use std::collections::BTreeMap;
2use std::time::Duration;
3
4use fedimint_core::PeerId;
5use maud::{Markup, html};
6
7pub fn render(
8 consensus_ord_latency: Option<Duration>,
9 p2p_connection_status: &BTreeMap<PeerId, Option<Duration>>,
10) -> Markup {
11 html! {
12 div class="card h-100" hx-swap-oob=(true)
13 id="consensus-latency"
14 {
15 div class="card-header dashboard-header" { "System Latency" }
16 div class="card-body" {
17 @if let Some(duration) = consensus_ord_latency {
18 div class=(format!("alert {}", if duration.as_millis() < 1000 {
19 "alert-success"
20 } else if duration.as_millis() < 2000 {
21 "alert-warning"
22 } else {
23 "alert-danger"
24 })) {
25 "Consensus Latency: " strong {
26 (format!("{} ms", duration.as_millis()))
27 }
28 }
29 }
30 @if p2p_connection_status.is_empty() {
31 p { "No peer connections available." }
32 } @else {
33 table class="table table-striped" {
34 thead {
35 tr {
36 th { "ID" }
37 th { "Status" }
38 th { "Round Trip" }
39 }
40 }
41 tbody {
42 @for (peer_id, rtt) in p2p_connection_status {
43 tr {
44 td { (peer_id.to_string()) }
45 td {
46 @match rtt {
47 Some(_) => {
48 span class="badge bg-success" { "Connected" }
49 }
50 None => {
51 span class="badge bg-danger" { "Disconnected" }
52 }
53 }
54 }
55 td {
56 @match rtt {
57 Some(duration) if duration.as_millis() > 0 => {
58 (format!("{} ms", duration.as_millis()))
59 }
60 Some(_) | None => {
61 span class="text-muted" { "N/A" }
62 }
63 }
64 }
65 }
66 }
67 }
68 }
69 }
70 }
71 }
72 }
73}