mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix parsing of blkio files
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
7f12260fd1
commit
37248039e1
2 changed files with 44 additions and 10 deletions
|
@ -3,8 +3,11 @@ package fs
|
|||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/dotcloud/docker/pkg/cgroups"
|
||||
)
|
||||
|
@ -58,10 +61,9 @@ func (s *blkioGroup) Stats(d *data) (map[string]float64, error) {
|
|||
var (
|
||||
paramData = make(map[string]float64)
|
||||
params = []string{
|
||||
"sectors",
|
||||
"io_service_bytes",
|
||||
"io_serviced",
|
||||
"io_queued",
|
||||
"io_service_bytes_recursive",
|
||||
"io_serviced_recursive",
|
||||
"io_queued_recursive",
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -70,6 +72,12 @@ func (s *blkioGroup) Stats(d *data) (map[string]float64, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
k, v, err := s.getSectors(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
paramData[fmt.Sprintf("blkio.sectors_recursive:%s", k)] = v
|
||||
|
||||
for _, param := range params {
|
||||
f, err := os.Open(filepath.Join(path, fmt.Sprintf("blkio.%s", param)))
|
||||
if err != nil {
|
||||
|
@ -79,12 +87,35 @@ func (s *blkioGroup) Stats(d *data) (map[string]float64, error) {
|
|||
|
||||
sc := bufio.NewScanner(f)
|
||||
for sc.Scan() {
|
||||
_, v, err := getCgroupParamKeyValue(sc.Text())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
// format: dev type amount
|
||||
fields := strings.Fields(sc.Text())
|
||||
switch len(fields) {
|
||||
case 3:
|
||||
v, err := strconv.ParseFloat(fields[2], 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
paramData[fmt.Sprintf("%s:%s:%s", param, fields[0], fields[1])] = v
|
||||
case 2:
|
||||
// this is the total line, skip
|
||||
default:
|
||||
return nil, ErrNotValidFormat
|
||||
}
|
||||
paramData[param] = v
|
||||
}
|
||||
}
|
||||
return paramData, nil
|
||||
}
|
||||
|
||||
func (s *blkioGroup) getSectors(path string) (string, float64, error) {
|
||||
f, err := os.Open(filepath.Join(path, "blkio.sectors_recursive"))
|
||||
if err != nil {
|
||||
return "", 0, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
data, err := ioutil.ReadAll(f)
|
||||
if err != nil {
|
||||
return "", 0, err
|
||||
}
|
||||
return getCgroupParamKeyValue(string(data))
|
||||
}
|
||||
|
|
|
@ -7,7 +7,10 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
var ErrNotSupportStat = errors.New("stats are not supported for subsystem")
|
||||
var (
|
||||
ErrNotSupportStat = errors.New("stats are not supported for subsystem")
|
||||
ErrNotValidFormat = errors.New("line is not a valid key value format")
|
||||
)
|
||||
|
||||
// Parses a cgroup param and returns as name, value
|
||||
// i.e. "io_service_bytes 1234" will return as io_service_bytes, 1234
|
||||
|
@ -21,6 +24,6 @@ func getCgroupParamKeyValue(t string) (string, float64, error) {
|
|||
}
|
||||
return parts[0], value, nil
|
||||
default:
|
||||
return "", 0.0, fmt.Errorf("Unable to parse cgroup param: not enough parts; expected 2")
|
||||
return "", 0.0, ErrNotValidFormat
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue