mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
add volume kubelet_volume_stats_health_abnormal to kubelet
This commit is contained in:
parent
f86ee5649b
commit
d71e21e01e
@ -61,6 +61,12 @@ var (
|
||||
[]string{"namespace", "persistentvolumeclaim"}, nil,
|
||||
metrics.ALPHA, "",
|
||||
)
|
||||
|
||||
volumeStatsHealthAbnormalDesc = metrics.NewDesc(
|
||||
metrics.BuildFQName("", kubeletmetrics.KubeletSubsystem, kubeletmetrics.VolumeStatsHealthAbnormalKey),
|
||||
"Volume health status. The count is either 1 or 0",
|
||||
[]string{"namespace", "persistentvolumeclaim"}, nil,
|
||||
metrics.ALPHA, "")
|
||||
)
|
||||
|
||||
type volumeStatsCollector struct {
|
||||
@ -85,6 +91,7 @@ func (collector *volumeStatsCollector) DescribeWithStability(ch chan<- *metrics.
|
||||
ch <- volumeStatsInodesDesc
|
||||
ch <- volumeStatsInodesFreeDesc
|
||||
ch <- volumeStatsInodesUsedDesc
|
||||
ch <- volumeStatsHealthAbnormalDesc
|
||||
}
|
||||
|
||||
// CollectWithStability implements the metrics.StableCollector interface.
|
||||
@ -120,7 +127,16 @@ func (collector *volumeStatsCollector) CollectWithStability(ch chan<- metrics.Me
|
||||
addGauge(volumeStatsInodesDesc, pvcRef, float64(*volumeStat.Inodes))
|
||||
addGauge(volumeStatsInodesFreeDesc, pvcRef, float64(*volumeStat.InodesFree))
|
||||
addGauge(volumeStatsInodesUsedDesc, pvcRef, float64(*volumeStat.InodesUsed))
|
||||
addGauge(volumeStatsHealthAbnormalDesc, pvcRef, float64(convertBoolToFloat64(volumeStat.Abnormal)))
|
||||
allPVCs.Insert(pvcUniqStr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func convertBoolToFloat64(boolVal bool) float64 {
|
||||
if boolVal {
|
||||
return 1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
@ -47,6 +47,8 @@ func TestVolumeStatsCollector(t *testing.T) {
|
||||
# TYPE kubelet_volume_stats_inodes_used gauge
|
||||
# HELP kubelet_volume_stats_used_bytes [ALPHA] Number of used bytes in the volume
|
||||
# TYPE kubelet_volume_stats_used_bytes gauge
|
||||
# HELP kubelet_volume_stats_health_abnormal [ALPHA] Volume health status. The count is either 1 or 0
|
||||
# TYPE kubelet_volume_stats_health_abnormal gauge
|
||||
`
|
||||
|
||||
var (
|
||||
@ -83,6 +85,9 @@ func TestVolumeStatsCollector(t *testing.T) {
|
||||
Name: "testpvc",
|
||||
Namespace: "testns",
|
||||
},
|
||||
VolumeHealthStats: statsapi.VolumeHealthStats{
|
||||
Abnormal: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -106,6 +111,9 @@ func TestVolumeStatsCollector(t *testing.T) {
|
||||
Name: "testpvc",
|
||||
Namespace: "testns",
|
||||
},
|
||||
VolumeHealthStats: statsapi.VolumeHealthStats{
|
||||
Abnormal: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -118,6 +126,7 @@ func TestVolumeStatsCollector(t *testing.T) {
|
||||
kubelet_volume_stats_inodes_free{namespace="testns",persistentvolumeclaim="testpvc"} 655344
|
||||
kubelet_volume_stats_inodes_used{namespace="testns",persistentvolumeclaim="testpvc"} 16
|
||||
kubelet_volume_stats_used_bytes{namespace="testns",persistentvolumeclaim="testpvc"} 4.21789696e+09
|
||||
kubelet_volume_stats_health_abnormal{namespace="testns",persistentvolumeclaim="testpvc"} 1
|
||||
`
|
||||
|
||||
metrics = []string{
|
||||
@ -127,6 +136,7 @@ func TestVolumeStatsCollector(t *testing.T) {
|
||||
"kubelet_volume_stats_inodes_free",
|
||||
"kubelet_volume_stats_inodes_used",
|
||||
"kubelet_volume_stats_used_bytes",
|
||||
"kubelet_volume_stats_health_abnormal",
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -53,6 +53,7 @@ const (
|
||||
VolumeStatsInodesKey = "volume_stats_inodes"
|
||||
VolumeStatsInodesFreeKey = "volume_stats_inodes_free"
|
||||
VolumeStatsInodesUsedKey = "volume_stats_inodes_used"
|
||||
VolumeStatsHealthAbnormalKey = "volume_stats_health_abnormal"
|
||||
RunningPodsKey = "running_pods"
|
||||
RunningContainersKey = "running_containers"
|
||||
// Metrics keys of remote runtime operations
|
||||
|
@ -200,6 +200,9 @@ func (s *volumeStatCalculator) parsePodVolumeStats(podName string, pvcRef *stats
|
||||
return stats.VolumeStats{
|
||||
Name: podName,
|
||||
PVCRef: pvcRef,
|
||||
VolumeHealthStats: stats.VolumeHealthStats{
|
||||
Abnormal: *metric.Abnormal,
|
||||
},
|
||||
FsStats: stats.FsStats{Time: metric.Time, AvailableBytes: &available, CapacityBytes: &capacity,
|
||||
UsedBytes: &used, Inodes: &inodes, InodesFree: &inodesFree, InodesUsed: &inodesUsed},
|
||||
}
|
||||
|
@ -283,6 +283,7 @@ func expectedBlockMetrics() *volume.Metrics {
|
||||
Available: resource.NewQuantity(available, resource.BinarySI),
|
||||
Capacity: resource.NewQuantity(capacity, resource.BinarySI),
|
||||
Used: resource.NewQuantity(available-capacity, resource.BinarySI),
|
||||
Abnormal: &volumeCondition.Abnormal,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -269,6 +269,17 @@ type VolumeStats struct {
|
||||
// Reference to the PVC, if one exists
|
||||
// +optional
|
||||
PVCRef *PVCReference `json:"pvcRef,omitempty"`
|
||||
|
||||
// VolumeHealthStats contains data about volume health
|
||||
// +optional
|
||||
VolumeHealthStats `json:"volumeHealthStats,omitempty"`
|
||||
}
|
||||
|
||||
// VolumeHealthStats contains data about volume health.
|
||||
type VolumeHealthStats struct {
|
||||
// Normal volumes are available for use and operating optimally.
|
||||
// An abnormal volume does not meet these criteria.
|
||||
Abnormal bool `json:"abnormal,omitempty"`
|
||||
}
|
||||
|
||||
// PVCReference contains enough information to describe the referenced PVC.
|
||||
|
Loading…
Reference in New Issue
Block a user