|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// Copyright © 2025 Apple Inc. and the container project authors. |
| 3 | +// |
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// |
| 8 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +// |
| 10 | +// Unless required by applicable law or agreed to in writing, software |
| 11 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | +//===----------------------------------------------------------------------===// |
| 16 | + |
| 17 | +import Foundation |
| 18 | + |
| 19 | +/// Statistics for a container suitable for CLI display. |
| 20 | +public struct ContainerStats: Sendable, Codable { |
| 21 | + /// Container ID |
| 22 | + public var id: String |
| 23 | + /// Physical memory usage in bytes |
| 24 | + public var memoryUsageBytes: UInt64 |
| 25 | + /// Memory limit in bytes |
| 26 | + public var memoryLimitBytes: UInt64 |
| 27 | + /// CPU usage in microseconds |
| 28 | + public var cpuUsageUsec: UInt64 |
| 29 | + /// Network received bytes (sum of all interfaces) |
| 30 | + public var networkRxBytes: UInt64 |
| 31 | + /// Network transmitted bytes (sum of all interfaces) |
| 32 | + public var networkTxBytes: UInt64 |
| 33 | + /// Block I/O read bytes (sum of all devices) |
| 34 | + public var blockReadBytes: UInt64 |
| 35 | + /// Block I/O write bytes (sum of all devices) |
| 36 | + public var blockWriteBytes: UInt64 |
| 37 | + /// Number of processes in the container |
| 38 | + public var numProcesses: UInt64 |
| 39 | + |
| 40 | + public init( |
| 41 | + id: String, |
| 42 | + memoryUsageBytes: UInt64, |
| 43 | + memoryLimitBytes: UInt64, |
| 44 | + cpuUsageUsec: UInt64, |
| 45 | + networkRxBytes: UInt64, |
| 46 | + networkTxBytes: UInt64, |
| 47 | + blockReadBytes: UInt64, |
| 48 | + blockWriteBytes: UInt64, |
| 49 | + numProcesses: UInt64 |
| 50 | + ) { |
| 51 | + self.id = id |
| 52 | + self.memoryUsageBytes = memoryUsageBytes |
| 53 | + self.memoryLimitBytes = memoryLimitBytes |
| 54 | + self.cpuUsageUsec = cpuUsageUsec |
| 55 | + self.networkRxBytes = networkRxBytes |
| 56 | + self.networkTxBytes = networkTxBytes |
| 57 | + self.blockReadBytes = blockReadBytes |
| 58 | + self.blockWriteBytes = blockWriteBytes |
| 59 | + self.numProcesses = numProcesses |
| 60 | + } |
| 61 | +} |
0 commit comments