complete scuttlebutt status route
This commit is contained in:
parent
fe04195030
commit
7cdf8c553d
|
@ -8,21 +8,6 @@ use peach_lib::sbot::{SbotConfig, SbotStatus};
|
||||||
|
|
||||||
use crate::{error::PeachWebError, templates};
|
use crate::{error::PeachWebError, templates};
|
||||||
|
|
||||||
/*
|
|
||||||
{# ASSIGN VARIABLES #}
|
|
||||||
{# ---------------- #}
|
|
||||||
{%- if sbot_status.memory -%}
|
|
||||||
{% set mem = sbot_status.memory / 1024 / 1024 | round | int -%}
|
|
||||||
{%- else -%}
|
|
||||||
{% set mem = "0" -%}
|
|
||||||
{%- endif -%}
|
|
||||||
{%- if sbot_status.blobstore -%}
|
|
||||||
{% set blobs = sbot_status.blobstore / 1024 / 1024 | round | int -%}
|
|
||||||
{%- else -%}
|
|
||||||
{% set blobs = "0" -%}
|
|
||||||
{%- endif -%}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// HELPER FUNCTIONS
|
// HELPER FUNCTIONS
|
||||||
|
|
||||||
pub async fn init_sbot_with_config(
|
pub async fn init_sbot_with_config(
|
||||||
|
@ -116,9 +101,89 @@ fn database_element(state: &str) -> Markup {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn memory_element(memory: Option<u32>) -> Markup {
|
||||||
|
let (memory, img_class, medium_label_class, small_label_class) = match memory {
|
||||||
|
Some(mem) => {
|
||||||
|
// convert memory to mb representation
|
||||||
|
let memory_rounded = mem / 1024 / 1024;
|
||||||
|
(
|
||||||
|
memory_rounded.to_string(),
|
||||||
|
"icon icon-active",
|
||||||
|
"label-medium font-normal",
|
||||||
|
"label-small font-normal",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
_ => (
|
||||||
|
0.to_string(),
|
||||||
|
"icon icon-inactive",
|
||||||
|
"label-medium font-gray",
|
||||||
|
"label-small font-gray",
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
html! {
|
||||||
|
div class="stack" {
|
||||||
|
img class=(img_class) title="Memory" src="/icons/ram.png";
|
||||||
|
div class="flex-grid" style="padding-top: 0.5rem;" {
|
||||||
|
label class=(medium_label_class) style="padding-right: 3px;" title="Memory usage of the go-sbot process in MB" { (memory) }
|
||||||
|
label class=(small_label_class) { "MB" }
|
||||||
|
}
|
||||||
|
label class=(small_label_class) { "MEMORY" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hops_element() -> Markup {
|
||||||
|
// retrieve go-sbot systemd process status
|
||||||
|
let hops = match SbotConfig::read() {
|
||||||
|
Ok(conf) => conf.hops,
|
||||||
|
_ => 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
html! {
|
||||||
|
div class="stack" {
|
||||||
|
img class="icon icon-active" title="Hops" src="/icons/orbits.png";
|
||||||
|
div class="flex-grid" style="padding-top: 0.5rem;" {
|
||||||
|
label class="label-medium font-normal" style="padding-right: 3px;" title="Replication hops" {
|
||||||
|
(hops)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
label class="label-small font-gray" { "HOPS" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn blobs_element(blobstore: Option<u64>) -> Markup {
|
||||||
|
let blobstore_size = match blobstore {
|
||||||
|
// convert blobstore size to mb representation
|
||||||
|
Some(blobs) => blobs / 1024 / 1024,
|
||||||
|
None => 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
html! {
|
||||||
|
div class="stack" {
|
||||||
|
img class="icon icon-active" title="Blobs" src="/icons/image-file.png";
|
||||||
|
div class="flex-grid" style="padding-top: 0.5rem;" {
|
||||||
|
label class="label-medium font-normal" style="padding-right: 3px;" title="Blobstore size in MB" { (blobstore_size) }
|
||||||
|
label class="label-small font-normal" { "MB" }
|
||||||
|
}
|
||||||
|
label class="label-small font-gray" { "BLOBSTORE" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Read the state of the go-sbot process and define status-related
|
/// Read the state of the go-sbot process and define status-related
|
||||||
/// elements accordingly.
|
/// elements accordingly.
|
||||||
fn render_status_elements<'a>() -> (String, &'a str, &'a str, Markup, Markup, Markup) {
|
fn render_status_elements<'a>() -> (
|
||||||
|
String,
|
||||||
|
&'a str,
|
||||||
|
&'a str,
|
||||||
|
Markup,
|
||||||
|
Markup,
|
||||||
|
Markup,
|
||||||
|
Markup,
|
||||||
|
Markup,
|
||||||
|
) {
|
||||||
// retrieve go-sbot systemd process status
|
// retrieve go-sbot systemd process status
|
||||||
let sbot_status = SbotStatus::read();
|
let sbot_status = SbotStatus::read();
|
||||||
|
|
||||||
|
@ -134,6 +199,8 @@ fn render_status_elements<'a>() -> (String, &'a str, &'a str, Markup, Markup, Ma
|
||||||
uptime_element(&status.uptime),
|
uptime_element(&status.uptime),
|
||||||
run_on_startup_element(&status.boot_state),
|
run_on_startup_element(&status.boot_state),
|
||||||
database_element("active"),
|
database_element("active"),
|
||||||
|
memory_element(status.memory),
|
||||||
|
blobs_element(status.blobstore),
|
||||||
),
|
),
|
||||||
Some(state) if state == "inactive" => (
|
Some(state) if state == "inactive" => (
|
||||||
"INACTIVE".to_string(),
|
"INACTIVE".to_string(),
|
||||||
|
@ -142,6 +209,8 @@ fn render_status_elements<'a>() -> (String, &'a str, &'a str, Markup, Markup, Ma
|
||||||
downtime_element(&status.downtime),
|
downtime_element(&status.downtime),
|
||||||
run_on_startup_element(&status.boot_state),
|
run_on_startup_element(&status.boot_state),
|
||||||
database_element("inactive"),
|
database_element("inactive"),
|
||||||
|
memory_element(None),
|
||||||
|
blobs_element(status.blobstore),
|
||||||
),
|
),
|
||||||
// state is neither active nor inactive (might be failed)
|
// state is neither active nor inactive (might be failed)
|
||||||
Some(state) => (
|
Some(state) => (
|
||||||
|
@ -151,6 +220,8 @@ fn render_status_elements<'a>() -> (String, &'a str, &'a str, Markup, Markup, Ma
|
||||||
downtime_element(&None),
|
downtime_element(&None),
|
||||||
run_on_startup_element(&status.boot_state),
|
run_on_startup_element(&status.boot_state),
|
||||||
database_element("failed"),
|
database_element("failed"),
|
||||||
|
memory_element(None),
|
||||||
|
blobs_element(status.blobstore),
|
||||||
),
|
),
|
||||||
None => (
|
None => (
|
||||||
"UNAVAILABLE".to_string(),
|
"UNAVAILABLE".to_string(),
|
||||||
|
@ -159,6 +230,8 @@ fn render_status_elements<'a>() -> (String, &'a str, &'a str, Markup, Markup, Ma
|
||||||
downtime_element(&None),
|
downtime_element(&None),
|
||||||
run_on_startup_element(&status.boot_state),
|
run_on_startup_element(&status.boot_state),
|
||||||
database_element("unavailable"),
|
database_element("unavailable"),
|
||||||
|
memory_element(None),
|
||||||
|
blobs_element(status.blobstore),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
// show an error state if the attempt to read the go-sbot process
|
// show an error state if the attempt to read the go-sbot process
|
||||||
|
@ -171,6 +244,8 @@ fn render_status_elements<'a>() -> (String, &'a str, &'a str, Markup, Markup, Ma
|
||||||
downtime_element(&None),
|
downtime_element(&None),
|
||||||
run_on_startup_element(&None),
|
run_on_startup_element(&None),
|
||||||
database_element("error"),
|
database_element("error"),
|
||||||
|
memory_element(None),
|
||||||
|
blobs_element(None),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -184,8 +259,12 @@ pub fn build_template() -> PreEscaped<String> {
|
||||||
uptime_downtime_element,
|
uptime_downtime_element,
|
||||||
run_on_startup_element,
|
run_on_startup_element,
|
||||||
database_element,
|
database_element,
|
||||||
|
memory_element,
|
||||||
|
blobs_element,
|
||||||
) = render_status_elements();
|
) = render_status_elements();
|
||||||
|
|
||||||
|
let hops_element = hops_element();
|
||||||
|
|
||||||
let status_template = html! {
|
let status_template = html! {
|
||||||
(PreEscaped("<!-- SCUTTLEBUTT STATUS -->"))
|
(PreEscaped("<!-- SCUTTLEBUTT STATUS -->"))
|
||||||
div class="card center" {
|
div class="card center" {
|
||||||
|
@ -228,36 +307,12 @@ pub fn build_template() -> PreEscaped<String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hr style="color: var(--light-gray);";
|
hr style="color: var(--light-gray);";
|
||||||
/*
|
(PreEscaped("<!-- THREE-ACROSS STACK -->"))
|
||||||
(PreEscaped("<!-- THREE-ACROSS STACK -->
|
div class="three-grid card-container" style="margin-top: 1rem;" {
|
||||||
<div class="three-grid card-container" style="margin-top: 1rem;">
|
(hops_element)
|
||||||
<div class="stack">
|
(blobs_element)
|
||||||
<img class="icon icon-active" title="Hops" src="/icons/orbits.png">
|
(memory_element)
|
||||||
<div class="flex-grid" style="padding-top: 0.5rem;">
|
}
|
||||||
<label class="label-medium font-normal" style="padding-right: 3px;" title="Replication hops">{{ sbot_config.hops }}</label>
|
|
||||||
</div>
|
|
||||||
<label class="label-small font-gray">HOPS</label>
|
|
||||||
</div>
|
|
||||||
<div class="stack">
|
|
||||||
<img class="icon icon-active" title="Blobs" src="/icons/image-file.png">
|
|
||||||
<div class="flex-grid" style="padding-top: 0.5rem;">
|
|
||||||
<label class="label-medium font-normal" style="padding-right: 3px;" title="Blobstore size in MB">{{ blobs }}</label>
|
|
||||||
<label class="label-small font-normal">MB</label>
|
|
||||||
</div>
|
|
||||||
<label class="label-small font-gray">BLOBSTORE</label>
|
|
||||||
</div>
|
|
||||||
<div class="stack">
|
|
||||||
<img class="icon{% if sbot_status.memory %} icon-active{% else %} icon-inactive{% endif %}" title="Memory" src="/icons/ram.png">
|
|
||||||
<div class="flex-grid" style="padding-top: 0.5rem;">
|
|
||||||
<label class="label-medium{% if sbot_status.state == "inactive" %} font-gray{% else %} font-normal{% endif %}" style="padding-right: 3px;" title="Memory usage of the go-sbot process in MB">{{ mem }}</label>
|
|
||||||
<label class="label-small{% if sbot_status.state == "inactive" %} font-gray{% else %} font-normal{% endif %}">MB</label>
|
|
||||||
</div>
|
|
||||||
<label class="label-small font-gray">MEMORY</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue