package status

import (
	"github.com/shirou/gopsutil/v3/docker"
	"strings"
	"wdd.io/agent-go/utils"
)

type DockerMetric struct {
	DockerStats []docker.CgroupDockerStat
}

func GetDockerMetric() (*DockerMetric, error) {
	dockerStats, err := docker.GetDockerStat()
	if err != nil {
		log.ErrorF("[GetDockerMetric] - get docker stats list error %v", err)
		return nil, err
	}

	return &DockerMetric{
		DockerStats: dockerStats,
	}, nil

}

func GetDockerInfo() {

	//dockerIDList, err := docker.GetDockerIDList()
	//if err != nil {
	//	log.ErrorF("[GetDockerInfo] - get docker id list error %v", err)
	//}
	//utils.BeautifulPrint(dockerIDList)

	dockerStats, err := docker.GetDockerStat()
	if err != nil {
		log.ErrorF("[GetDockerInfo] - get docker stats list error %v", err)
	}

	utils.BeautifulPrint(dockerStats)

	for _, dockerStat := range dockerStats {
		if strings.Contains(dockerStat.Name, "mysql") {
			cpuDocker, _ := docker.CgroupCPUDocker(dockerStat.ContainerID)

			utils.BeautifulPrint(cpuDocker)

			//usageDocker, _ := docker.CgroupCPUUsageDocker(dockerStat.ContainerID)
			//utils.BeautifulPrint(usageDocker)

			mem, _ := docker.CgroupMemDocker(dockerStat.ContainerID)
			utils.BeautifulPrint(mem)

		}
	}

}
