Avoid storage usagge calculations when aufs driver is not being used.

This commit is contained in:
Vishnu Kannan 2014-10-07 08:34:59 +00:00
parent 5e8fecea6a
commit 0699e7029d
4 changed files with 28 additions and 5 deletions

View File

@ -39,6 +39,9 @@ type dockerFactory struct {
// Whether this system is using systemd. // Whether this system is using systemd.
useSystemd bool useSystemd bool
// Whether docker is running with AUFS storage driver.
usesAufsDriver bool
client *docker.Client client *docker.Client
} }
@ -57,6 +60,7 @@ func (self *dockerFactory) NewContainerHandler(name string) (handler container.C
self.machineInfoFactory, self.machineInfoFactory,
self.useSystemd, self.useSystemd,
*dockerRootDir, *dockerRootDir,
self.usesAufsDriver,
) )
return return
} }
@ -148,10 +152,19 @@ func Register(factory info.MachineInfoFactory) error {
return fmt.Errorf("Docker found, but not using native exec driver") return fmt.Errorf("Docker found, but not using native exec driver")
} }
usesAufsDriver := false
for _, val := range *information {
if strings.Contains(val, "Driver=") && strings.Contains(val, "aufs") {
usesAufsDriver = true
break
}
}
f := &dockerFactory{ f := &dockerFactory{
machineInfoFactory: factory, machineInfoFactory: factory,
useSystemd: systemd.UseSystemd(), useSystemd: systemd.UseSystemd(),
client: client, client: client,
usesAufsDriver: usesAufsDriver,
} }
if f.useSystemd { if f.useSystemd {
glog.Infof("System is using systemd") glog.Infof("System is using systemd")

View File

@ -54,6 +54,7 @@ type dockerContainerHandler struct {
useSystemd bool useSystemd bool
libcontainerStateDir string libcontainerStateDir string
cgroup cgroups.Cgroup cgroup cgroups.Cgroup
usesAufsDriver bool
fsInfo fs.FsInfo fsInfo fs.FsInfo
storageDirs []string storageDirs []string
} }
@ -64,6 +65,7 @@ func newDockerContainerHandler(
machineInfoFactory info.MachineInfoFactory, machineInfoFactory info.MachineInfoFactory,
useSystemd bool, useSystemd bool,
dockerRootDir string, dockerRootDir string,
usesAufsDriver bool,
) (container.ContainerHandler, error) { ) (container.ContainerHandler, error) {
fsInfo, err := fs.NewFsInfo() fsInfo, err := fs.NewFsInfo()
if err != nil { if err != nil {
@ -79,6 +81,7 @@ func newDockerContainerHandler(
Parent: "/", Parent: "/",
Name: name, Name: name,
}, },
usesAufsDriver: usesAufsDriver,
fsInfo: fsInfo, fsInfo: fsInfo,
} }
handler.storageDirs = append(handler.storageDirs, path.Join(dockerRootDir, pathToAufsDir, path.Base(name))) handler.storageDirs = append(handler.storageDirs, path.Join(dockerRootDir, pathToAufsDir, path.Base(name)))
@ -228,12 +231,19 @@ func (self *dockerContainerHandler) GetSpec() (spec info.ContainerSpec, err erro
spec = libcontainerConfigToContainerSpec(libcontainerConfig, mi) spec = libcontainerConfigToContainerSpec(libcontainerConfig, mi)
if self.usesAufsDriver {
spec.HasFilesystem = true spec.HasFilesystem = true
}
return return
} }
func (self *dockerContainerHandler) getFsStats(stats *info.ContainerStats) error { func (self *dockerContainerHandler) getFsStats(stats *info.ContainerStats) error {
// No support for non-aufs storage drivers.
if !self.usesAufsDriver {
return nil
}
// As of now we assume that all the storage dirs are on the same device. // As of now we assume that all the storage dirs are on the same device.
// The first storage dir will be that of the image layers. // The first storage dir will be that of the image layers.
deviceInfo, err := self.fsInfo.GetDirFsDevice(self.storageDirs[0]) deviceInfo, err := self.fsInfo.GetDirFsDevice(self.storageDirs[0])

View File

@ -239,7 +239,7 @@ type FsStats struct {
Limit uint64 `json:"capacity"` Limit uint64 `json:"capacity"`
// Number of bytes that is consumed by the container on this filesystem. // Number of bytes that is consumed by the container on this filesystem.
Usage uint64 `json:"free"` Usage uint64 `json:"usage"`
} }
type ContainerStats struct { type ContainerStats struct {

View File

@ -61,8 +61,8 @@ func buildTrace(cpu, mem []uint64, duration time.Duration) []*info.ContainerStat
stats.Filesystem = make([]info.FsStats, 1) stats.Filesystem = make([]info.FsStats, 1)
stats.Filesystem[0].Device = "/dev/sda1" stats.Filesystem[0].Device = "/dev/sda1"
stats.Filesystem[0].Capacity = 1024000000 stats.Filesystem[0].Limit = 1024000000
stats.Filesystem[0].Free = 1024000 stats.Filesystem[0].Usage = 1024000
ret[i] = stats ret[i] = stats
} }
return ret return ret