diff --git a/pkg/ktexporter/fetchmetrics/fetchmetrics.go b/pkg/ktexporter/fetchmetrics/fetchmetrics.go index 2743516d..d823e80b 100644 --- a/pkg/ktexporter/fetchmetrics/fetchmetrics.go +++ b/pkg/ktexporter/fetchmetrics/fetchmetrics.go @@ -95,7 +95,7 @@ type ContainerStats struct { } // GetContainerStats fetches the container stats using crictl stats command -func GetContainerStats() (map[string]ContainerStats, error) { +func GetContainerStats(podLister listers.PodLister) (map[string]ContainerStats, error) { // Execute the crictl stats command cmd := exec.Command("crictl", "stats") var out bytes.Buffer diff --git a/pkg/ktexporter/ktmetrics/ktmetrics.go b/pkg/ktexporter/ktmetrics/ktmetrics.go index ae6b4e46..f1d1493a 100644 --- a/pkg/ktexporter/ktmetrics/ktmetrics.go +++ b/pkg/ktexporter/ktmetrics/ktmetrics.go @@ -150,7 +150,11 @@ func GetStatisticFromKt() ([]map[string]string, error) { ktMetrics[parse.MetricRecvBw] = fmt.Sprintf("%.2f", recvBW) ktMetrics[parse.MetricXmitBw] = fmt.Sprintf("%.2f", xmitBW) ktMetrics["taskid"] = kusciaTaskID - containerStats, err := fetchmetrics.GetContainerStats() + + podLister := informers.NewSharedInformerFactoryWithOptions(kubernetes.NewForConfigOrDie(nil), 0).Core().V1().Pods().Lister() + + containerStats, err := fetchmetrics.GetContainerStats(podLister) + if err != nil { nlog.Warn("Fail to get the stats of containers") continue