2014-04-19 04:55:06 +00:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
2014-04-20 18:34:28 +00:00
|
|
|
"bufio"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2014-04-19 04:55:06 +00:00
|
|
|
"github.com/dotcloud/docker/pkg/cgroups"
|
|
|
|
)
|
|
|
|
|
|
|
|
type blkioGroup struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *blkioGroup) Set(d *data) error {
|
|
|
|
// we just want to join this group even though we don't set anything
|
|
|
|
if _, err := d.join("blkio"); err != nil && err != cgroups.ErrNotFound {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2014-04-19 05:17:31 +00:00
|
|
|
|
|
|
|
func (s *blkioGroup) Remove(d *data) error {
|
|
|
|
return removePath(d.path("blkio"))
|
|
|
|
}
|
2014-04-20 18:34:28 +00:00
|
|
|
|
|
|
|
func (s *blkioGroup) Stats(d *data) (map[string]float64, error) {
|
2014-04-20 19:02:39 +00:00
|
|
|
var (
|
|
|
|
paramData = make(map[string]float64)
|
|
|
|
params = []string{
|
|
|
|
"sectors",
|
|
|
|
"io_service_bytes",
|
|
|
|
"io_serviced",
|
|
|
|
"io_queued",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2014-04-20 18:34:28 +00:00
|
|
|
path, err := d.path("blkio")
|
|
|
|
if err != nil {
|
2014-04-20 19:02:39 +00:00
|
|
|
return nil, err
|
2014-04-20 18:34:28 +00:00
|
|
|
}
|
2014-04-20 19:02:39 +00:00
|
|
|
|
2014-04-20 18:34:28 +00:00
|
|
|
for _, param := range params {
|
2014-04-20 19:02:39 +00:00
|
|
|
f, err := os.Open(filepath.Join(path, fmt.Sprintf("blkio.%s", param)))
|
2014-04-20 18:34:28 +00:00
|
|
|
if err != nil {
|
2014-04-20 19:02:39 +00:00
|
|
|
return nil, err
|
2014-04-20 18:34:28 +00:00
|
|
|
}
|
|
|
|
defer f.Close()
|
2014-04-20 19:02:39 +00:00
|
|
|
|
2014-04-20 18:34:28 +00:00
|
|
|
sc := bufio.NewScanner(f)
|
|
|
|
for sc.Scan() {
|
|
|
|
_, v, err := getCgroupParamKeyValue(sc.Text())
|
|
|
|
if err != nil {
|
2014-04-20 19:02:39 +00:00
|
|
|
return nil, err
|
2014-04-20 18:34:28 +00:00
|
|
|
}
|
|
|
|
paramData[param] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return paramData, nil
|
|
|
|
}
|