| 100 | } |
| 101 | |
| 102 | func (c *cpuController) Stat(path string, stats *v1.Metrics) error { |
| 103 | f, err := os.Open(filepath.Join(c.Path(path), "cpu.stat")) |
| 104 | if err != nil { |
| 105 | return err |
| 106 | } |
| 107 | defer f.Close() |
| 108 | // get or create the cpu field because cpuacct can also set values on this struct |
| 109 | sc := bufio.NewScanner(f) |
| 110 | for sc.Scan() { |
| 111 | key, v, err := parseKV(sc.Text()) |
| 112 | if err != nil { |
| 113 | return err |
| 114 | } |
| 115 | switch key { |
| 116 | case "nr_periods": |
| 117 | stats.CPU.Throttling.Periods = v |
| 118 | case "nr_throttled": |
| 119 | stats.CPU.Throttling.ThrottledPeriods = v |
| 120 | case "throttled_time": |
| 121 | stats.CPU.Throttling.ThrottledTime = v |
| 122 | } |
| 123 | } |
| 124 | return sc.Err() |
| 125 | } |