mirror of https://github.com/k3s-io/k3s
Expose accelerator metrics in the summary API.
parent
238b4a0d8e
commit
9c38abd482
|
@ -109,6 +109,8 @@ type ContainerStats struct {
|
|||
// Stats pertaining to memory (RAM) resources.
|
||||
// +optional
|
||||
Memory *MemoryStats `json:"memory,omitempty"`
|
||||
// Metrics for Accelerators. Each Accelerator corresponds to one element in the array.
|
||||
Accelerators []AcceleratorStats `json:"accelerators,omitempty"`
|
||||
// Stats pertaining to container rootfs usage of filesystem resources.
|
||||
// Rootfs.UsedBytes is the number of bytes used for the container write layer.
|
||||
// +optional
|
||||
|
@ -188,6 +190,30 @@ type MemoryStats struct {
|
|||
MajorPageFaults *uint64 `json:"majorPageFaults,omitempty"`
|
||||
}
|
||||
|
||||
// AcceleratorStats contains stats for accelerators attached to the container.
|
||||
type AcceleratorStats struct {
|
||||
// Make of the accelerator (nvidia, amd, google etc.)
|
||||
Make string `json:"make"`
|
||||
|
||||
// Model of the accelerator (tesla-p100, tesla-k80 etc.)
|
||||
Model string `json:"model"`
|
||||
|
||||
// ID of the accelerator.
|
||||
ID string `json:"id"`
|
||||
|
||||
// Total accelerator memory.
|
||||
// unit: bytes
|
||||
MemoryTotal uint64 `json:"memory_total"`
|
||||
|
||||
// Total accelerator memory allocated.
|
||||
// unit: bytes
|
||||
MemoryUsed uint64 `json:"memory_used"`
|
||||
|
||||
// Percent of time over the past sample period (10s) during which
|
||||
// the accelerator was actively processing.
|
||||
DutyCycle uint64 `json:"duty_cycle"`
|
||||
}
|
||||
|
||||
// VolumeStats contains data about Volume filesystem usage.
|
||||
type VolumeStats struct {
|
||||
// Embedded FsStats
|
||||
|
|
|
@ -92,6 +92,7 @@ func TestSummaryProvider(t *testing.T) {
|
|||
StartTime: cgroupStatsMap["/kubelet"].cs.StartTime,
|
||||
CPU: cgroupStatsMap["/kubelet"].cs.CPU,
|
||||
Memory: cgroupStatsMap["/kubelet"].cs.Memory,
|
||||
Accelerators: cgroupStatsMap["/kubelet"].cs.Accelerators,
|
||||
UserDefinedMetrics: cgroupStatsMap["/kubelet"].cs.UserDefinedMetrics,
|
||||
})
|
||||
assert.Contains(summary.Node.SystemContainers, statsapi.ContainerStats{
|
||||
|
@ -99,6 +100,7 @@ func TestSummaryProvider(t *testing.T) {
|
|||
StartTime: cgroupStatsMap["/misc"].cs.StartTime,
|
||||
CPU: cgroupStatsMap["/misc"].cs.CPU,
|
||||
Memory: cgroupStatsMap["/misc"].cs.Memory,
|
||||
Accelerators: cgroupStatsMap["/misc"].cs.Accelerators,
|
||||
UserDefinedMetrics: cgroupStatsMap["/misc"].cs.UserDefinedMetrics,
|
||||
})
|
||||
assert.Contains(summary.Node.SystemContainers, statsapi.ContainerStats{
|
||||
|
@ -106,6 +108,7 @@ func TestSummaryProvider(t *testing.T) {
|
|||
StartTime: cgroupStatsMap["/runtime"].cs.StartTime,
|
||||
CPU: cgroupStatsMap["/runtime"].cs.CPU,
|
||||
Memory: cgroupStatsMap["/runtime"].cs.Memory,
|
||||
Accelerators: cgroupStatsMap["/runtime"].cs.Accelerators,
|
||||
UserDefinedMetrics: cgroupStatsMap["/runtime"].cs.UserDefinedMetrics,
|
||||
})
|
||||
assert.Equal(summary.Pods, podStats)
|
||||
|
|
|
@ -119,6 +119,17 @@ func cadvisorInfoToContainerStats(name string, info *cadvisorapiv2.ContainerInfo
|
|||
}
|
||||
}
|
||||
|
||||
for _, acc := range cstat.Accelerators {
|
||||
result.Accelerators = append(result.Accelerators, statsapi.AcceleratorStats{
|
||||
Make: acc.Make,
|
||||
Model: acc.Model,
|
||||
ID: acc.ID,
|
||||
MemoryTotal: acc.MemoryTotal,
|
||||
MemoryUsed: acc.MemoryUsed,
|
||||
DutyCycle: acc.DutyCycle,
|
||||
})
|
||||
}
|
||||
|
||||
result.UserDefinedMetrics = cadvisorInfoToUserDefinedMetrics(info)
|
||||
|
||||
return result
|
||||
|
|
|
@ -97,6 +97,7 @@ var _ = framework.KubeDescribe("Summary API", func() {
|
|||
"PageFaults": bounded(1000, 1E9),
|
||||
"MajorPageFaults": bounded(0, 100000),
|
||||
}),
|
||||
"Accelerators": BeEmpty(),
|
||||
"Rootfs": BeNil(),
|
||||
"Logs": BeNil(),
|
||||
"UserDefinedMetrics": BeEmpty(),
|
||||
|
@ -145,6 +146,7 @@ var _ = framework.KubeDescribe("Summary API", func() {
|
|||
"PageFaults": bounded(100, 1000000),
|
||||
"MajorPageFaults": bounded(0, 10),
|
||||
}),
|
||||
"Accelerators": BeEmpty(),
|
||||
"Rootfs": ptrMatchAllFields(gstruct.Fields{
|
||||
"Time": recent(maxStatsAge),
|
||||
"AvailableBytes": fsCapacityBounds,
|
||||
|
|
Loading…
Reference in New Issue