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
dcbca94904
commit
3bd149f766
2 changed files with 44 additions and 10 deletions
|
@ -3,8 +3,11 @@ package fs
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/dotcloud/docker/pkg/cgroups"
|
"github.com/dotcloud/docker/pkg/cgroups"
|
||||||
)
|
)
|
||||||
|
@ -58,10 +61,9 @@ func (s *blkioGroup) Stats(d *data) (map[string]float64, error) {
|
||||||
var (
|
var (
|
||||||
paramData = make(map[string]float64)
|
paramData = make(map[string]float64)
|
||||||
params = []string{
|
params = []string{
|
||||||
"sectors",
|
"io_service_bytes_recursive",
|
||||||
"io_service_bytes",
|
"io_serviced_recursive",
|
||||||
"io_serviced",
|
"io_queued_recursive",
|
||||||
"io_queued",
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -70,6 +72,12 @@ func (s *blkioGroup) Stats(d *data) (map[string]float64, error) {
|
||||||
return nil, err
|
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 {
|
for _, param := range params {
|
||||||
f, err := os.Open(filepath.Join(path, fmt.Sprintf("blkio.%s", param)))
|
f, err := os.Open(filepath.Join(path, fmt.Sprintf("blkio.%s", param)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -79,12 +87,35 @@ func (s *blkioGroup) Stats(d *data) (map[string]float64, error) {
|
||||||
|
|
||||||
sc := bufio.NewScanner(f)
|
sc := bufio.NewScanner(f)
|
||||||
for sc.Scan() {
|
for sc.Scan() {
|
||||||
_, v, err := getCgroupParamKeyValue(sc.Text())
|
// format: dev type amount
|
||||||
|
fields := strings.Fields(sc.Text())
|
||||||
|
switch len(fields) {
|
||||||
|
case 3:
|
||||||
|
v, err := strconv.ParseFloat(fields[2], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
paramData[param] = v
|
paramData[fmt.Sprintf("%s:%s:%s", param, fields[0], fields[1])] = v
|
||||||
|
case 2:
|
||||||
|
// this is the total line, skip
|
||||||
|
default:
|
||||||
|
return nil, ErrNotValidFormat
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return paramData, nil
|
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"
|
"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
|
// Parses a cgroup param and returns as name, value
|
||||||
// i.e. "io_service_bytes 1234" will return as io_service_bytes, 1234
|
// 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
|
return parts[0], value, nil
|
||||||
default:
|
default:
|
||||||
return "", 0.0, fmt.Errorf("Unable to parse cgroup param: not enough parts; expected 2")
|
return "", 0.0, ErrNotValidFormat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue