1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
use crate::{Capacity, Timestamp, Uint64};
use ckb_types::U256;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
/// Overview data structure aggregating system and mining information
/// for the CKB-TUI Terminal module.
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct Overview {
/// System information, including hardware and OS metrics.
pub sys: SysInfo,
/// Mining information, covering hash power, difficulty.
pub mining: MiningInfo,
/// Transaction pool information.
pub pool: TerminalPoolInfo,
/// Cells information.
pub cells: CellsInfo,
/// Network peer latency information.
pub network: NetworkInfo,
/// CKB node version.
///
/// Example: "version": "0.34.0 (f37f598 2020-07-17)"
pub version: String,
}
/// System’s information.
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct SysInfo {
/// global system information
pub global: Global,
/// Returns the total ckb CPU usage (in %).
/// Notice that it might be bigger than 100 if run on a multi-core machine.
pub cpu_usage: f32,
/// Returns number of bytes ckb read and written to disk.
pub disk_usage: DiskUsage,
/// Returns the memory ckb usage (in bytes).
pub memory: u64,
/// Returns the virtual memory usage (in bytes).
pub virtual_memory: u64,
}
/// Global system information
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct Global {
/// Returns the RAM size in bytes.
pub total_memory: u64,
/// Returns the amount of used RAM in bytes.
pub used_memory: u64,
/// Returns “global” CPUs usage (aka the addition of all the CPUs).
pub global_cpu_usage: f32,
/// Returns disks information.
pub disks: Vec<Disk>,
/// Returns networks information.
pub networks: Vec<Network>,
}
/// Struct containing a disk information.
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct Disk {
/// Returns the total disk size, in bytes.
pub total_space: u64,
/// Returns the available disk size, in bytes.
pub available_space: u64,
/// Returns true if the disk is removable.
pub is_removable: bool,
}
/// Struct containing read and written bytes.
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, Default)]
pub struct DiskUsage {
/// Total number of written bytes.
pub total_written_bytes: u64,
/// Number of written bytes since the last refresh.
pub written_bytes: u64,
/// Total number of read bytes.
pub total_read_bytes: u64,
/// Number of read bytes since the last refresh.
pub read_bytes: u64,
}
/// Getting volume of received and transmitted data.
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct Network {
/// Returns network interface name
pub interface_name: String,
/// Returns the number of received bytes since the last refresh.
pub received: u64,
/// Returns the total number of received bytes.
pub total_received: u64,
/// Returns the number of transmitted bytes since the last refresh.
pub transmitted: u64,
/// Returns the total number of transmitted bytes.
pub total_transmitted: u64,
}
/// Mining information structure for the CKB-TUI Terminal module.
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct MiningInfo {
/// Current network difficulty, represented as a U256 integer.
#[schemars(schema_with = "crate::json_schema::u256_json_schema")]
pub difficulty: U256,
/// Current network hash rate, represented as a U256 integer (in hashes per second).
/// This approximates the total computational power of the mining network.
#[schemars(schema_with = "crate::json_schema::u256_json_schema")]
pub hash_rate: U256,
}
/// Transaction pool information.
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct TerminalPoolInfo {
/// Count of transactions in the pending state.
///
/// The pending transactions must be proposed in a new block first.
pub pending: Uint64,
/// Count of transactions in the proposed state.
///
/// The proposed transactions are ready to be committed in the new block after the block
/// `tip_hash`.
pub proposed: Uint64,
/// Count of orphan transactions.
///
/// An orphan transaction has an input cell from the transaction which is neither in the chain
/// nor in the transaction pool.
pub orphan: Uint64,
/// Count of committing transactions.
///
/// The Committing transactions refer to transactions that have been packaged into the
/// block_template and are awaiting mining into a block.
pub committing: Uint64,
/// Total count of recent reject transactions by pool
pub total_recent_reject_num: Uint64,
/// Total size of transactions bytes in the pool of all the different kinds of states (excluding orphan transactions).
pub total_tx_size: Uint64,
/// Total consumed VM cycles of all the transactions in the pool (excluding orphan transactions).
pub total_tx_cycles: Uint64,
/// Total limit on the size of transactions in the tx-pool
pub max_tx_pool_size: Uint64,
/// Last updated time. This is the Unix timestamp in milliseconds.
pub last_txs_updated_at: Timestamp,
}
/// Individual peer connection information.
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct PeerInfo {
/// Unique identifier for peer
pub peer_id: usize,
/// Whether this is an outbound connection
pub is_outbound: bool,
/// Round-trip time in milliseconds for this peer (0 if not available)
pub latency_ms: Uint64,
/// Peer address
pub address: String,
}
/// Network peer latency information.
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct NetworkInfo {
/// Total number of connected peers
pub connected_peers: Uint64,
/// Number of outbound connections
pub outbound_peers: Uint64,
/// Number of inbound connections
pub inbound_peers: Uint64,
/// List of individual peer information with their latencies
pub peers: Vec<PeerInfo>,
}
/// Cells information.
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct CellsInfo {
/// estimate live cells total num
pub estimate_live_cells_num: Uint64,
/// The total occupied capacities currently in the CKB
pub total_occupied_capacities: Capacity,
}
impl Default for CellsInfo {
fn default() -> Self {
Self {
estimate_live_cells_num: 0u64.into(),
total_occupied_capacities: 0u64.into(),
}
}
}
impl Default for TerminalPoolInfo {
fn default() -> Self {
Self {
pending: 0u64.into(),
proposed: 0u64.into(),
orphan: 0u64.into(),
committing: 0u64.into(),
total_recent_reject_num: 0u64.into(),
total_tx_size: 0u64.into(),
total_tx_cycles: 0u64.into(),
max_tx_pool_size: 0u64.into(),
last_txs_updated_at: 0u64.into(),
}
}
}
impl Default for MiningInfo {
fn default() -> Self {
Self {
difficulty: U256::zero(),
hash_rate: U256::zero(),
}
}
}
impl Default for SysInfo {
fn default() -> Self {
Self {
global: Global::default(),
cpu_usage: 0.0,
memory: 0,
virtual_memory: 0,
disk_usage: DiskUsage::default(),
}
}
}
impl Default for Global {
fn default() -> Self {
Self {
total_memory: 0,
used_memory: 0,
global_cpu_usage: 0.0,
disks: Vec::new(),
networks: Vec::new(),
}
}
}
impl Default for PeerInfo {
fn default() -> Self {
Self {
peer_id: 0,
is_outbound: false,
latency_ms: 0u64.into(),
address: String::new(),
}
}
}
impl Default for NetworkInfo {
fn default() -> Self {
Self {
connected_peers: 0u64.into(),
outbound_peers: 0u64.into(),
inbound_peers: 0u64.into(),
peers: Vec::new(),
}
}
}