Report process-level system metrics (memory, CPU, file descriptors) to Swift Metrics
180
stars
106
commits
Swift
primary language
Sep 7, 2026
updated
A Swift library for reporting process-level system metrics (memory, CPU, file descriptors) to Swift Metrics.
Swift System Metrics provides a type that periodically collects process-level system metrics and reports them to the Swift Metrics factory.
This package is designed to be run in tools and applications directly and is not expected to be used from libraries. If you'd like to report additional metrics from your library, use Swift Metrics directly.
Add the dependency to your Package.swift:
.package(url: "https://github.com/apple/swift-system-metrics", from: "1.0.0")
Add the library dependency to your target:
.product(name: "SystemMetrics", package: "swift-system-metrics")
Import and use in your code:
import SystemMetrics
import ServiceLifecycle
import Metrics
import Logging
@main
struct Application {
static func main() async throws {
// Create a logger, or use one of the existing loggers
let logger = Logger(label: "Application")
let metrics = MyMetricsBackendImplementation()
MetricsSystem.bootstrap(metrics)
let service = FooService()
// Create the monitor
let systemMetricsMonitor = SystemMetricsMonitor(logger: logger)
// Create the service
let serviceGroup = ServiceGroup(
services: [service, systemMetricsMonitor],
gracefulShutdownSignals: [.sigint],
cancellationSignals: [.sigterm],
logger: logger
)
try await serviceGroup.run()
}
}
The monitor collects and reports the following metrics as gauges:
process_virtual_memory_bytesprocess_resident_memory_bytesprocess_start_time_secondsprocess_cpu_seconds_totalprocess_max_fdsprocess_open_fdsprocess_thread_countprocess_page_faults_minor_totalprocess_page_faults_major_totalIf your metrics backend expects different label names, use MappingMetricsFactory from Swift Metrics to rename labels
without modifying the library itself. See the
Getting Started
guide for a complete example.
The library is supported on macOS and Linux.
| Component | macOS | Linux |
|---|---|---|
| SystemMetrics | β 13+ | β |
Comprehensive documentation is hosted on the Swift Package Index.
Swift
98.2%
Shell
1.8%
Report process-level system metrics (memory, CPU, file descriptors) to Swift Metrics
180
stars
106
commits
Swift
primary language
Sep 7, 2026
updated
A Swift library for reporting process-level system metrics (memory, CPU, file descriptors) to Swift Metrics.
Swift System Metrics provides a type that periodically collects process-level system metrics and reports them to the Swift Metrics factory.
This package is designed to be run in tools and applications directly and is not expected to be used from libraries. If you'd like to report additional metrics from your library, use Swift Metrics directly.
Add the dependency to your Package.swift:
.package(url: "https://github.com/apple/swift-system-metrics", from: "1.0.0")
Add the library dependency to your target:
.product(name: "SystemMetrics", package: "swift-system-metrics")
Import and use in your code:
import SystemMetrics
import ServiceLifecycle
import Metrics
import Logging
@main
struct Application {
static func main() async throws {
// Create a logger, or use one of the existing loggers
let logger = Logger(label: "Application")
let metrics = MyMetricsBackendImplementation()
MetricsSystem.bootstrap(metrics)
let service = FooService()
// Create the monitor
let systemMetricsMonitor = SystemMetricsMonitor(logger: logger)
// Create the service
let serviceGroup = ServiceGroup(
services: [service, systemMetricsMonitor],
gracefulShutdownSignals: [.sigint],
cancellationSignals: [.sigterm],
logger: logger
)
try await serviceGroup.run()
}
}
The monitor collects and reports the following metrics as gauges:
process_virtual_memory_bytesprocess_resident_memory_bytesprocess_start_time_secondsprocess_cpu_seconds_totalprocess_max_fdsprocess_open_fdsprocess_thread_countprocess_page_faults_minor_totalprocess_page_faults_major_totalIf your metrics backend expects different label names, use MappingMetricsFactory from Swift Metrics to rename labels
without modifying the library itself. See the
Getting Started
guide for a complete example.
The library is supported on macOS and Linux.
| Component | macOS | Linux |
|---|---|---|
| SystemMetrics | β 13+ | β |
Comprehensive documentation is hosted on the Swift Package Index.
Swift
98.2%
Shell
1.8%