Compare commits

...

2 Commits

Author SHA1 Message Date
Bogdan-Ștefan Neacșu 51576c2b3b Add gateway id to stats data 2022-06-29 16:38:05 +03:00
Bogdan-Ștefan Neacșu db8730d13a Update with the mainnet stats domain 2022-06-29 15:51:07 +03:00
9 changed files with 32 additions and 8 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ pub(crate) const _ETH_ERC20_CONTRACT_ADDRESS: [u8; 20] =
hex_literal::hex!("0000000000000000000000000000000000000000");
pub(crate) const REWARDING_VALIDATOR_ADDRESS: &str = "n10yyd98e2tuwu0f7ypz9dy3hhjw7v772q6287gy";
pub(crate) const STATISTICS_SERVICE_DOMAIN_ADDRESS: &str = "http://127.0.0.1:8090";
pub(crate) const STATISTICS_SERVICE_DOMAIN_ADDRESS: &str = "http://mainnet-stats.nymte.ch:8090";
pub(crate) fn validators() -> Vec<ValidatorDetails> {
vec![ValidatorDetails::new(
"https://rpc.nyx.nodes.guru/",
+6 -2
View File
@@ -34,12 +34,16 @@ pub enum StatsData {
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct StatsGatewayData {
pub gateway_id: String,
pub inbox_count: u32,
}
impl StatsGatewayData {
pub fn new(inbox_count: u32) -> Self {
StatsGatewayData { inbox_count }
pub fn new(gateway_id: String, inbox_count: u32) -> Self {
StatsGatewayData {
gateway_id,
inbox_count,
}
}
}
+1
View File
@@ -333,6 +333,7 @@ where
if self.config.get_enabled_statistics() {
let statistics_service_url = self.config.get_statistics_service_url();
let stats_collector = GatewayStatisticsCollector::new(
self.identity_keypair.public_key().to_base58_string(),
active_clients_store.clone(),
statistics_service_url,
);
+11 -3
View File
@@ -14,13 +14,19 @@ use statistics_common::{
use crate::node::client_handling::active_clients::ActiveClientsStore;
pub(crate) struct GatewayStatisticsCollector {
gateway_id: String,
active_clients_store: ActiveClientsStore,
statistics_service_url: Url,
}
impl GatewayStatisticsCollector {
pub fn new(active_clients_store: ActiveClientsStore, statistics_service_url: Url) -> Self {
pub fn new(
gateway_id: String,
active_clients_store: ActiveClientsStore,
statistics_service_url: Url,
) -> Self {
GatewayStatisticsCollector {
gateway_id,
active_clients_store,
statistics_service_url,
}
@@ -34,8 +40,10 @@ impl StatisticsCollector for GatewayStatisticsCollector {
interval: Duration,
timestamp: DateTime<Utc>,
) -> StatsMessage {
let inbox_count = self.active_clients_store.size() as u32;
let stats_data = vec![StatsData::Gateway(StatsGatewayData { inbox_count })];
let stats_data = vec![StatsData::Gateway(StatsGatewayData::new(
self.gateway_id.clone(),
self.active_clients_store.size() as u32,
))];
StatsMessage {
stats_data,
interval_seconds: interval.as_secs() as u32,
@@ -16,6 +16,7 @@ CREATE TABLE service_statistics
CREATE TABLE gateway_statistics
(
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
gateway_id VARCHAR NOT NULL,
inbox_count INTEGER NOT NULL,
timestamp DATETIME NOT NULL
);
@@ -35,6 +35,7 @@ pub struct ServiceStatistic {
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct GatewayStatistic {
pub gateway_id: String,
pub inbox_count: u32,
pub timestamp: String,
}
@@ -70,6 +71,7 @@ pub(crate) async fn post_all_statistics(
.into_iter()
.map(|data| {
GenericStatistic::Gateway(GatewayStatistic {
gateway_id: data.gateway_id,
inbox_count: data.inbox_count as u32,
timestamp: data.timestamp.to_string(),
})
@@ -47,16 +47,19 @@ impl StorageManager {
///
/// # Arguments
///
/// * `gateway_id`: The gateway identity that collected the statstics.
/// * `inbox_count`: Number of clients of a gateway.
/// * `interval_seconds`: Duration in seconds in which the data was gathered.
/// * `timestamp`: The moment in time when the data started being collected.
pub(super) async fn insert_gateway_statistics(
&self,
gateway_id: String,
inbox_count: u32,
timestamp: DateTime<Utc>,
) -> Result<(), sqlx::Error> {
sqlx::query!(
"INSERT INTO gateway_statistics(inbox_count, timestamp) VALUES (?, ?)",
"INSERT INTO gateway_statistics(gateway_id, inbox_count, timestamp) VALUES (?, ?, ?)",
gateway_id,
inbox_count,
timestamp,
)
@@ -71,7 +71,11 @@ impl NetworkStatisticsStorage {
}
statistics_common::StatsData::Gateway(gateway_data) => {
self.manager
.insert_gateway_statistics(gateway_data.inbox_count, timestamp)
.insert_gateway_statistics(
gateway_data.gateway_id,
gateway_data.inbox_count,
timestamp,
)
.await?
}
}
@@ -17,6 +17,7 @@ pub(crate) struct ServiceStatistics {
pub(crate) struct GatewayStatistics {
#[allow(dead_code)]
pub(crate) id: i64,
pub(crate) gateway_id: String,
pub(crate) inbox_count: i64,
pub(crate) timestamp: NaiveDateTime,
}