fedimint_server_ui/dashboard/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" id="consensus-latency" {
13 div class="card-header dashboard-header" { "System Latency" }
14 div class="card-body" {
15 @if let Some(duration) = consensus_ord_latency {
16 div class=(format!("alert {}", if duration.as_millis() < 1000 {
17 "alert-success"
18 } else if duration.as_millis() < 2000 {
19 "alert-warning"
20 } else {
21 "alert-danger"
22 })) {
23 "Consensus Latency: " strong {
24 (format!("{} ms", duration.as_millis()))
25 }
26 }
27 }
28 @if p2p_connection_status.is_empty() {
29 p { "No peer connections available." }
30 } @else {
31 table class="table table-striped" {
32 thead {
33 tr {
34 th { "ID" }
35 th { "Status" }
36 th { "Round Trip" }
37 }
38 }
39 tbody {
40 @for (peer_id, rtt) in p2p_connection_status {
41 tr {
42 td { (peer_id.to_string()) }
43 td {
44 @match rtt {
45 Some(_) => {
46 span class="badge bg-success" { "Connected" }
47 }
48 None => {
49 span class="badge bg-danger" { "Disconnected" }
50 }
51 }
52 }
53 td {
54 @match rtt {
55 Some(duration) if duration.as_millis() > 0 => {
56 (format!("{} ms", duration.as_millis()))
57 }
58 Some(_) | None => {
59 span class="text-muted" { "N/A" }
60 }
61 }
62 }
63 }
64 }
65 }
66 }
67 }
68 }
69 }
70 }
71}