Rolling counters for the Tier 1 monitoring agent.
The aggregator holds in-memory state only. Each sampler produces a Sample
once per tick (default 2 s); apply_sample updates the counters with that
sample's effect on the running totals. The counters are serialised to
JSON by the pusher and POSTed to the allocator.
There is no per-sample storage. Crashing the process loses at most the
last push_interval_seconds of counter state.
Attributes
GPU_ACTIVE_UTIL_THRESHOLD = 5
module-attribute
SUBJECT_FIELD = 'seconds_in_subject_software'
module-attribute
WINDOW_BUCKETS = ('subject', 'terminal', 'browser', 'other')
module-attribute
Classes
Sample(ts, sample_interval_seconds, active_window_bucket, gpu_util_pct, vram_mb, processes_seen, max_labeled_frames, training_epochs_completed, training_final_loss)
dataclass
One tick of input from the four samplers.
Attributes
active_window_bucket
instance-attribute
gpu_util_pct
instance-attribute
max_labeled_frames
instance-attribute
processes_seen
instance-attribute
sample_interval_seconds
instance-attribute
training_epochs_completed
instance-attribute
training_final_loss
instance-attribute
vram_mb
instance-attribute
SessionCounters(session_started_at, sample_count=0, seconds_in_subject_software=0, seconds_in_terminal=0, seconds_in_browser=0, seconds_in_other=0, gpu_active_seconds=0, gpu_util_peak=0, vram_used_peak_mb=0, seconds_to_first_sleap_label=None, seconds_to_first_sleap_train=None, seconds_to_first_sleap_track=None, max_labeled_frames=0, training_epochs_completed=0, training_final_loss=None)
dataclass
Attributes
gpu_active_seconds = 0
class-attribute
instance-attribute
gpu_util_peak = 0
class-attribute
instance-attribute
max_labeled_frames = 0
class-attribute
instance-attribute
sample_count = 0
class-attribute
instance-attribute
seconds_in_browser = 0
class-attribute
instance-attribute
seconds_in_other = 0
class-attribute
instance-attribute
seconds_in_subject_software = 0
class-attribute
instance-attribute
seconds_in_terminal = 0
class-attribute
instance-attribute
seconds_to_first_sleap_label = None
class-attribute
instance-attribute
seconds_to_first_sleap_track = None
class-attribute
instance-attribute
seconds_to_first_sleap_train = None
class-attribute
instance-attribute
session_started_at
instance-attribute
training_epochs_completed = 0
class-attribute
instance-attribute
training_final_loss = None
class-attribute
instance-attribute
vram_used_peak_mb = 0
class-attribute
instance-attribute
Functions:
apply_sample(c, s)
Source code in packages/client/src/lablink_client_service/monitoring/aggregator.py
| def apply_sample(c: SessionCounters, s: Sample) -> None:
c.sample_count += 1
bucket = (
s.active_window_bucket if s.active_window_bucket in WINDOW_BUCKETS else "other"
)
attr = SUBJECT_FIELD if bucket == "subject" else f"seconds_in_{bucket}"
setattr(c, attr, getattr(c, attr) + s.sample_interval_seconds)
if s.gpu_util_pct > GPU_ACTIVE_UTIL_THRESHOLD:
c.gpu_active_seconds += s.sample_interval_seconds
if s.gpu_util_pct > c.gpu_util_peak:
c.gpu_util_peak = s.gpu_util_pct
if s.vram_mb > c.vram_used_peak_mb:
c.vram_used_peak_mb = s.vram_mb
elapsed = int((s.ts - c.session_started_at).total_seconds())
if "sleap-label" in s.processes_seen and c.seconds_to_first_sleap_label is None:
c.seconds_to_first_sleap_label = elapsed
if "sleap-train" in s.processes_seen and c.seconds_to_first_sleap_train is None:
c.seconds_to_first_sleap_train = elapsed
if "sleap-track" in s.processes_seen and c.seconds_to_first_sleap_track is None:
c.seconds_to_first_sleap_track = elapsed
if s.max_labeled_frames is not None and s.max_labeled_frames > c.max_labeled_frames:
c.max_labeled_frames = s.max_labeled_frames
if (
s.training_epochs_completed is not None
and s.training_epochs_completed > c.training_epochs_completed
):
c.training_epochs_completed = s.training_epochs_completed
if s.training_final_loss is not None:
c.training_final_loss = s.training_final_loss
|
new_counters(session_started_at)
Source code in packages/client/src/lablink_client_service/monitoring/aggregator.py
| def new_counters(session_started_at: datetime) -> SessionCounters:
return SessionCounters(session_started_at=session_started_at)
|