Processor, memory and disk

What this Mac, its extra Spaces and your other computers use: one snapshot, a stream of changes and the low-disk warning.

Spaces.resources returns one ResourcesSnapshot: this Mac's cores, memory and free disk, each extra Space's allocation, use and cost on this Mac's disk, and the summary each of your other computers published. Spaces.watch_resources calls a ResourcesListener with a snapshot, then only the entries that changed by more than 1 point or 256 MB, and a LowDisk event when the free-disk level changes. Numbers only: counts, bytes and percentages.

Resources#

Methods of Spaces.

Spaces.resources#

What this Mac, its extra Spaces and your other computers use now: processor, memory and disk, as one snapshot (a few seconds old at most). With visible, the call also says a window shows the numbers for the next 30 seconds, so the runtime samples every 10 seconds instead of every 5 minutes: call it every 10 seconds while a window is visible and stop when it is hidden.

async def resources(self, visible: bool) -> ResourcesSnapshot
ParameterTypeDefault
visibleboolrequired

Returns ResourcesSnapshot · Async · Raises CuaError

Spaces.watch_resources#

The same numbers as events for listener: a snapshot first, then an update with only the entries that changed by more than 1 point or 256 MB, and LowDisk whenever the warning level changes. Reopens by itself if the daemon restarts (the snapshot comes again). Stop it with ResourcesWatch.stop.

def watch_resources(self, visible: bool, listener: ResourcesListener) -> ResourcesWatch
ParameterTypeDefault
visibleboolrequired
listenerResourcesListenerrequired

Returns ResourcesWatch

ResourcesSnapshot record#

One sample of everything.

Returned by Spaces.resources.

FieldTypeDefaultDescription
sequenceu64Grows by one per sample.
sampled_at_ms / sampledAtMsu64Unix ms.
this_mac / thisMacComputerResourcesThis Mac.
spacesVec<SpaceResources>Extra Spaces on this Mac.
computersVec<ComputerResources>Your other computers, from the summaries they published.
warningDiskWarningthis_mac.warning, for the menu bar.

ComputerResources record#

A computer: this Mac, or one of your other computers (from the summary it published).

