Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 51576c2b3b | |||
| db8730d13a |
@@ -23,7 +23,7 @@ pub(crate) const _ETH_ERC20_CONTRACT_ADDRESS: [u8; 20] =
|
|||||||
hex_literal::hex!("0000000000000000000000000000000000000000");
|
hex_literal::hex!("0000000000000000000000000000000000000000");
|
||||||
pub(crate) const REWARDING_VALIDATOR_ADDRESS: &str = "n10yyd98e2tuwu0f7ypz9dy3hhjw7v772q6287gy";
|
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> {
|
pub(crate) fn validators() -> Vec<ValidatorDetails> {
|
||||||
vec![ValidatorDetails::new(
|
vec![ValidatorDetails::new(
|
||||||
"https://rpc.nyx.nodes.guru/",
|
"https://rpc.nyx.nodes.guru/",
|
||||||
|
|||||||
@@ -34,12 +34,16 @@ pub enum StatsData {
|
|||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct StatsGatewayData {
|
pub struct StatsGatewayData {
|
||||||
|
pub gateway_id: String,
|
||||||
pub inbox_count: u32,
|
pub inbox_count: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StatsGatewayData {
|
impl StatsGatewayData {
|
||||||
pub fn new(inbox_count: u32) -> Self {
|
pub fn new(gateway_id: String, inbox_count: u32) -> Self {
|
||||||
StatsGatewayData { inbox_count }
|
StatsGatewayData {
|
||||||
|
gateway_id,
|
||||||
|
inbox_count,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -333,6 +333,7 @@ where
|
|||||||
if self.config.get_enabled_statistics() {
|
if self.config.get_enabled_statistics() {
|
||||||
let statistics_service_url = self.config.get_statistics_service_url();
|
let statistics_service_url = self.config.get_statistics_service_url();
|
||||||
let stats_collector = GatewayStatisticsCollector::new(
|
let stats_collector = GatewayStatisticsCollector::new(
|
||||||
|
self.identity_keypair.public_key().to_base58_string(),
|
||||||
active_clients_store.clone(),
|
active_clients_store.clone(),
|
||||||
statistics_service_url,
|
statistics_service_url,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -14,13 +14,19 @@ use statistics_common::{
|
|||||||
use crate::node::client_handling::active_clients::ActiveClientsStore;
|
use crate::node::client_handling::active_clients::ActiveClientsStore;
|
||||||
|
|
||||||
pub(crate) struct GatewayStatisticsCollector {
|
pub(crate) struct GatewayStatisticsCollector {
|
||||||
|
gateway_id: String,
|
||||||
active_clients_store: ActiveClientsStore,
|
active_clients_store: ActiveClientsStore,
|
||||||
statistics_service_url: Url,
|
statistics_service_url: Url,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GatewayStatisticsCollector {
|
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 {
|
GatewayStatisticsCollector {
|
||||||
|
gateway_id,
|
||||||
active_clients_store,
|
active_clients_store,
|
||||||
statistics_service_url,
|
statistics_service_url,
|
||||||
}
|
}
|
||||||
@@ -34,8 +40,10 @@ impl StatisticsCollector for GatewayStatisticsCollector {
|
|||||||
interval: Duration,
|
interval: Duration,
|
||||||
timestamp: DateTime<Utc>,
|
timestamp: DateTime<Utc>,
|
||||||
) -> StatsMessage {
|
) -> StatsMessage {
|
||||||
let inbox_count = self.active_clients_store.size() as u32;
|
let stats_data = vec![StatsData::Gateway(StatsGatewayData::new(
|
||||||
let stats_data = vec![StatsData::Gateway(StatsGatewayData { inbox_count })];
|
self.gateway_id.clone(),
|
||||||
|
self.active_clients_store.size() as u32,
|
||||||
|
))];
|
||||||
StatsMessage {
|
StatsMessage {
|
||||||
stats_data,
|
stats_data,
|
||||||
interval_seconds: interval.as_secs() as u32,
|
interval_seconds: interval.as_secs() as u32,
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ CREATE TABLE service_statistics
|
|||||||
CREATE TABLE gateway_statistics
|
CREATE TABLE gateway_statistics
|
||||||
(
|
(
|
||||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
gateway_id VARCHAR NOT NULL,
|
||||||
inbox_count INTEGER NOT NULL,
|
inbox_count INTEGER NOT NULL,
|
||||||
timestamp DATETIME NOT NULL
|
timestamp DATETIME NOT NULL
|
||||||
);
|
);
|
||||||
@@ -35,6 +35,7 @@ pub struct ServiceStatistic {
|
|||||||
|
|
||||||
#[derive(Clone, Serialize, Deserialize, Debug)]
|
#[derive(Clone, Serialize, Deserialize, Debug)]
|
||||||
pub struct GatewayStatistic {
|
pub struct GatewayStatistic {
|
||||||
|
pub gateway_id: String,
|
||||||
pub inbox_count: u32,
|
pub inbox_count: u32,
|
||||||
pub timestamp: String,
|
pub timestamp: String,
|
||||||
}
|
}
|
||||||
@@ -70,6 +71,7 @@ pub(crate) async fn post_all_statistics(
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|data| {
|
.map(|data| {
|
||||||
GenericStatistic::Gateway(GatewayStatistic {
|
GenericStatistic::Gateway(GatewayStatistic {
|
||||||
|
gateway_id: data.gateway_id,
|
||||||
inbox_count: data.inbox_count as u32,
|
inbox_count: data.inbox_count as u32,
|
||||||
timestamp: data.timestamp.to_string(),
|
timestamp: data.timestamp.to_string(),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -47,16 +47,19 @@ impl StorageManager {
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
|
/// * `gateway_id`: The gateway identity that collected the statstics.
|
||||||
/// * `inbox_count`: Number of clients of a gateway.
|
/// * `inbox_count`: Number of clients of a gateway.
|
||||||
/// * `interval_seconds`: Duration in seconds in which the data was gathered.
|
/// * `interval_seconds`: Duration in seconds in which the data was gathered.
|
||||||
/// * `timestamp`: The moment in time when the data started being collected.
|
/// * `timestamp`: The moment in time when the data started being collected.
|
||||||
pub(super) async fn insert_gateway_statistics(
|
pub(super) async fn insert_gateway_statistics(
|
||||||
&self,
|
&self,
|
||||||
|
gateway_id: String,
|
||||||
inbox_count: u32,
|
inbox_count: u32,
|
||||||
timestamp: DateTime<Utc>,
|
timestamp: DateTime<Utc>,
|
||||||
) -> Result<(), sqlx::Error> {
|
) -> Result<(), sqlx::Error> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"INSERT INTO gateway_statistics(inbox_count, timestamp) VALUES (?, ?)",
|
"INSERT INTO gateway_statistics(gateway_id, inbox_count, timestamp) VALUES (?, ?, ?)",
|
||||||
|
gateway_id,
|
||||||
inbox_count,
|
inbox_count,
|
||||||
timestamp,
|
timestamp,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -71,7 +71,11 @@ impl NetworkStatisticsStorage {
|
|||||||
}
|
}
|
||||||
statistics_common::StatsData::Gateway(gateway_data) => {
|
statistics_common::StatsData::Gateway(gateway_data) => {
|
||||||
self.manager
|
self.manager
|
||||||
.insert_gateway_statistics(gateway_data.inbox_count, timestamp)
|
.insert_gateway_statistics(
|
||||||
|
gateway_data.gateway_id,
|
||||||
|
gateway_data.inbox_count,
|
||||||
|
timestamp,
|
||||||
|
)
|
||||||
.await?
|
.await?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ pub(crate) struct ServiceStatistics {
|
|||||||
pub(crate) struct GatewayStatistics {
|
pub(crate) struct GatewayStatistics {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(crate) id: i64,
|
pub(crate) id: i64,
|
||||||
|
pub(crate) gateway_id: String,
|
||||||
pub(crate) inbox_count: i64,
|
pub(crate) inbox_count: i64,
|
||||||
pub(crate) timestamp: NaiveDateTime,
|
pub(crate) timestamp: NaiveDateTime,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user