Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions servers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ async-stream = "0.3"
walkdir = "2.3.1"
hyper-util = { version = "0.1.20", features = ["client-legacy"] }
http-body-util = "0.1.3"
millisecond = "0.15"

grin_api = { path = "../api", version = "5.5.1-alpha.0" }
grin_chain = { path = "../chain", version = "5.5.1-alpha.0" }
Expand Down
21 changes: 15 additions & 6 deletions servers/src/common/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@
//! Server stat collection types, to be used by tests, logging or GUI/TUI
//! to collect information about server status

use crate::util::RwLock;
use chrono::prelude::*;
use grin_core::pow::Difficulty;
use millisecond::MillisecondFormatter;
use std::sync::Arc;
use std::time::SystemTime;

use crate::chain::SyncStatus;
use crate::core::core::hash::Hash;
use crate::core::ser::ProtocolVersion;

use chrono::prelude::*;

use crate::chain::SyncStatus;
use crate::p2p;
use crate::p2p::Capabilities;
use grin_core::pow::Difficulty;
use crate::util::RwLock;

/// Server state info collection struct, to be passed around into internals
/// and populated when required
Expand All @@ -48,6 +47,8 @@ impl Default for ServerStateInfo {
/// consumers might be interested in, such as test results or UI
#[derive(Debug, Clone)]
pub struct ServerStats {
/// Server uptime in seconds
pub uptime_seconds: u64,
/// Number of peers
pub peer_count: u32,
/// Chain head
Expand All @@ -68,6 +69,14 @@ pub struct ServerStats {
pub disk_usage_gb: String,
}

impl ServerStats {
/// Formatted uptime (i.e.: 1y 17d 5h 10m 48s).
pub fn uptime_format(&self) -> String {
let time = millisecond::Millisecond::from_secs(self.uptime_seconds);
time.pretty()
}
}

/// Chain Statistics
#[derive(Clone, Serialize, Debug)]
pub struct ChainStats {
Expand Down
4 changes: 4 additions & 0 deletions servers/src/grin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub struct Server {
pub stop_state: Arc<StopState>,
/// Maintain a lock_file so we do not run multiple Grin nodes from same dir.
lock_file: Arc<File>,
start_time: time::Instant,
connect_thread: Option<JoinHandle<()>>,
sync_thread: JoinHandle<()>,
dandelion_thread: JoinHandle<()>,
Expand Down Expand Up @@ -153,6 +154,7 @@ impl Server {
) -> Result<Server, Error> {
// Obtain our lock_file or fail immediately with an error.
let lock_file = Server::one_grin_at_a_time(&config)?;
let start_time = time::Instant::now();

// Defaults to None (optional) in config file.
// This translates to false here.
Expand Down Expand Up @@ -339,6 +341,7 @@ impl Server {
},
stop_state,
lock_file,
start_time,
connect_thread,
sync_thread,
dandelion_thread,
Expand Down Expand Up @@ -542,6 +545,7 @@ impl Server {
let disk_usage_gb = format!("{:.*}", 3, (disk_usage_bytes as f64 / 1_000_000_000_f64));

Ok(ServerStats {
uptime_seconds: self.start_time.elapsed().as_secs(),
peer_count: self.peer_count(),
chain_stats: head_stats,
header_stats,
Expand Down
8 changes: 8 additions & 0 deletions src/bin/tui/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ impl TUIStatusView {
pub fn create() -> impl View {
let basic_status_view = ResizedView::with_full_screen(
LinearLayout::new(Orientation::Vertical)
.child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("Uptime: "))
.child(TextView::new("0").with_name("basic_uptime")),
)
.child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("Current Status: "))
Expand Down Expand Up @@ -292,6 +297,9 @@ impl TUIStatusListener for TUIStatusView {
fn update(c: &mut Cursive, stats: &ServerStats) {
let basic_status = TUIStatusView::update_sync_status(stats.sync_status);

c.call_on_name("basic_uptime", |t: &mut TextView| {
t.set_content(stats.uptime_format());
});
c.call_on_name("basic_current_status", |t: &mut TextView| {
t.set_content(basic_status);
});
Expand Down
Loading