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;
14pub mod prometheus_metrics;
15pub mod routes;
16pub mod server;
17pub mod snapshot_cache;
18pub mod sv1;
19
20pub use client::{
21 ExtendedChannelInfo, StandardChannelInfo, Sv2ClientInfo, Sv2ClientMetadata,
22 Sv2ClientsMonitoring, Sv2ClientsSummary,
23};
24pub use http_server::{
25 ErrorResponse, HealthResponse, MonitoringServer, RootResponse, ServerChannelsResponse,
26 ServerResponse, Sv1ClientsResponse, Sv2ClientChannelsResponse, Sv2ClientResponse,
27 Sv2ClientsResponse,
28};
29pub use server::{
30 ServerExtendedChannelInfo, ServerInfo, ServerMonitoring, ServerStandardChannelInfo,
31 ServerSummary,
32};
33pub use snapshot_cache::{MonitoringSnapshot, SnapshotCache};
34pub use sv1::{Sv1ClientInfo, Sv1ClientsMonitoring, Sv1ClientsSummary};
35
36use serde::{Deserialize, Serialize};
37use utoipa::ToSchema;
38
39/// Global statistics from `/api/v1/global` endpoint
40///
41/// Fields are `Option` to distinguish "not monitored" (`None`) from "monitored but empty" (`Some`
42/// with zeros).
43///
44/// Typical configurations:
45/// - **Pool/JDC**: `server` and `sv2_clients` are `Some`, `sv1_clients` is `None`
46/// - **tProxy**: `server` and `sv1_clients` are `Some`, `sv2_clients` is `None`
47#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
48pub struct GlobalInfo {
49 /// Server (upstream) summary - `None` if server monitoring is not enabled
50 pub server: Option<ServerSummary>,
51 /// Sv2 clients (downstream) summary - `None` if Sv2 client monitoring is not enabled (e.g.,
52 /// tProxy)
53 pub sv2_clients: Option<Sv2ClientsSummary>,
54 /// Sv1 clients summary - `None` if Sv1 monitoring is not enabled (e.g., Pool/JDC)
55 pub sv1_clients: Option<Sv1ClientsSummary>,
56 /// Uptime in seconds since the application started
57 pub uptime_secs: u64,
58}