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
//! The per-second, per-service sample the home-page cards graph (#6642).
//!
//! Why: #6641 gave the console a 10-minute window of WHOLE-MACHINE samples plus
//! a log of the moments a service changed state. The owner's ruling for the home
//! page needs a third thing: a bar per second per service, showing that
//! service's own CPU. A transition log cannot draw it (it records changes, not
//! levels) and the host sample cannot either (it is one number for the whole
//! machine).
//!
//! Why `cpu_pct` and `rss_bytes` are `Option` and never `0` for an absent
//! service: a service that is not installed, is on-demand and idle, or whose
//! process the console could not identify has NO measurement. Rendering that as
//! zero draws a flat idle bar, which is visually identical to a healthy service
//! doing nothing — the one reading the operator must be able to tell apart.
//! `None` is the honest answer and the UI renders it as a gap.
//!
//! Why memory rides on the SAME sample as CPU (#6773): the owner's ruling puts
//! a CPU graph and a memory graph side by side in every service row. A second
//! sampler, a second ring or a second event would each let the two graphs show
//! different seconds, which is the one way a side-by-side pair can lie. One
//! sample, one tick, one ring, one event.
//!
//! What: [`ServiceSample`] is one service at one instant; [`ServiceSampleBatch`]
//! is the whole roster at one instant, which is what the sampler produces per
//! tick, what the `services` SSE event carries, and what
//! [`MachineHistory::record_service_samples`] folds into the per-service rings.
//! [`SERVICE_HISTORY_CAPACITY`] sizes those rings to the same 10-minute window
//! the host ring covers.
//! Test: `a_sample_serialises_the_shape_the_ui_reads`,
//! `an_absent_cpu_serialises_as_null`, `an_absent_memory_serialises_as_null`,
//! `a_batch_names_its_services`.
//!
//! [`MachineHistory::record_service_samples`]:
//! crate::machine_history::MachineHistory::record_service_samples
use ;
use HOST_HISTORY_CAPACITY;
use crateServiceStatus;
/// Samples retained per service — the same 10-minute window the host ring holds.
///
/// Why: the home-page card draws the host graph and the service graph on one
/// x-axis. Two different capacities would put two different spans side by side
/// with nothing saying so, so this is defined as the host constant rather than
/// as a second number that could drift from it.
/// What: [`HOST_HISTORY_CAPACITY`] — 600 points at the 1 s cadence.
/// Test: `the_service_window_matches_the_host_window`.
pub const SERVICE_HISTORY_CAPACITY: usize = HOST_HISTORY_CAPACITY;
/// One service's state, CPU and memory at one instant (#6642, #6773).
///
/// Why: the row needs all three together. CPU alone cannot say whether a
/// missing bar means "idle" or "stopped", status alone cannot draw a graph, and
/// a memory figure sampled on a different tick than the CPU figure would put two
/// different seconds beside each other in one row.
/// What: the service id (the same `ServiceInfo::id` the services route serves,
/// so the UI joins the two by string), the status the poller last detected, the
/// CPU percentage, and the resident-memory figure in bytes — each `None`
/// whenever no measurement was taken. The percentage follows `sysinfo`'s
/// convention: `100.0` is one fully-saturated core, so a multi-threaded daemon
/// can exceed 100.
/// Test: `a_sample_serialises_the_shape_the_ui_reads`,
/// `an_absent_cpu_serialises_as_null`, `an_absent_memory_serialises_as_null`.
/// The whole service roster at one instant (#6642).
///
/// Why one batch rather than N independent samples: the graphs are read
/// together, and a client that received six separate events would have to
/// re-group them by timestamp to draw one column. Batching also means one
/// broadcast send per tick instead of six.
/// What: the wall-clock second the batch was taken plus one [`ServiceSample`]
/// per registered service, in the order the poller reported them (the UI sorts;
/// see #6642 PR-B).
/// Test: `a_batch_names_its_services`.