Skip to main content

stratum_apps/monitoring/
mod.rs

1//! Monitoring system for SV2 applications.
2//!
3//! Provides HTTP JSON API and Prometheus metrics for monitoring.
4//! Read-only - does not modify any state.
5//!
6//! ## Architecture
7//!
8//! - **Server**: The upstream connection (pool, JDS) - typically one per app
9//! - **Clients**: Downstream connections (miners) - multiple per app
10//! - **SV1 clients**: Legacy SV1 connections (Translator only)
11
12pub mod client;
13pub mod http_server;
14#[cfg(feature = "asic-rs-telemetry")]
15pub mod miner_telemetry;
16pub mod prometheus_metrics;
17pub mod routes;
18pub mod server;
19pub mod snapshot_cache;
20pub mod sv1;
21
22pub use client::{
23    ExtendedChannelInfo, StandardChannelInfo, Sv2ClientInfo, Sv2ClientMetadata,
24    Sv2ClientsMonitoring, Sv2ClientsSummary,
25};
26pub use http_server::{
27    ErrorResponse, HealthResponse, MonitoringServer, RootResponse, ServerChannelsResponse,
28    ServerResponse, Sv1ClientsResponse, Sv2ClientChannelsResponse, Sv2ClientResponse,
29    Sv2ClientsResponse,
30};
31#[cfg(feature = "asic-rs-telemetry")]
32pub use miner_telemetry::{MinerTelemetry, MinerTelemetryCollector};
33pub use server::{
34    ServerExtendedChannelInfo, ServerInfo, ServerMonitoring, ServerStandardChannelInfo,
35    ServerSummary,
36};
37pub use snapshot_cache::{MonitoringSnapshot, SnapshotCache};
38pub use sv1::{Sv1ClientInfo, Sv1ClientsMonitoring, Sv1ClientsSummary};
39
40use serde::{Deserialize, Serialize};
41use utoipa::ToSchema;
42
43/// Global statistics from `/api/v1/global` endpoint
44///
45/// Fields are `Option` to distinguish "not monitored" (`None`) from "monitored but empty" (`Some`
46/// with zeros).
47///
48/// Typical configurations:
49/// - **Pool/JDC**: `server` and `sv2_clients` are `Some`, `sv1_clients` is `None`
50/// - **tProxy**: `server` and `sv1_clients` are `Some`, `sv2_clients` is `None`
51#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
52pub struct GlobalInfo {
53    /// Server (upstream) summary - `None` if server monitoring is not enabled
54    pub server: Option<ServerSummary>,
55    /// Sv2 clients (downstream) summary - `None` if Sv2 client monitoring is not enabled (e.g.,
56    /// tProxy)
57    pub sv2_clients: Option<Sv2ClientsSummary>,
58    /// Sv1 clients summary - `None` if Sv1 monitoring is not enabled (e.g., Pool/JDC)
59    pub sv1_clients: Option<Sv1ClientsSummary>,
60    /// Uptime in seconds since the application started
61    pub uptime_secs: u64,
62}