Add support for container statistics (#318)

Closes #138

This rounds up cgroup and network stats (via netlink) and exposes them
via an agent rpc and on LinuxContainer. While this is not an entirely
accurate view into the full resources being used by the container given
the virtualized nature (doesn't account for vcpu, device etc overhead)
it should give an accurate overview of the workload resource usage in
the guest.

This change besides the stated goal also removes the interfaceStatistics
rpc and just moves these network stats into the new containerStatistics
one. Related to that, it also renames the InterfaceStatistics struct to
NetworkStatistics and moves this into ContainerStatistics as a nested
struct.
This commit is contained in:
Danny Canter
2025-10-08 10:09:10 -04:00
committed by GitHub
parent 85de8fc0c5
commit 06d3a37f8d
13 changed files with 1321 additions and 382 deletions
@@ -68,7 +68,9 @@ public protocol VirtualMachineAgent: Sendable {
func routeAddDefault(name: String, gateway: String) async throws
func configureDNS(config: DNS, location: String) async throws
func configureHosts(config: Hosts, location: String) async throws
func interfaceStatistics(name: String) async throws -> InterfaceStatistics
// Container statistics
func containerStatistics(containerIDs: [String]) async throws -> [ContainerStatistics]
}
extension VirtualMachineAgent {
@@ -84,7 +86,7 @@ extension VirtualMachineAgent {
throw ContainerizationError(.unsupported, message: "writeFile")
}
public func interfaceStatistics(name: String) async throws -> InterfaceStatistics {
throw ContainerizationError(.unsupported, message: "interfaceStatistics")
public func containerStatistics(containerIDs: [String]) async throws -> [ContainerStatistics] {
throw ContainerizationError(.unsupported, message: "containerStatistics")
}
}