Merge pull request #6153 from vishh/stats1
Add per cpu usage to libcontainer stats
This commit is contained in:
commit
460e9bcc04
3 changed files with 25 additions and 2 deletions
|
@ -3,6 +3,7 @@ package fs
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
@ -76,6 +77,11 @@ func (s *cpuacctGroup) GetStats(d *data, stats *cgroups.Stats) error {
|
||||||
stats.CpuStats.CpuUsage.PercentUsage = percentage
|
stats.CpuStats.CpuUsage.PercentUsage = percentage
|
||||||
// Delta usage is in nanoseconds of CPU time so get the usage (in cores) over the sample time.
|
// Delta usage is in nanoseconds of CPU time so get the usage (in cores) over the sample time.
|
||||||
stats.CpuStats.CpuUsage.CurrentUsage = deltaUsage / uint64(usageSampleDuration.Nanoseconds())
|
stats.CpuStats.CpuUsage.CurrentUsage = deltaUsage / uint64(usageSampleDuration.Nanoseconds())
|
||||||
|
percpuUsage, err := s.getPercpuUsage(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
stats.CpuStats.CpuUsage.PercpuUsage = percpuUsage
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,3 +138,19 @@ func (s *cpuacctGroup) getCpuUsage(d *data, path string) (uint64, error) {
|
||||||
}
|
}
|
||||||
return cpuTotal, nil
|
return cpuTotal, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *cpuacctGroup) getPercpuUsage(path string) ([]uint64, error) {
|
||||||
|
percpuUsage := []uint64{}
|
||||||
|
data, err := ioutil.ReadFile(filepath.Join(path, "cpuacct.usage_percpu"))
|
||||||
|
if err != nil {
|
||||||
|
return percpuUsage, err
|
||||||
|
}
|
||||||
|
for _, value := range strings.Fields(string(data)) {
|
||||||
|
value, err := strconv.ParseUint(value, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return percpuUsage, fmt.Errorf("Unable to convert param value to uint64: %s", err)
|
||||||
|
}
|
||||||
|
percpuUsage = append(percpuUsage, value)
|
||||||
|
}
|
||||||
|
return percpuUsage, nil
|
||||||
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ func getCgroupParamKeyValue(t string) (string, uint64, error) {
|
||||||
case 2:
|
case 2:
|
||||||
value, err := strconv.ParseUint(parts[1], 10, 64)
|
value, err := strconv.ParseUint(parts[1], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", 0, fmt.Errorf("Unable to convert param value to int: %s", err)
|
return "", 0, fmt.Errorf("Unable to convert param value to uint64: %s", err)
|
||||||
}
|
}
|
||||||
return parts[0], value, nil
|
return parts[0], value, nil
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -14,6 +14,7 @@ type CpuUsage struct {
|
||||||
PercentUsage uint64 `json:"percent_usage,omitempty"`
|
PercentUsage uint64 `json:"percent_usage,omitempty"`
|
||||||
// nanoseconds of cpu time consumed over the last 100 ms.
|
// nanoseconds of cpu time consumed over the last 100 ms.
|
||||||
CurrentUsage uint64 `json:"current_usage,omitempty"`
|
CurrentUsage uint64 `json:"current_usage,omitempty"`
|
||||||
|
PercpuUsage []uint64 `json:"percpu_usage,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CpuStats struct {
|
type CpuStats struct {
|
||||||
|
|
Loading…
Reference in a new issue