|
| 1 | +package me.devnatan.dockerkt.models.container |
| 2 | + |
| 3 | +import kotlinx.serialization.SerialName |
| 4 | +import kotlinx.serialization.Serializable |
| 5 | + |
| 6 | +/** |
| 7 | + * Sentinel value Docker uses in `uint64` fields (e.g. memory/pids limits) to |
| 8 | + * indicate "unlimited". Equivalent to [ULong.MAX_VALUE]. |
| 9 | + * |
| 10 | + * ``` |
| 11 | + * if (stats.memoryStats?.limit == Unlimited) { ... } |
| 12 | + * ``` |
| 13 | + */ |
| 14 | +public const val Unlimited: ULong = ULong.MAX_VALUE |
| 15 | + |
| 16 | +/** |
| 17 | + * Container resource usage statistics. |
| 18 | + * |
| 19 | + * Fields are nullable because Docker returns different subsets depending |
| 20 | + * on the container platform (Linux vs Windows) and state (running vs stopped). |
| 21 | + * |
| 22 | + * Counter values are modeled as [ULong] to match Docker's `uint64` API types — |
| 23 | + * some fields (e.g. memory/pids limits) use the `uint64` max value as a sentinel |
| 24 | + * for "unlimited". |
| 25 | + */ |
| 26 | +@Serializable |
| 27 | +public data class ContainerStats internal constructor( |
| 28 | + @SerialName("read") public val read: String, |
| 29 | + @SerialName("preread") public val preread: String? = null, |
| 30 | + @SerialName("name") public val name: String? = null, |
| 31 | + @SerialName("id") public val id: String? = null, |
| 32 | + @SerialName("num_procs") public val numProcs: ULong? = null, |
| 33 | + @SerialName("pids_stats") public val pidsStats: PidsStats? = null, |
| 34 | + @SerialName("cpu_stats") public val cpuStats: CpuStats? = null, |
| 35 | + @SerialName("precpu_stats") public val precpuStats: CpuStats? = null, |
| 36 | + @SerialName("memory_stats") public val memoryStats: MemoryStats? = null, |
| 37 | + @SerialName("blkio_stats") public val blkioStats: BlkioStats? = null, |
| 38 | + @SerialName("networks") public val networks: Map<String, NetworkStats>? = null, |
| 39 | + @SerialName("storage_stats") public val storageStats: StorageStats? = null, |
| 40 | +) |
| 41 | + |
| 42 | +@Serializable |
| 43 | +public data class PidsStats internal constructor( |
| 44 | + @SerialName("current") public val current: ULong? = null, |
| 45 | + @SerialName("limit") public val limit: ULong? = null, |
| 46 | +) |
| 47 | + |
| 48 | +@Serializable |
| 49 | +public data class CpuStats internal constructor( |
| 50 | + @SerialName("cpu_usage") public val cpuUsage: CpuUsage? = null, |
| 51 | + @SerialName("system_cpu_usage") public val systemCpuUsage: ULong? = null, |
| 52 | + @SerialName("online_cpus") public val onlineCpus: ULong? = null, |
| 53 | + @SerialName("throttling_data") public val throttlingData: ThrottlingData? = null, |
| 54 | +) |
| 55 | + |
| 56 | +@Serializable |
| 57 | +public data class CpuUsage internal constructor( |
| 58 | + @SerialName("total_usage") public val totalUsage: ULong? = null, |
| 59 | + @SerialName("usage_in_kernelmode") public val usageInKernelmode: ULong? = null, |
| 60 | + @SerialName("usage_in_usermode") public val usageInUsermode: ULong? = null, |
| 61 | + @SerialName("percpu_usage") public val percpuUsage: List<ULong>? = null, |
| 62 | +) |
| 63 | + |
| 64 | +@Serializable |
| 65 | +public data class ThrottlingData internal constructor( |
| 66 | + @SerialName("periods") public val periods: ULong? = null, |
| 67 | + @SerialName("throttled_periods") public val throttledPeriods: ULong? = null, |
| 68 | + @SerialName("throttled_time") public val throttledTime: ULong? = null, |
| 69 | +) |
| 70 | + |
| 71 | +@Serializable |
| 72 | +public data class MemoryStats internal constructor( |
| 73 | + @SerialName("usage") public val usage: ULong? = null, |
| 74 | + @SerialName("max_usage") public val maxUsage: ULong? = null, |
| 75 | + @SerialName("limit") public val limit: ULong? = null, |
| 76 | + @SerialName("failcnt") public val failcnt: ULong? = null, |
| 77 | + @SerialName("stats") public val stats: Map<String, ULong>? = null, |
| 78 | + @SerialName("commitbytes") public val commitBytes: ULong? = null, |
| 79 | + @SerialName("commitpeakbytes") public val commitPeakBytes: ULong? = null, |
| 80 | + @SerialName("privateworkingset") public val privateWorkingSet: ULong? = null, |
| 81 | +) |
| 82 | + |
| 83 | +@Serializable |
| 84 | +public data class BlkioStats internal constructor( |
| 85 | + @SerialName("io_service_bytes_recursive") public val ioServiceBytesRecursive: List<BlkioStatsEntry>? = null, |
| 86 | + @SerialName("io_serviced_recursive") public val ioServicedRecursive: List<BlkioStatsEntry>? = null, |
| 87 | + @SerialName("io_queue_recursive") public val ioQueueRecursive: List<BlkioStatsEntry>? = null, |
| 88 | + @SerialName("io_service_time_recursive") public val ioServiceTimeRecursive: List<BlkioStatsEntry>? = null, |
| 89 | + @SerialName("io_wait_time_recursive") public val ioWaitTimeRecursive: List<BlkioStatsEntry>? = null, |
| 90 | + @SerialName("io_merged_recursive") public val ioMergedRecursive: List<BlkioStatsEntry>? = null, |
| 91 | + @SerialName("io_time_recursive") public val ioTimeRecursive: List<BlkioStatsEntry>? = null, |
| 92 | + @SerialName("sectors_recursive") public val sectorsRecursive: List<BlkioStatsEntry>? = null, |
| 93 | +) |
| 94 | + |
| 95 | +@Serializable |
| 96 | +public data class BlkioStatsEntry internal constructor( |
| 97 | + @SerialName("major") public val major: ULong? = null, |
| 98 | + @SerialName("minor") public val minor: ULong? = null, |
| 99 | + @SerialName("op") public val op: String? = null, |
| 100 | + @SerialName("value") public val value: ULong? = null, |
| 101 | +) |
| 102 | + |
| 103 | +@Serializable |
| 104 | +public data class NetworkStats internal constructor( |
| 105 | + @SerialName("rx_bytes") public val rxBytes: ULong? = null, |
| 106 | + @SerialName("rx_packets") public val rxPackets: ULong? = null, |
| 107 | + @SerialName("rx_errors") public val rxErrors: ULong? = null, |
| 108 | + @SerialName("rx_dropped") public val rxDropped: ULong? = null, |
| 109 | + @SerialName("tx_bytes") public val txBytes: ULong? = null, |
| 110 | + @SerialName("tx_packets") public val txPackets: ULong? = null, |
| 111 | + @SerialName("tx_errors") public val txErrors: ULong? = null, |
| 112 | + @SerialName("tx_dropped") public val txDropped: ULong? = null, |
| 113 | +) |
| 114 | + |
| 115 | +@Serializable |
| 116 | +public data class StorageStats internal constructor( |
| 117 | + @SerialName("read_count_normalized") public val readCountNormalized: ULong? = null, |
| 118 | + @SerialName("read_size_bytes") public val readSizeBytes: ULong? = null, |
| 119 | + @SerialName("write_count_normalized") public val writeCountNormalized: ULong? = null, |
| 120 | + @SerialName("write_size_bytes") public val writeSizeBytes: ULong? = null, |
| 121 | +) |
0 commit comments