introduce sbot status data

This commit is contained in:
glyph 2022-02-01 10:06:45 +02:00
parent 3397e5eb75
commit d801c957bd
7 changed files with 58 additions and 41 deletions

View File

@ -1,4 +1,4 @@
use peach_stats::sbot;
use peach_lib::sbot::SbotStatus;
use rocket::{get, request::FlashMessage, State};
use rocket_dyn_templates::{tera::Context, Template};
@ -9,11 +9,11 @@ use crate::RocketConfig;
#[get("/")]
pub fn home(_auth: Authenticated, config: &State<RocketConfig>) -> Template {
// retrieve go-sbot systemd process stats
let sbot_stats = sbot::sbot_stats().ok();
// retrieve go-sbot systemd process status
let sbot_status = SbotStatus::read().ok();
let mut context = Context::new();
context.insert("sbot_stats", &sbot_stats);
context.insert("sbot_status", &sbot_status);
context.insert("flash_name", &None::<()>);
context.insert("flash_msg", &None::<()>);
context.insert("title", &None::<()>);

View File

@ -12,7 +12,7 @@ use std::{
};
use peach_lib::{
config_manager::load_peach_config, dyndns_client, network_client, oled_client, sbot_client,
config_manager::load_peach_config, dyndns_client, network_client, oled_client, sbot::SbotStatus,
};
use peach_stats::{
stats,
@ -117,10 +117,11 @@ impl StatusContext {
}
// test if go-sbot is running
let sbot_is_online_result = sbot_client::is_sbot_online();
let sbot_is_online: bool = match sbot_is_online_result {
Ok(val) => val,
Err(_err) => false,
let sbot_status = SbotStatus::read();
let sbot_is_online: bool = match sbot_status {
// return true if state is active
Ok(status) => matches!(status.state == Some("active".to_string()), true),
_ => false,
};
StatusContext {

View File

@ -1,4 +1,4 @@
use peach_stats::sbot;
use peach_lib::sbot::{SbotConfig, SbotStatus};
use rocket::{get, State};
use rocket_dyn_templates::{tera::Context, Template};
@ -9,10 +9,14 @@ use crate::RocketConfig;
#[get("/scuttlebutt")]
pub fn scuttlebutt_status(_auth: Authenticated, config: &State<RocketConfig>) -> Template {
// retrieve go-sbot systemd process status
let sbot_status = SbotStatus::read().ok();
// retrieve go-sbot configuration parameters
let sbot_config = SbotConfig::read().ok();
let mut context = Context::new();
// retrieve go-sbot systemd process stats
let sbot_stats = sbot::sbot_stats().ok();
context.insert("sbot_stats", &sbot_stats);
context.insert("sbot_status", &sbot_status);
context.insert("sbot_config", &sbot_config);
context.insert("flash_name", &None::<()>);
context.insert("flash_msg", &None::<()>);
context.insert("title", &Some("Scuttlebutt Status"));

View File

@ -25,7 +25,7 @@
</a>
<!-- middle -->
<a class="middle">
<div class="circle circle-large {% if sbot_stats.state == "active" %}circle-success{% else %}circle-error{% endif %}"></div>
<div class="circle circle-large {% if sbot_status.state == "active" %}circle-success{% else %}circle-error{% endif %}"></div>
</a>
<!-- bottom-left -->
<!-- SYSTEM STATUS LINK AND ICON -->

View File

@ -1,20 +1,32 @@
{%- extends "nav" -%}
{%- block card %}
{# ASSIGN VARIABLES #}
{# ---------------- #}
{%- if sbot_config.hops -%}
{% set hops = sbot_config.hops -%}
{%- else -%}
{% set hops = "X" -%}
{%- endif -%}
{%- if sbot_config.lis -%}
{%- set listen_addr = sbot_config.lis | split(pat=":") -%}
{%- else -%}
{%- set listen_addr = ["", ""] -%}
{%- endif -%}
<!-- SBOT CONFIGURATION FORM -->
<div class="card center">
<form>
<div class="center" style="display: flex; flex-direction: column; width: 80%;" title="Number of hops to replicate">
<label for="hops" class="label-small">HOPS</label>
<div id="hops" style="display: flex; justify-content: space-evenly;">
<input type="radio" id="hops_0" name="hops" value="0">
<input type="radio" id="hops_0" name="hops" value="0"{% if hops == 0 %} checked{% endif %}>
<label for="hops_0">0</label>
<input type="radio" id="hops_1" name="hops" value="1">
<input type="radio" id="hops_1" name="hops" value="1"{% if hops == 1 %} checked{% endif %}>
<label for="hops_1">1</label>
<input type="radio" id="hops_2" name="hops" value="2">
<input type="radio" id="hops_2" name="hops" value="2"{% if hops == 2 %} checked{% endif %}>
<label for="hops_2">2</label>
<input type="radio" id="hops_3" name="hops" value="3">
<input type="radio" id="hops_3" name="hops" value="3"{% if hops == 3 %} checked{% endif %}>
<label for="hops_3">3</label>
<input type="radio" id="hops_4" name="hops" value="4">
<input type="radio" id="hops_4" name="hops" value="4"{% if hops == 4 %} checked{% endif %}>
<label for="hops_4">4</label><br>
</div>
</div>
@ -22,32 +34,32 @@
<div class="center" style="display: flex; justify-content: space-between; width: 80%;">
<div style="display: flex; flex-direction: column; width: 60%;" title="IP address on which the sbot runs">
<label for="ip" class="label-small">IP ADDRESS</label>
<input type="text" id="ip" name="ip">
<input type="text" id="ip" name="ip" value="{{ listen_addr.0 }}">
</div>
<div style="display: flex; flex-direction: column; width: 20%;" title="Port on which the sbot runs">
<label for="port" class="label-small">PORT</label>
<input type="text" id="port" name="port">
<input type="text" id="port" name="port" value="{{ listen_addr.1 }}">
</div>
</div>
<br>
<div class="center" style="display: flex; flex-direction: column; width: 80%;" title="Network key (aka 'caps key') to define the Scuttleverse in which the sbot operates in">
<label for="network_key" class="label-small">NETWORK KEY</label>
<input type="text" id="network_key" name="network_key">
<input type="text" id="network_key" name="network_key" value="{{ sbot_config.shscap }}">
</div>
<br>
<div class="center" style="display: flex; flex-direction: column; width: 80%;" title="Directory in which the sbot database is saved">
<label for="database_dir" class="label-small">DATABASE DIRECTORY</label>
<input type="text" id="database_dir" name="database_dir">
<input type="text" id="database_dir" name="database_dir" value="{{ sbot_config.repo }}">
</div>
<br>
<div class="center" style="width: 80%;" title="Broadcast the IP and port of this sbot instance so that local peers can discovery it and attempt to connect">
<input type="checkbox" id="lanBroadcast" name="lan_broadcast">
<input type="checkbox" id="lanBroadcast" name="lan_broadcast"{% if sbot_config.localadv == true %} checked{% endif %}>
<label for="lanBroadcast">Enable LAN Broadcasting</label><br>
<br>
<input type="checkbox" id="lanDiscovery" name="lan_discovery" title="Listen for the presence of local peers and attempt to connect if found">
<input type="checkbox" id="lanDiscovery" name="lan_discovery" title="Listen for the presence of local peers and attempt to connect if found"{% if sbot_config.localdiscov == true %} checked{% endif %}>
<label for="lanDiscovery">Enable LAN Discovery</label><br>
<br>
<input type="checkbox" id="startup" name="startup" title="Define whether the pub runs automatically on system startup">
<input type="checkbox" id="startup" name="startup" title="Define whether the pub runs automatically on system startup"{% if run_on_startup == "enabled" %}checked{% endif %}>
<label for="startup">Run pub on system startup</label><br>
</div>
<br>

View File

@ -5,7 +5,7 @@
<!-- BUTTONS -->
<div id="settingsButtons">
<a id="configureSbot" class="button button-primary center" href="/settings/scuttlebutt/configure" title="Configure Sbot">Configure Sbot</a>
{% if sbot_stats.state == "active" %}
{% if sbot_status.state == "active" %}
<a id="stop" class="button button-primary center" href="/settings/scuttlebutt/stop" title="Stop Sbot">Stop Sbot</a>
<a id="restart" class="button button-primary center" href="/settings/scuttlebutt/restart" title="Restart Sbot">Restart Sbot</a>
{% else %}

View File

@ -2,15 +2,15 @@
{%- block card %}
{# ASSIGN VARIABLES #}
{# ---------------- #}
{%- if sbot_stats.memory -%}
{% set mem = sbot_stats.memory / 1024 / 1024 | round -%}
{%- if sbot_status.memory -%}
{% set mem = sbot_status.memory / 1024 / 1024 | round -%}
{%- else -%}
{% set mem = "X" -%}
{%- endif -%}
<!-- SCUTTLEBUTT STATUS -->
<div class="card center">
<!-- SBOT INFO BOX -->
<div class="capsule capsule-container {% if sbot_stats.state == "active" %}success-border{% else %}warning-border{% endif %}">
<div class="capsule capsule-container {% if sbot_status.state == "active" %}success-border{% else %}warning-border{% endif %}">
<!-- SBOT STATUS GRID -->
<div class="two-grid" title="go-sbot process state">
<!-- top-right config icon -->
@ -20,25 +20,25 @@
<!-- left column -->
<!-- go-sbot state icon with label -->
<div class="grid-column-1">
<img id="sbotStateIcon" class="center icon {% if sbot_stats.state == "inactive" %}icon-inactive{% endif %}" src="/icons/hermies.svg" alt="Hermies">
<label id="sbotStateLabel" for="sbotStateIcon" class="center label-small font-gray" style="margin-top: 0.5rem;" title="Sbot state">{{ sbot_stats.state | upper }}</label>
<img id="sbotStateIcon" class="center icon {% if sbot_status.state == "inactive" %}icon-inactive{% endif %}" src="/icons/hermies.svg" alt="Hermies">
<label id="sbotStateLabel" for="sbotStateIcon" class="center label-small font-gray" style="margin-top: 0.5rem;" title="Sbot state">{{ sbot_status.state | upper }}</label>
</div>
<!-- right column -->
<!-- go-sbot version and uptime / downtime with labels -->
<div class="grid-column-2">
<label class="label-small font-gray" for="sbotVersion" title="go-sbot version">VERSION</label>
<p id="sbotVersion" class="card-text" title="Version">1.1.0-alpha</p>
{% if sbot_stats.state == "active" %}
{% if sbot_status.state == "active" %}
<label class="label-small font-gray" for="sbotUptime" title="go-sbot uptime" style="margin-top: 0.5rem;">UPTIME</label>
<p id="sbotUptime" class="card-text" title="Uptime">{{ sbot_stats.uptime }}</p>
<p id="sbotUptime" class="card-text" title="Uptime">{{ sbot_status.uptime }}</p>
{# render downtime element if downtime is `Some(time)` #}
{# downtime will be `None` if service is stopped and disabled #}
{%- elif sbot_stats.downtime -%}
{%- elif sbot_status.downtime -%}
<label class="label-small font-gray" for="sbotDowntime" title="go-sbot downtime" style="margin-top: 0.5rem;">DOWNTIME</label>
<p id="sbotDowntime" class="card-text" title="Downtime">{{ sbot_stats.downtime }}</p>
<p id="sbotDowntime" class="card-text" title="Downtime">{{ sbot_status.downtime }}</p>
{%- endif -%}
<label class="label-small font-gray" for="sbotBootState" title="go-sbot boot state" style="margin-top: 0.5rem;">RUN ON STARTUP</label>
{% if sbot_stats.boot_state == "enabled" %}
{% if sbot_status.boot_state == "enabled" %}
<p id="runOnStartup" class="card-text" title="Enabled">Enabled</p>
{% else %}
<p id="runOnStartup" class="card-text" title="Disabled">Disabled</p>
@ -80,7 +80,7 @@
<div class="stack">
<img class="icon" title="Hops" src="/icons/orbits.png">
<div class="flex-grid" style="padding-top: 0.5rem;">
<label class="label-medium" style="padding-right: 3px;" title="Replication hops">2</label>
<label class="label-medium" style="padding-right: 3px;" title="Replication hops">{{ sbot_config.hops }}</label>
</div>
<label class="label-small font-gray">HOPS</label>
</div>
@ -93,10 +93,10 @@
<label class="label-small font-gray">BLOBSTORE</label>
</div>
<div class="stack">
<img class="icon{% if not sbot_stats.memory %} icon-inactive{% endif %}" title="Memory" src="/icons/ram.png">
<img class="icon{% if not sbot_status.memory %} icon-inactive{% endif %}" title="Memory" src="/icons/ram.png">
<div class="flex-grid" style="padding-top: 0.5rem;">
<label class="label-medium{% if sbot_stats.state == "inactive" %} font-gray{% endif %}" style="padding-right: 3px;" title="Memory usage of the go-sbot process in MB">{{ mem }}</label>
<label class="label-small {% if sbot_stats.state == "inactive" %}font-gray{% else %}font-near-black{% endif %}">MB</label>
<label class="label-medium{% if sbot_status.state == "inactive" %} font-gray{% 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-near-black{% endif %}">MB</label>
</div>
<label class="label-small font-gray">MEMORY</label>
</div>