add volume type and seperated histogram for volume stat collection

This commit is contained in:
Paco Xu
2022-01-06 09:49:01 +08:00
committed by -e
parent c5d8354e0e
commit 6611c36372
6 changed files with 30 additions and 13 deletions

View File

@@ -68,14 +68,13 @@ var (
// this metric is mainly for comparison between fsquota monitoring and `du` for disk usage.
VolumeStatCalDuration = metrics.NewHistogramVec(
&metrics.HistogramOpts{
Subsystem: kubeletSubsystem,
Name: "volume_stat_cal_duration_seconds",
Help: "Duration in seconds to calculate volume stats",
// Use DefBuckets for now, will customize the buckets if necessary.
Subsystem: kubeletSubsystem,
Name: "volume_metric_collection_duration_seconds",
Help: "Duration in seconds to calculate volume stats",
Buckets: metrics.DefBuckets,
StabilityLevel: metrics.ALPHA,
},
[]string{},
[]string{"metric_source"},
)
)
@@ -95,3 +94,8 @@ func Register() {
func SinceInSeconds(start time.Time) float64 {
return time.Since(start).Seconds()
}
// CollectVolumeStatCalDuration collects the duration in seconds to calculate volume stats.
func CollectVolumeStatCalDuration(metricSource string, start time.Time) {
VolumeStatCalDuration.WithLabelValues(metricSource).Observe(SinceInSeconds(start))
}

View File

@@ -30,7 +30,6 @@ import (
"k8s.io/klog/v2"
stats "k8s.io/kubelet/pkg/apis/stats/v1alpha1"
"k8s.io/kubernetes/pkg/features"
servermetrics "k8s.io/kubernetes/pkg/kubelet/server/metrics"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume/util"
)
@@ -134,13 +133,7 @@ func (s *volumeStatCalculator) calcAndStoreStats() {
var ephemeralStats []stats.VolumeStats
var persistentStats []stats.VolumeStats
for name, v := range metricVolumes {
metric, err := func() (*volume.Metrics, error) {
startTime := time.Now()
defer func() {
servermetrics.VolumeStatCalDuration.WithLabelValues().Observe(servermetrics.SinceInSeconds(startTime))
}()
return v.GetMetrics()
}()
metric, err := v.GetMetrics()
if err != nil {
// Expected for Volumes that don't support Metrics
if !volume.IsNotSupported(err) {