diff --git a/nomium/prometheus/Cargo.toml b/nomium/prometheus/Cargo.toml new file mode 100644 index 000000000..8ac0afd94 --- /dev/null +++ b/nomium/prometheus/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "nomium-prometheus" +version = "0.1.0" +edition = "2021" + +[dependencies] +lazy_static = "1.5" +prometheus = "0.13" +prometheus-static-metric = "0.5" +tiny_http = "0.12" +tracing = { version = "0.1" } +dotenvy = "0.15" \ No newline at end of file diff --git a/nomium/prometheus/README.md b/nomium/prometheus/README.md new file mode 100644 index 000000000..9b78af7a2 --- /dev/null +++ b/nomium/prometheus/README.md @@ -0,0 +1,20 @@ +``` +mining_shares_received_total - Общее количество шар, полученных от майнеров до любой валидации +mining_shares_valid_jobid_total - Количество шар с корректным идентификатором работы +mining_shares_upstream_target_meet_total - Количество шар, соответствующих таргету апстрим пула +mining_shares_downstream_target_meet_total - Количество шар, соответствующих таргету майнера +tproxy_shares_rejected_total - Общее количество отклоненных шар +mining_active_connections - Количество активных подключений майнеров +mining_connection_attempts_total - Общее количество попыток подключения +mining_connection_failures_total - Количество неудачных попыток подключения +mining_auth_failures_total - Количество ошибок аутентификации +mining_timeout_failures_total - Количество таймаутов подключения +chfact_shares_logged_total - Общее количество шар, отправленных в логгер +shalog_shares_received_total - Общее количество шар, полученных логгером шар +shalog_primary_channel_shares_total - Общее количество шар, отправленных через основной канал +shalog_backup_channel_shares_total - Общее количество шар, отправленных через резервный канал +shalog_primary_try_stored_total - Общее количество попыток сохранения шар через основной канал +shalog_backup_try_stored_total - Общее количество попыток сохранения шар через резервный канал +shalog_primary_store_failed_total - Количество неудачных попыток сохранения шар через основной канал +shalog_backup_store_failed_total - Количество неудачных попыток сохранения шар через резервный канал +``` \ No newline at end of file diff --git a/roles/translator/src/lib/metrics.rs b/nomium/prometheus/src/lib.rs similarity index 63% rename from roles/translator/src/lib/metrics.rs rename to nomium/prometheus/src/lib.rs index 4ef45f33c..66542710d 100644 --- a/roles/translator/src/lib/metrics.rs +++ b/nomium/prometheus/src/lib.rs @@ -23,6 +23,10 @@ lazy_static! { register_int_counter!("mining_shares_downstream_target_meet_total", "Shares that meet downstream (miner) target").unwrap(); + pub static ref TPROXY_SHARES_REJECTED_TOTAL: IntCounter = + register_int_counter!("tproxy_shares_rejected_total", + "Total number of rejected shares").unwrap(); + pub static ref ACTIVE_CONNECTIONS: IntGauge = register_int_gauge!("mining_active_connections", "Number of active miner connections").unwrap(); @@ -43,6 +47,38 @@ lazy_static! { register_int_counter!("mining_timeout_failures_total", "Number of connection timeouts").unwrap(); + pub static ref CHFACT_SHARES_LOGGED_TOTAL: IntCounter = + register_int_counter!("chfact_shares_logged_total", + "Total number of shares sent to logger").unwrap(); + + pub static ref SHALOG_SHARES_RECEIVED_TOTAL: IntCounter = + register_int_counter!("shalog_shares_received_total", + "Total number of shares received by shares-logger").unwrap(); + + pub static ref SHALOG_PRIMARY_CHANNEL_SHARES_TOTAL: IntCounter = + register_int_counter!("shalog_primary_channel_shares_total", + "Total number of shares sent through primary channel").unwrap(); + + pub static ref SHALOG_BACKUP_CHANNEL_SHARES_TOTAL: IntCounter = + register_int_counter!("shalog_backup_channel_shares_total", + "Total number of shares sent through backup channel").unwrap(); + + pub static ref SHALOG_PRIMARY_TRY_STORED_TOTAL: IntCounter = + register_int_counter!("shalog_primary_try_stored_total", + "Total number of shares stored from primary channel").unwrap(); + + pub static ref SHALOG_BACKUP_TRY_STORED_TOTAL: IntCounter = + register_int_counter!("shalog_backup_try_stored_total", + "Total number of shares stored from backup channel").unwrap(); + + pub static ref SHALOG_PRIMARY_STORE_FAILED_TOTAL: IntCounter = + register_int_counter!("shalog_primary_store_failed_total", + "Total number of shares failed to store from primary channel").unwrap(); + + pub static ref SHALOG_BACKUP_STORE_FAILED_TOTAL: IntCounter = + register_int_counter!("shalog_backup_store_failed_total", + "Total number of shares failed to store from backup channel").unwrap(); + } pub fn start_metrics_server() { diff --git a/nomium/shares-logger/Cargo.toml b/nomium/shares-logger/Cargo.toml index b57c9616d..63237a1a8 100644 --- a/nomium/shares-logger/Cargo.toml +++ b/nomium/shares-logger/Cargo.toml @@ -17,6 +17,7 @@ primitive-types = "0.12" lazy_static = "1.4" config = "0.13" parking_lot = "0.12" +nomium-prometheus = { path = "../prometheus" } [dev-dependencies] tokio = { version = "1.0", features = ["rt", "macros", "test-util", "time"] } \ No newline at end of file diff --git a/nomium/shares-logger/src/lib.rs b/nomium/shares-logger/src/lib.rs index dace1fe9e..6efbce279 100644 --- a/nomium/shares-logger/src/lib.rs +++ b/nomium/shares-logger/src/lib.rs @@ -21,6 +21,16 @@ use std::time::Instant; use serde::Serialize; use serde::de::DeserializeOwned; +use nomium_prometheus::{ + SHALOG_SHARES_RECEIVED_TOTAL, + SHALOG_PRIMARY_CHANNEL_SHARES_TOTAL, + SHALOG_BACKUP_CHANNEL_SHARES_TOTAL, + SHALOG_PRIMARY_TRY_STORED_TOTAL, + SHALOG_BACKUP_TRY_STORED_TOTAL, + SHALOG_PRIMARY_STORE_FAILED_TOTAL, + SHALOG_BACKUP_STORE_FAILED_TOTAL +}; + lazy_static! { static ref GLOBAL_LOGGER: ShareLogger = { let storage = ClickhouseStorage::new() @@ -107,9 +117,14 @@ impl ShareLogge impl ShareLogger { pub fn log_share(&self, share: T) { + SHALOG_SHARES_RECEIVED_TOTAL.inc(); + match self.primary_tx.try_send(share.clone()) { - Ok(_) => (), + Ok(_) => { + SHALOG_PRIMARY_CHANNEL_SHARES_TOTAL.inc(); + }, Err(TrySendError::Full(share)) | Err(TrySendError::Closed(share)) => { + SHALOG_BACKUP_CHANNEL_SHARES_TOTAL.inc(); if let Err(e) = self.backup_tx.send(share) { info!("Failed to send share to backup logger: {}", e); } @@ -136,7 +151,9 @@ async fn process_shares( tokio::select! { Some(share) = primary_rx.recv() => { info!("Processing share from primary channel"); + SHALOG_PRIMARY_TRY_STORED_TOTAL.inc(); if let Err(e) = storage.lock().await.store_share(share).await { + SHALOG_PRIMARY_STORE_FAILED_TOTAL.inc(); info!("Failed to store share: {}", e); } } @@ -146,7 +163,10 @@ async fn process_shares( backup_shares.push(share); } if !backup_shares.is_empty() { + let shares_count = backup_shares.len() as u64; + SHALOG_BACKUP_TRY_STORED_TOTAL.inc_by(shares_count); if let Err(e) = storage.lock().await.store_batch(backup_shares).await { + SHALOG_BACKUP_STORE_FAILED_TOTAL.inc_by(shares_count); info!("Failed to store backup shares: {}", e); } } diff --git a/protocols/v2/roles-logic-sv2/Cargo.toml b/protocols/v2/roles-logic-sv2/Cargo.toml index a0ed27eaf..7a5b65f86 100644 --- a/protocols/v2/roles-logic-sv2/Cargo.toml +++ b/protocols/v2/roles-logic-sv2/Cargo.toml @@ -28,6 +28,7 @@ chacha20poly1305 = { version = "0.10.1"} nohash-hasher = "0.2.0" siphasher = "1" shares-logger = { path = "../../../nomium/shares-logger" } +nomium-prometheus = { path = "../../../nomium/prometheus" } [dev-dependencies] quickcheck = "1.0.3" diff --git a/protocols/v2/roles-logic-sv2/src/channel_logic/channel_factory.rs b/protocols/v2/roles-logic-sv2/src/channel_logic/channel_factory.rs index 1a69a9abc..d29baef3b 100644 --- a/protocols/v2/roles-logic-sv2/src/channel_logic/channel_factory.rs +++ b/protocols/v2/roles-logic-sv2/src/channel_logic/channel_factory.rs @@ -870,6 +870,7 @@ impl ChannelFactory { ); info!("Calling share logging for PROXY"); shares_logger::log_share(share_log); + nomium_prometheus::CHFACT_SHARES_LOGGED_TOTAL.inc(); } } // ---- NOMIUM share_log injection ---- diff --git a/roles/Cargo.lock b/roles/Cargo.lock index 4c8f90571..8cfe9237f 100644 --- a/roles/Cargo.lock +++ b/roles/Cargo.lock @@ -2095,6 +2095,18 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "nomium-prometheus" +version = "0.1.0" +dependencies = [ + "dotenvy", + "lazy_static", + "prometheus", + "prometheus-static-metric", + "tiny_http", + "tracing", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -2646,6 +2658,7 @@ dependencies = [ "job_declaration_sv2", "mining_sv2", "nohash-hasher", + "nomium-prometheus", "shares-logger", "siphasher", "stratum-common", @@ -3015,6 +3028,7 @@ dependencies = [ "lazy_static", "log", "mining_sv2", + "nomium-prometheus", "once_cell", "parking_lot", "primitive-types", @@ -3539,9 +3553,8 @@ dependencies = [ "key-utils", "lazy_static", "network_helpers_sv2", + "nomium-prometheus", "once_cell", - "prometheus", - "prometheus-static-metric", "rand", "reqwest", "roles_logic_sv2", @@ -3551,7 +3564,6 @@ dependencies = [ "shares-logger", "stratum-common", "sv1_api", - "tiny_http", "tokio", "tokio-util", "tracing", diff --git a/roles/translator/Cargo.toml b/roles/translator/Cargo.toml index 4dd99d781..cd1474b2b 100644 --- a/roles/translator/Cargo.toml +++ b/roles/translator/Cargo.toml @@ -48,10 +48,8 @@ reqwest = { version = "0.12", features = ["json", "rustls-tls"], default-feature shares-logger = { path = "../../nomium/shares-logger" } dotenvy = "0.15" tracing-appender = "0.2" -prometheus = "0.13" -prometheus-static-metric = "0.5" lazy_static = "1.5" -tiny_http = "0.12" +nomium-prometheus = { path = "../../nomium/prometheus" } [dev-dependencies] sha2 = "0.10.6" diff --git a/roles/translator/src/lib/mod.rs b/roles/translator/src/lib/mod.rs index 3fc5fcd77..1286a6b60 100644 --- a/roles/translator/src/lib/mod.rs +++ b/roles/translator/src/lib/mod.rs @@ -1,4 +1,4 @@ -pub mod metrics; +pub use nomium_prometheus as metrics; use async_channel::{bounded, unbounded}; use futures::FutureExt; diff --git a/roles/translator/src/lib/proxy/bridge.rs b/roles/translator/src/lib/proxy/bridge.rs index 9d1ca85d4..350a7f298 100644 --- a/roles/translator/src/lib/proxy/bridge.rs +++ b/roles/translator/src/lib/proxy/bridge.rs @@ -1,4 +1,4 @@ -use crate::metrics::{SHARES_UPSTREAM_TARGET_MEET, SHARES_DOWNSTREAM_TARGET_MEET}; +use crate::metrics::{SHARES_UPSTREAM_TARGET_MEET, SHARES_DOWNSTREAM_TARGET_MEET, TPROXY_SHARES_REJECTED_TOTAL}; use async_channel::{Receiver, Sender}; use roles_logic_sv2::{ channel_logic::channel_factory::{ExtendedChannelKind, ProxyExtendedChannelFactory, Share}, @@ -250,6 +250,7 @@ impl Bridge { "Submit share error {:?}", std::str::from_utf8(&e.error_code.to_vec()[..]) ); + TPROXY_SHARES_REJECTED_TOTAL.inc(); } Ok(Ok(OnNewShare::SendSubmitShareUpstream((share, _)))) => { info!("SHARE MEETS UPSTREAM TARGET");