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::{
33    match_discovered_miners_to_downstreams_by_worker_and_port, DiscoveredMiner, MinerTelemetry,
34    MinerTelemetryCollector, MinerTelemetryDownstreamMatches, MinerTelemetryStatus,
35};
36pub use server::{
37    ServerExtendedChannelInfo, ServerInfo, ServerMonitoring, ServerStandardChannelInfo,
38    ServerSummary,
39};
40pub use snapshot_cache::{MonitoringSnapshot, SnapshotCache};
41pub use sv1::{Sv1ClientInfo, Sv1ClientsMonitoring, Sv1ClientsSummary};
42
43use serde::{Deserialize, Serialize};
44use utoipa::ToSchema;
45
46/// Global statistics from `/api/v1/global` endpoint
47///
48/// Fields are `Option` to distinguish "not monitored" (`None`) from "monitored but empty" (`Some`
49/// with zeros).
50///
51/// Typical configurations:
52/// - **Pool/JDC**: `server` and `sv2_clients` are `Some`, `sv1_clients` is `None`
53/// - **tProxy**: `server` and `sv1_clients` are `Some`, `sv2_clients` is `None`
54#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
55pub struct GlobalInfo {
56    /// Server (upstream) summary - `None` if server monitoring is not enabled
57    pub server: Option<ServerSummary>,
58    /// Sv2 clients (downstream) summary - `None` if Sv2 client monitoring is not enabled (e.g.,
59    /// tProxy)
60    pub sv2_clients: Option<Sv2ClientsSummary>,
61    /// Sv1 clients summary - `None` if Sv1 monitoring is not enabled (e.g., Pool/JDC)
62    pub sv1_clients: Option<Sv1ClientsSummary>,
63    /// Uptime in seconds since the application started
64    pub uptime_secs: u64,
65}