Merge pull request #1343 from sjenning/dm-fallback
fallback to /dev/mapper device if metadata device is not set in docker info
This commit is contained in:
commit
e97c522721
@ -22,6 +22,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
dockertypes "github.com/docker/engine-api/types"
|
||||||
"github.com/google/cadvisor/container"
|
"github.com/google/cadvisor/container"
|
||||||
"github.com/google/cadvisor/container/libcontainer"
|
"github.com/google/cadvisor/container/libcontainer"
|
||||||
"github.com/google/cadvisor/devicemapper"
|
"github.com/google/cadvisor/devicemapper"
|
||||||
@ -171,6 +172,31 @@ var (
|
|||||||
version_re = regexp.MustCompile(version_regexp_string)
|
version_re = regexp.MustCompile(version_regexp_string)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func startThinPoolWatcher(dockerInfo *dockertypes.Info) (*devicemapper.ThinPoolWatcher, error) {
|
||||||
|
_, err := devicemapper.ThinLsBinaryPresent()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
dockerThinPoolName, err := dockerutil.DockerThinPoolName(*dockerInfo)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
dockerMetadataDevice, err := dockerutil.DockerMetadataDevice(*dockerInfo)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
thinPoolWatcher, err := devicemapper.NewThinPoolWatcher(dockerThinPoolName, dockerMetadataDevice)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
go thinPoolWatcher.Start()
|
||||||
|
return thinPoolWatcher, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Register root container before running this function!
|
// Register root container before running this function!
|
||||||
func Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo, ignoreMetrics container.MetricSet) error {
|
func Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo, ignoreMetrics container.MetricSet) error {
|
||||||
client, err := Client()
|
client, err := Client()
|
||||||
@ -191,40 +217,11 @@ func Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo, ignoreMetrics c
|
|||||||
return fmt.Errorf("failed to get cgroup subsystems: %v", err)
|
return fmt.Errorf("failed to get cgroup subsystems: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var thinPoolWatcher *devicemapper.ThinPoolWatcher
|
||||||
dockerStorageDriver = storageDriver(dockerInfo.Driver)
|
if storageDriver(dockerInfo.Driver) == devicemapperStorageDriver {
|
||||||
thinPoolWatcher *devicemapper.ThinPoolWatcher = nil
|
thinPoolWatcher, err = startThinPoolWatcher(dockerInfo)
|
||||||
)
|
if err != nil {
|
||||||
|
glog.Errorf("devicemapper filesystem stats will not be reported: %v", err)
|
||||||
if dockerStorageDriver == devicemapperStorageDriver {
|
|
||||||
_, err := devicemapper.ThinLsBinaryPresent()
|
|
||||||
if err == nil {
|
|
||||||
// If the storage driver is devicemapper, create and start a
|
|
||||||
// ThinPoolWatcher to monitor the size of container CoW layers
|
|
||||||
// with thin_ls.
|
|
||||||
dockerThinPoolName, err := dockerutil.DockerThinPoolName(*dockerInfo)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("couldn't find device mapper thin pool name: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
dockerMetadataDevice, err := dockerutil.DockerMetadataDevice(*dockerInfo)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("couldn't determine devicemapper metadata device: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
thinPoolWatcher, err = devicemapper.NewThinPoolWatcher(dockerThinPoolName, dockerMetadataDevice)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("couldn't create thin pool watcher: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
go thinPoolWatcher.Start()
|
|
||||||
} else {
|
|
||||||
msg := []string{
|
|
||||||
"Couldn't locate thin_ls binary; not starting thin pool watcher.",
|
|
||||||
"Containers backed by thin pools will not show accurate usage.",
|
|
||||||
"err: %v",
|
|
||||||
}
|
|
||||||
glog.Errorf(strings.Join(msg, " "), err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ package docker
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
dockertypes "github.com/docker/engine-api/types"
|
dockertypes "github.com/docker/engine-api/types"
|
||||||
@ -50,8 +51,19 @@ func DockerThinPoolName(info dockertypes.Info) (string, error) {
|
|||||||
|
|
||||||
func DockerMetadataDevice(info dockertypes.Info) (string, error) {
|
func DockerMetadataDevice(info dockertypes.Info) (string, error) {
|
||||||
metadataDevice := DriverStatusValue(info.DriverStatus, DriverStatusMetadataFile)
|
metadataDevice := DriverStatusValue(info.DriverStatus, DriverStatusMetadataFile)
|
||||||
if len(metadataDevice) == 0 {
|
if len(metadataDevice) != 0 {
|
||||||
return "", fmt.Errorf("Could not get the devicemapper metadata device")
|
return metadataDevice, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
poolName, err := DockerThinPoolName(info)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
metadataDevice = fmt.Sprintf("/dev/mapper/%s_tmeta", poolName)
|
||||||
|
|
||||||
|
if _, err := os.Stat(metadataDevice); err != nil {
|
||||||
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return metadataDevice, nil
|
return metadataDevice, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user