Skip to content

Commit

Permalink
框架over
Browse files Browse the repository at this point in the history
  • Loading branch information
renji555 committed Dec 1, 2024
1 parent 1a01a86 commit 835837a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/ktexporter/fetchmetrics/fetchmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion pkg/ktexporter/ktmetrics/ktmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 835837a

Please sign in to comment.