Skip to content

Repository files navigation

SystemInfoKit

SystemInfoKit provides macOS/iOS system information.

  • CPU Usage
  • Memory Pressure
  • Storage Capacity
  • Battery Status
  • Network Connectivity

Requirements

  • Development with Xcode 26.3+
  • Written in Swift 6.2
  • Compatible with macOS 13.0+, iOS 16.0+

Installation

SystemInfoKit supports Swift Package Manager.

Usage

import SystemInfoKit

// Get all system info per 3 seconds
let observer = SystemInfoObserver.shared

Task {
    for await systemInfoBundle in observer.systemInfoStream() {
        Swift.print(systemInfoBundle)
    }
}
observer.startMonitoring(monitorInterval: 3.0)

// Finish to get system info
observer.stopMonitoring()

Broadcasting to multiple consumers

systemInfoStream() returns a single-consumer AsyncStream. If two for await loops iterate the same stream, they will compete for values rather than each receiving every update. SystemInfoKit intentionally does not own the multi-broadcast concern — wrap the stream with swift-async-algorithms' share() on the consumer side.

import AsyncAlgorithms
import SystemInfoKit

let observer = SystemInfoObserver.shared
let shared = observer.systemInfoStream().share()

Task {
    for await systemInfoBundle in shared {
        Swift.print("subscriber A:", systemInfoBundle)
    }
}
Task {
    for await systemInfoBundle in shared {
        Swift.print("subscriber B:", systemInfoBundle)
    }
}
observer.startMonitoring(monitorInterval: 3.0)

Reading the latest snapshot synchronously

If you only need the most recent values without subscribing to the stream, use currentSystemInfo:

let snapshot = observer.currentSystemInfo
Swift.print(snapshot.cpuInfo, snapshot.memoryInfo)

Fields corresponding to a SystemInfoType that has not yet been updated (or has been disabled via toggleActivation) remain nil.

Enabling / disabling specific info types

Use toggleActivation to turn individual SystemInfoType values on or off at runtime. Only the types whose state actually changes are touched — other entries in the bundle keep their existing measurements.

observer.toggleActivation(requests: [
    .battery: false,  // stop collecting battery info
    .network: true,   // resume collecting network info
])

When the activation state changes, the corresponding fields in the bundle are updated immediately and the new bundle is re-emitted through systemInfoStream():

  • Newly disabled types → the field is set to nil.
  • Newly enabled types → the field is filled with a zero placeholder (a localized XxxInfo with default values), so subscribers see a non-nil value right away. The real measurement replaces it on the next monitoring tick.
  • Types whose activation did not change are left untouched (their last measured value is preserved).

If a type is disabled, update() is skipped at the next monitoring tick and its field stays nil until it is enabled again.

Sample Output

CPU:  7.5%
    System:  2.9%
    User:  4.6%
    Idle: 92.5%
Memory: 72.9%
    Pressure: 33.1%
    App:  6.4 GB
    Wired:  1.8 GB
    Compressed:  3.5 GB
Storage: 58.7% used
    584.13 GB / 994.66 GB
Battery:  98.2%
    Power Source: 140W USB-C Power Adapter
    Max Capacity:  95.7%
    Cycle Count: 7
    Temperature: 30.2°C
Network: Ethernet
    Local IP: 192.0.2.1
    Upload:  50.7 kB/s
    Download:   1.7 kB/s

Max Capacity is the battery's full charge capacity as a fraction of the capacity it was designed to hold, read straight from IOKit. It is not the Maximum Capacity that System Settings shows, which macOS appears to smooth or cache rather than read live — on the two machines measured so far the two figures differ by +2.9 and −4.2 points, in opposite directions, and no key in IOKit reproduces the System Settings number. MeasuredValues/README.md records the measurements.

Supported languages

  • Chinese, Simplified
  • Chinese, Traditional
  • English (primary)
  • French
  • German
  • Japanese
  • Korean
  • Russian
  • Spanish
  • Vietnamese

Copyright and License

Copyright 2020 Takuto Nakamura

Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0

About

SystemInfoKit provides macOS/iOS system information (CPU usage, Memory performance, Battery state, Storage capacity, and Network connection).

Topics

Resources

Stars

Watchers

Forks

Releases

Contributors

Languages