FieldTypeDefaultDescription
idStringthis-mac, or the relay machine id.
nameStringDisplay name (empty for this Mac).
onlineboolReachable now (always true for this Mac).
sampled_at_ms / sampledAtMsu64When the computer measured this, unix ms (another computer's can be minutes old).
cpu_count / cpuCountu32Processor cores.
cpu_percent / cpuPercentf64Busy now, 0 to 100.
load_average_1m / loadAverage1mf641-minute load average.
memory_total / memoryTotalu64Memory size, bytes.
memory_used / memoryUsedu64Memory in use, bytes (without reclaimable cache).
disk_total / diskTotalu64Size of the volume that holds Spaces, bytes.
disk_free / diskFreeu64Free bytes on it.
spaces_count / spacesCountu32Extra Spaces on it.
spaces_running / spacesRunningu32Of those, running.
spaces_cpu_allocated / spacesCpuAllocatedu32Cores given to the running ones.
spaces_memory_allocated / spacesMemoryAllocatedu64Memory given to the running ones, bytes.
spaces_memory_used / spacesMemoryUsedu64Memory the running guests report in use, bytes.
spaces_disk_bytes / spacesDiskBytesu64Bytes all its extra Spaces take on it.
spaces_disk_exact / spacesDiskExactboolFalse when some Space's disk could only be estimated.
warningDiskWarningThe low-disk signal.

SpaceResources record#

One extra Space on this Mac.

FieldTypeDefaultDescription
idStringlocal:<name>.
power_state / powerStateStringrunning, stopped, suspended, or empty when unknown.
cpu_allocated / cpuAllocatedu32Cores given to it (0: unknown).
memory_allocated / memoryAllocatedu64Memory given to it, bytes (0: unknown).
disk_allocated / diskAllocatedu64Its disk's size limit, bytes (0: unknown).
usageOption<GuestUsage>The guest's own numbers; absent while it is off or unreachable.
disk_on_host / diskOnHostOption<DiskOnHost>What it costs this Mac; absent for a container.

GuestUsage record#

What SystemService.Metrics reports from inside a Space.

FieldTypeDefaultDescription
cpu_count / cpuCountu32Cores the guest sees.
cpu_percent / cpuPercentf64Busy now, 0 to 100.
load_average_1m / loadAverage1mf641-minute load average.
memory_used / memoryUsedu64Memory in use, bytes.
memory_total / memoryTotalu64Memory size, bytes.
memory_limited / memoryLimitedboolmemory_total is the guest's own limit.
disk_used / diskUsedu64Disk in use, bytes.
disk_total / diskTotalu64Disk size, bytes.
disk_limited / diskLimitedbooldisk_total is the guest's own disk.

DiskOnHost record#

What a Space costs this computer's disk, as opposed to what the guest sees.

FieldTypeDefaultDescription
bytesOption<u64>Bytes only this Space holds (what deleting it frees); absent when they could not be measured.
allocatedu64Blocks its files occupy, clones counted in full: an upper bound.
shares_space / sharesSpaceboolPart of it is shared with other copies.

DiskWarning record#

The low-disk signal for the app and the menu bar.

FieldTypeDefaultDescription
levelDiskLevelHow low it is.
freeu64Free bytes on the volume that holds Spaces.
totalu64Size of that volume.
thresholdu64The line that was crossed (0 when ok).

DiskLevel enum#

How low the free disk is.

DiskLevel.OK
DiskLevel.LOW
DiskLevel.CRITICAL
VariantDescription
OkPlenty.
LowUnder 50 GB or 15% of the volume, whichever line is higher (the line never rises above 100 GB).
CriticalUnder the floor where creating a Space already fails (5 GiB).

ResourcesUpdate record#

What changed since the last event: only entries that moved by more than 1 point or 256 MB. Replace entries by id; drop the removed ids.

FieldTypeDefaultDescription
sequenceu64The sample it brings you to.
sampled_at_ms / sampledAtMsu64Unix ms.
this_mac / thisMacOption<ComputerResources>This Mac, when it changed.
spacesVec<SpaceResources>Extra Spaces that changed or appeared.
computersVec<ComputerResources>Other computers that changed or appeared.
removedVec<String>Ids (Spaces or computers) that are gone.

ResourcesEvent enum#

What Spaces.watch_resources reports.

ResourcesEvent.SNAPSHOT(snapshot: ResourcesSnapshot)
ResourcesEvent.UPDATE(update: ResourcesUpdate)
ResourcesEvent.LOW_DISK(warning: DiskWarning)
VariantDescription
SnapshotEverything, at the start (and again after a reconnect). Fields: snapshot: ResourcesSnapshot
UpdateOnly what changed. Fields: update: ResourcesUpdate
LowDiskThe low-disk level changed (including back to ok). Fields: warning: DiskWarning

ResourcesListener#

Receives ResourcesEvents from Spaces.watch_resources, in order. Called on an SDK worker thread; return quickly.

You implement ResourcesListener and pass it to the SDK (a callback interface): subclass it in Python, implement the interface in TypeScript, the ResourcesListener protocol in Swift, the interface in Kotlin and the trait in Rust.

MethodDescription
on_eventSomething moved.

ResourcesListener.on_event#

Something moved.

def on_event(self, event: ResourcesEvent) -> None
ParameterTypeDefault
eventResourcesEventrequired

ResourcesWatch#

A running Spaces.watch_resources: tell it whether a window shows the numbers, and stop it when done. Dropping it also stops it.

Returned by Spaces.watch_resources.

MethodDescription
set_visibleWhether a window shows the numbers: visible watchers are sampled every 10 seconds, hidden ones every 5 minutes (and still hear LowDisk, for the menu bar).
AccessorReturnsDescription
stop()Ends the watch. No event is delivered after this returns.

ResourcesWatch.set_visible#

Whether a window shows the numbers: visible watchers are sampled every 10 seconds, hidden ones every 5 minutes (and still hear LowDisk, for the menu bar).

def set_visible(self, visible: bool) -> None
ParameterTypeDefault
visibleboolrequired

All items#

11 items, across this page and its subpages, grouped by page (each item's section is on its page). Methods are listed on their object.

Processor, memory and disk: ComputerResources, DiskLevel, DiskOnHost, DiskWarning, GuestUsage, ResourcesEvent, ResourcesListener, ResourcesSnapshot, ResourcesUpdate, ResourcesWatch, SpaceResources