adding hashrate chart

This commit is contained in:
aglkm
2024-09-22 17:14:03 +03:00
parent cb775ecd9c
commit a4603ea536
5 changed files with 76 additions and 85 deletions

View File

@@ -213,19 +213,25 @@ impl Output {
// Statistics data
#[derive(Debug)]
#[derive(Debug, Serialize)]
pub struct Statistics {
pub timing: u32,
pub user_agent: Vec<String>,
pub count: Vec<String>,
pub total: u32,
pub hashrate: Vec<String>,
pub hash_date: Vec<String>,
}
impl Statistics {
pub fn new() -> Statistics {
Statistics {
user_agent: Vec::new(),
count: Vec::new(),
total: 0,
timing: 0,
user_agent: Vec::new(),
count: Vec::new(),
total: 0,
hashrate: Vec::new(),
hash_date: Vec::new(),
}
}
}

View File

@@ -223,6 +223,8 @@ fn stats(statistics: &State<Arc<Mutex<Statistics>>>) -> Template {
user_agent: data.user_agent.clone(),
count: data.count.clone(),
total: data.total,
hashrate: data.hashrate.clone(),
hash_date: data.hash_date.clone(),
})
}
@@ -673,7 +675,7 @@ async fn main() {
error!("{}", e);
},
}
tokio::time::sleep(Duration::from_secs(15)).await;
}
});

View File

@@ -325,7 +325,7 @@ pub fn get_disk_usage(dashboard: Arc<Mutex<Dashboard>>) -> Result<(), Error> {
// Collecting: hashrate, difficulty, production cost, breakeven cost.
pub async fn get_mining_stats(dashboard: Arc<Mutex<Dashboard>>) -> Result<(), anyhow::Error> {
pub async fn get_mining_stats(dashboard: Arc<Mutex<Dashboard>>, statistics: Arc<Mutex<Statistics>>) -> Result<(), anyhow::Error> {
let difficulty_window = 1440;
let height = get_current_height(dashboard.clone());
@@ -356,7 +356,7 @@ pub async fn get_mining_stats(dashboard: Arc<Mutex<Dashboard>>) -> Result<(), an
} else {
data.hashrate = format!("{:.2} G/s", hashrate);
}
data.difficulty = net_diff.to_string();
if CONFIG.coingecko_api == "enabled" {
@@ -374,6 +374,23 @@ pub async fn get_mining_stats(dashboard: Arc<Mutex<Dashboard>>) -> Result<(), an
/ (120.0 / 1000.0 * (1.0 / coins_per_hour)));
}
}
let mut stats = statistics.lock().unwrap();
// Save hashrate into statistics every 24H
if stats.timing == 0 || stats.timing >= 86400 {
if stats.hashrate.len() == 30 {
stats.hashrate.remove(0);
}
stats.hashrate.push(format!("{:.2}", hashrate / 1000.0));
stats.hash_date.push(format!("\"{}\"", Utc::now().format("%d-%m-%Y")));
stats.timing = 0;
}
// Increasing timing by 15 seconds (our data update period)
stats.timing = stats.timing + 15;
}
}

View File

@@ -17,7 +17,7 @@ pub async fn run(dash: Arc<Mutex<Dashboard>>, blocks: Arc<Mutex<Vec<Block>>>,
let _ = requests::get_connected_peers(dash.clone(), stats.clone()).await?;
let _ = requests::get_market(dash.clone()).await?;
requests::get_disk_usage(dash.clone())?;
let _ = requests::get_mining_stats(dash.clone()).await?;
let _ = requests::get_mining_stats(dash.clone(), stats.clone()).await?;
let _ = requests::get_recent_blocks(dash.clone(), blocks.clone()).await?;
let _ = requests::get_txn_stats(dash.clone(), txns.clone()).await?;