@@ -22,6 +22,7 @@ import (
2222 "strings"
2323 "sync"
2424
25+ dockertypes "github.com/docker/engine-api/types"
2526 "github.com/google/cadvisor/container"
2627 "github.com/google/cadvisor/container/libcontainer"
2728 "github.com/google/cadvisor/devicemapper"
@@ -171,6 +172,31 @@ var (
171172 version_re = regexp .MustCompile (version_regexp_string )
172173)
173174
175+ func startThinPoolWatcher (dockerInfo * dockertypes.Info ) (* devicemapper.ThinPoolWatcher , error ) {
176+ _ , err := devicemapper .ThinLsBinaryPresent ()
177+ if err != nil {
178+ return nil , err
179+ }
180+
181+ dockerThinPoolName , err := dockerutil .DockerThinPoolName (* dockerInfo )
182+ if err != nil {
183+ return nil , err
184+ }
185+
186+ dockerMetadataDevice , err := dockerutil .DockerMetadataDevice (* dockerInfo )
187+ if err != nil {
188+ return nil , err
189+ }
190+
191+ thinPoolWatcher , err := devicemapper .NewThinPoolWatcher (dockerThinPoolName , dockerMetadataDevice )
192+ if err != nil {
193+ return nil , err
194+ }
195+
196+ go thinPoolWatcher .Start ()
197+ return thinPoolWatcher , nil
198+ }
199+
174200// Register root container before running this function!
175201func Register (factory info.MachineInfoFactory , fsInfo fs.FsInfo , ignoreMetrics container.MetricSet ) error {
176202 client , err := Client ()
@@ -191,40 +217,11 @@ func Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo, ignoreMetrics c
191217 return fmt .Errorf ("failed to get cgroup subsystems: %v" , err )
192218 }
193219
194- var (
195- dockerStorageDriver = storageDriver (dockerInfo .Driver )
196- thinPoolWatcher * devicemapper.ThinPoolWatcher = nil
197- )
198-
199- if dockerStorageDriver == devicemapperStorageDriver {
200- _ , err := devicemapper .ThinLsBinaryPresent ()
201- if err == nil {
202- // If the storage driver is devicemapper, create and start a
203- // ThinPoolWatcher to monitor the size of container CoW layers
204- // with thin_ls.
205- dockerThinPoolName , err := dockerutil .DockerThinPoolName (* dockerInfo )
206- if err != nil {
207- return fmt .Errorf ("couldn't find device mapper thin pool name: %v" , err )
208- }
209-
210- dockerMetadataDevice , err := dockerutil .DockerMetadataDevice (* dockerInfo )
211- if err != nil {
212- return fmt .Errorf ("couldn't determine devicemapper metadata device: %v" , err )
213- }
214-
215- thinPoolWatcher , err = devicemapper .NewThinPoolWatcher (dockerThinPoolName , dockerMetadataDevice )
216- if err != nil {
217- return fmt .Errorf ("couldn't create thin pool watcher: %v" , err )
218- }
219-
220- go thinPoolWatcher .Start ()
221- } else {
222- msg := []string {
223- "Couldn't locate thin_ls binary; not starting thin pool watcher." ,
224- "Containers backed by thin pools will not show accurate usage." ,
225- "err: %v" ,
226- }
227- glog .Errorf (strings .Join (msg , " " ), err )
220+ var thinPoolWatcher * devicemapper.ThinPoolWatcher
221+ if storageDriver (dockerInfo .Driver ) == devicemapperStorageDriver {
222+ thinPoolWatcher , err = startThinPoolWatcher (dockerInfo )
223+ if err != nil {
224+ glog .Errorf ("devicemapper filesystem stats will not be reported: %v" , err )
228225 }
229226 }
230227
0 commit comments