Go에서 CPU 사용량 측정
host machine의 CPU usage를 측정 import "github.com/shirou/gopsutil/cpu" period := 100 * time.Millisecond cpuInfo, err := cpu.Percent(period, false) if err != nil { return } c.usage = cpuInfo[0]container의 CPU usage를 측정 dat, err := ioutil.ReadFile(path) ... used, err := strconv.Atoi(strings.Replace(string(dat), "\n", "", 1)) ... time.Sleep(period) // process가 사용한 system time을 획득 var r syscall.Rusage s..
2023.06.21