Skip to content

Commit 5b435b4

Browse files
committed
Clean up cAdvisor logging
1 parent 3a40bbf commit 5b435b4

File tree

18 files changed

+52
-56
lines changed

18 files changed

+52
-56
lines changed

accelerators/nvidia.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const nvidiaVendorId = "0x10de"
4747
// Setup initializes NVML if nvidia devices are present on the node.
4848
func (nm *NvidiaManager) Setup() {
4949
if !detectDevices(nvidiaVendorId) {
50-
glog.Info("No NVIDIA devices found.")
50+
glog.V(4).Info("No NVIDIA devices found.")
5151
return
5252
}
5353

@@ -56,7 +56,7 @@ func (nm *NvidiaManager) Setup() {
5656
return
5757
}
5858
go func() {
59-
glog.Info("Starting goroutine to initialize NVML")
59+
glog.V(2).Info("Starting goroutine to initialize NVML")
6060
// TODO: use globalHousekeepingInterval
6161
for range time.Tick(time.Minute) {
6262
nm.initializeNVML()
@@ -71,19 +71,19 @@ func (nm *NvidiaManager) Setup() {
7171
func detectDevices(vendorId string) bool {
7272
devices, err := ioutil.ReadDir(sysFsPCIDevicesPath)
7373
if err != nil {
74-
glog.Warningf("error reading %q: %v", sysFsPCIDevicesPath, err)
74+
glog.Warningf("Error reading %q: %v", sysFsPCIDevicesPath, err)
7575
return false
7676
}
7777

7878
for _, device := range devices {
7979
vendorPath := filepath.Join(sysFsPCIDevicesPath, device.Name(), "vendor")
8080
content, err := ioutil.ReadFile(vendorPath)
8181
if err != nil {
82-
glog.Infof("Error while reading %q: %v", vendorPath, err)
82+
glog.V(4).Infof("Error while reading %q: %v", vendorPath, err)
8383
continue
8484
}
8585
if strings.EqualFold(strings.TrimSpace(string(content)), vendorId) {
86-
glog.Infof("Found device with vendorId %q", vendorId)
86+
glog.V(3).Infof("Found device with vendorId %q", vendorId)
8787
return true
8888
}
8989
}
@@ -95,7 +95,7 @@ func (nm *NvidiaManager) initializeNVML() {
9595
if err := gonvml.Initialize(); err != nil {
9696
// This is under a logging level because otherwise we may cause
9797
// log spam if the drivers/nvml is not installed on the system.
98-
glog.V(3).Infof("Could not initialize NVML: %v", err)
98+
glog.V(4).Infof("Could not initialize NVML: %v", err)
9999
return
100100
}
101101
numDevices, err := gonvml.DeviceCount()
@@ -107,7 +107,7 @@ func (nm *NvidiaManager) initializeNVML() {
107107
nm.Unlock()
108108
return
109109
}
110-
glog.Infof("NVML initialized. Number of nvidia devices: %v", numDevices)
110+
glog.V(1).Infof("NVML initialized. Number of nvidia devices: %v", numDevices)
111111
nm.nvidiaDevices = make(map[int]gonvml.Device, numDevices)
112112
for i := 0; i < int(numDevices); i++ {
113113
device, err := gonvml.DeviceHandleByIndex(uint(i))

cadvisor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func main() {
156156
// Install signal handler.
157157
installSignalHandler(containerManager)
158158

159-
glog.Infof("Starting cAdvisor version: %s-%s on port %d", version.Info["version"], version.Info["revision"], *argPort)
159+
glog.V(1).Infof("Starting cAdvisor version: %s-%s on port %d", version.Info["version"], version.Info["revision"], *argPort)
160160

161161
addr := fmt.Sprintf("%s:%d", *argIp, *argPort)
162162
glog.Fatal(http.ListenAndServe(addr, mux))

container/containerd/factory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo, ignoreMetrics c
133133
return fmt.Errorf("failed to get cgroup subsystems: %v", err)
134134
}
135135

136-
glog.Infof("Registering containerd factory")
136+
glog.V(1).Infof("Registering containerd factory")
137137
f := &containerdFactory{
138138
cgroupSubsystems: cgroupSubsystems,
139139
client: client,

container/crio/factory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo, ignoreMetrics c
154154
return fmt.Errorf("failed to get cgroup subsystems: %v", err)
155155
}
156156

157-
glog.Infof("Registering CRI-O factory")
157+
glog.V(1).Infof("Registering CRI-O factory")
158158
f := &crioFactory{
159159
client: client,
160160
cgroupSubsystems: cgroupSubsystems,

container/crio/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func newCrioContainerHandler(
185185
}
186186
// TODO for env vars we wanted to show from container.Config.Env from whitelist
187187
//for _, exposedEnv := range metadataEnvs {
188-
//glog.Infof("TODO env whitelist: %v", exposedEnv)
188+
//glog.V(4).Infof("TODO env whitelist: %v", exposedEnv)
189189
//}
190190

191191
return handler, nil

container/docker/factory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ func Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo, ignoreMetrics c
352352
}
353353
}
354354

355-
glog.Infof("Registering Docker factory")
355+
glog.V(1).Infof("Registering Docker factory")
356356
f := &dockerFactory{
357357
cgroupSubsystems: cgroupSubsystems,
358358
client: client,

container/raw/factory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func Register(machineInfoFactory info.MachineInfoFactory, fsInfo fs.FsInfo, igno
8383
return err
8484
}
8585

86-
glog.Infof("Registering Raw factory")
86+
glog.V(1).Infof("Registering Raw factory")
8787
factory := &rawFactory{
8888
machineInfoFactory: machineInfoFactory,
8989
fsInfo: fsInfo,

container/rkt/factory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func Register(machineInfoFactory info.MachineInfoFactory, fsInfo fs.FsInfo, igno
8686
return fmt.Errorf("failed to find supported cgroup mounts for the raw factory")
8787
}
8888

89-
glog.Infof("Registering Rkt factory")
89+
glog.V(1).Infof("Registering Rkt factory")
9090
factory := &rktFactory{
9191
machineInfoFactory: machineInfoFactory,
9292
fsInfo: fsInfo,

container/systemd/factory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (f *systemdFactory) DebugInfo() map[string][]string {
5151

5252
// Register registers the systemd container factory.
5353
func Register(machineInfoFactory info.MachineInfoFactory, fsInfo fs.FsInfo, ignoreMetrics container.MetricSet) error {
54-
glog.Infof("Registering systemd factory")
54+
glog.V(1).Infof("Registering systemd factory")
5555
factory := &systemdFactory{}
5656
container.RegisterContainerHandlerFactory(factory, []watcher.ContainerWatchSource{watcher.Raw})
5757
return nil

fs/fs.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ func NewFsInfo(context Context) (FsInfo, error) {
136136
fsInfo.addDockerImagesLabel(context, mounts)
137137
fsInfo.addCrioImagesLabel(context, mounts)
138138

139-
glog.Infof("Filesystem UUIDs: %+v", fsInfo.fsUUIDToDeviceName)
140-
glog.Infof("Filesystem partitions: %+v", fsInfo.partitions)
139+
glog.V(1).Infof("Filesystem UUIDs: %+v", fsInfo.fsUUIDToDeviceName)
140+
glog.V(1).Infof("Filesystem partitions: %+v", fsInfo.partitions)
141141
fsInfo.addSystemRootLabel(mounts)
142142
return fsInfo, nil
143143
}
@@ -162,7 +162,7 @@ func getFsUUIDToDeviceNameMap() (map[string]string, error) {
162162
path := filepath.Join(dir, file.Name())
163163
target, err := os.Readlink(path)
164164
if err != nil {
165-
glog.Infof("Failed to resolve symlink for %q", path)
165+
glog.Warningf("Failed to resolve symlink for %q", path)
166166
continue
167167
}
168168
device, err := filepath.Abs(filepath.Join(dir, target))
@@ -438,7 +438,7 @@ func getDiskStatsMap(diskStatsFile string) (map[string]DiskStats, error) {
438438
file, err := os.Open(diskStatsFile)
439439
if err != nil {
440440
if os.IsNotExist(err) {
441-
glog.Infof("not collecting filesystem statistics because file %q was not available", diskStatsFile)
441+
glog.Warningf("Not collecting filesystem statistics because file %q was not found", diskStatsFile)
442442
return diskStatsMap, nil
443443
}
444444
return nil, err
@@ -561,12 +561,12 @@ func GetDirDiskUsage(dir string, timeout time.Duration) (uint64, error) {
561561
return 0, fmt.Errorf("failed to exec du - %v", err)
562562
}
563563
timer := time.AfterFunc(timeout, func() {
564-
glog.Infof("killing cmd %v due to timeout(%s)", cmd.Args, timeout.String())
564+
glog.Warningf("Killing cmd %v due to timeout(%s)", cmd.Args, timeout.String())
565565
cmd.Process.Kill()
566566
})
567567
stdoutb, souterr := ioutil.ReadAll(stdoutp)
568568
if souterr != nil {
569-
glog.Errorf("failed to read from stdout for cmd %v - %v", cmd.Args, souterr)
569+
glog.Errorf("Failed to read from stdout for cmd %v - %v", cmd.Args, souterr)
570570
}
571571
stderrb, _ := ioutil.ReadAll(stderrp)
572572
err = cmd.Wait()
@@ -600,7 +600,7 @@ func GetDirInodeUsage(dir string, timeout time.Duration) (uint64, error) {
600600
return 0, fmt.Errorf("failed to exec cmd %v - %v; stderr: %v", findCmd.Args, err, stderr.String())
601601
}
602602
timer := time.AfterFunc(timeout, func() {
603-
glog.Infof("killing cmd %v due to timeout(%s)", findCmd.Args, timeout.String())
603+
glog.Warningf("Killing cmd %v due to timeout(%s)", findCmd.Args, timeout.String())
604604
findCmd.Process.Kill()
605605
})
606606
err := findCmd.Wait()
@@ -741,16 +741,16 @@ func getBtrfsMajorMinorIds(mount *mount.Info) (int, int, error) {
741741
return 0, 0, err
742742
}
743743

744-
glog.Infof("btrfs mount %#v", mount)
744+
glog.V(4).Infof("btrfs mount %#v", mount)
745745
if buf.Mode&syscall.S_IFMT == syscall.S_IFBLK {
746746
err := syscall.Stat(mount.Mountpoint, buf)
747747
if err != nil {
748748
err = fmt.Errorf("stat failed on %s with error: %s", mount.Mountpoint, err)
749749
return 0, 0, err
750750
}
751751

752-
glog.Infof("btrfs dev major:minor %d:%d\n", int(major(buf.Dev)), int(minor(buf.Dev)))
753-
glog.Infof("btrfs rdev major:minor %d:%d\n", int(major(buf.Rdev)), int(minor(buf.Rdev)))
752+
glog.V(4).Infof("btrfs dev major:minor %d:%d\n", int(major(buf.Dev)), int(minor(buf.Dev)))
753+
glog.V(4).Infof("btrfs rdev major:minor %d:%d\n", int(major(buf.Rdev)), int(minor(buf.Rdev)))
754754

755755
return int(major(buf.Dev)), int(minor(buf.Dev)), nil
756756
} else {

http/handlers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func RegisterHandlers(mux httpmux.Mux, containerManager manager.Manager, httpAut
6060

6161
// Setup the authenticator object
6262
if httpAuthFile != "" {
63-
glog.Infof("Using auth file %s", httpAuthFile)
63+
glog.V(1).Infof("Using auth file %s", httpAuthFile)
6464
secrets := auth.HtpasswdFileProvider(httpAuthFile)
6565
authenticator := auth.NewBasicAuthenticator(httpAuthRealm, secrets)
6666
mux.HandleFunc(static.StaticResource, authenticator.Wrap(staticHandler))
@@ -70,7 +70,7 @@ func RegisterHandlers(mux httpmux.Mux, containerManager manager.Manager, httpAut
7070
authenticated = true
7171
}
7272
if httpAuthFile == "" && httpDigestFile != "" {
73-
glog.Infof("Using digest file %s", httpDigestFile)
73+
glog.V(1).Infof("Using digest file %s", httpDigestFile)
7474
secrets := auth.HtdigestFileProvider(httpDigestFile)
7575
authenticator := auth.NewDigestAuthenticator(httpDigestRealm, secrets)
7676
mux.HandleFunc(static.StaticResource, authenticator.Wrap(staticHandler))

machine/info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func getInfoFromFiles(filePaths string) string {
4949
return strings.TrimSpace(string(id))
5050
}
5151
}
52-
glog.Infof("Couldn't collect info from any of the files in %q", filePaths)
52+
glog.Warningf("Couldn't collect info from any of the files in %q", filePaths)
5353
return ""
5454
}
5555

manager/container.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,7 @@ func newContainerData(containerName string, memoryCache *memory.InMemoryCache, h
377377
// Create cpu load reader.
378378
loadReader, err := cpuload.New()
379379
if err != nil {
380-
// TODO(rjnagal): Promote to warning once we support cpu load inside namespaces.
381-
glog.Infof("Could not initialize cpu load reader for %q: %s", ref.Name, err)
380+
glog.Warningf("Could not initialize cpu load reader for %q: %s", ref.Name, err)
382381
} else {
383382
cont.loadReader = loadReader
384383
}
@@ -467,7 +466,7 @@ func (c *containerData) housekeeping() {
467466
stats, err := c.memoryCache.RecentStats(c.info.Name, empty, empty, numSamples)
468467
if err != nil {
469468
if c.allowErrorLogging() {
470-
glog.Infof("[%s] Failed to get recent stats for logging usage: %v", c.info.Name, err)
469+
glog.Warningf("[%s] Failed to get recent stats for logging usage: %v", c.info.Name, err)
471470
}
472471
} else if len(stats) < numSamples {
473472
// Ignore, not enough stats yet.
@@ -483,6 +482,7 @@ func (c *containerData) housekeeping() {
483482
instantUsageInCores := float64(stats[numSamples-1].Cpu.Usage.Total-stats[numSamples-2].Cpu.Usage.Total) / float64(stats[numSamples-1].Timestamp.Sub(stats[numSamples-2].Timestamp).Nanoseconds())
484483
usageInCores := float64(usageCpuNs) / float64(stats[numSamples-1].Timestamp.Sub(stats[0].Timestamp).Nanoseconds())
485484
usageInHuman := units.HumanSize(float64(usageMemory))
485+
// Don't set verbosity since this is already protected by the logUsage flag.
486486
glog.Infof("[%s] %.3f cores (average: %.3f cores), %s of memory", c.info.Name, instantUsageInCores, usageInCores, usageInHuman)
487487
}
488488
}
@@ -504,7 +504,7 @@ func (c *containerData) housekeepingTick(timer <-chan time.Time, longHousekeepin
504504
err := c.updateStats()
505505
if err != nil {
506506
if c.allowErrorLogging() {
507-
glog.Infof("Failed to update stats for container \"%s\": %s", c.info.Name, err)
507+
glog.Warning("Failed to update stats for container \"%s\": %s", c.info.Name, err)
508508
}
509509
}
510510
// Log if housekeeping took too long.

manager/manager.go

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func New(memoryCache *memory.InMemoryCache, sysfs sysfs.SysFs, maxHousekeepingIn
148148
if err != nil {
149149
return nil, err
150150
}
151-
glog.Infof("cAdvisor running in container: %q", selfContainer)
151+
glog.V(2).Infof("cAdvisor running in container: %q", selfContainer)
152152

153153
var (
154154
dockerStatus info.DockerStatus
@@ -222,13 +222,13 @@ func New(memoryCache *memory.InMemoryCache, sysfs sysfs.SysFs, maxHousekeepingIn
222222
return nil, err
223223
}
224224
newManager.machineInfo = *machineInfo
225-
glog.Infof("Machine: %+v", newManager.machineInfo)
225+
glog.V(1).Infof("Machine: %+v", newManager.machineInfo)
226226

227227
versionInfo, err := getVersionInfo()
228228
if err != nil {
229229
return nil, err
230230
}
231-
glog.Infof("Version: %+v", *versionInfo)
231+
glog.V(1).Infof("Version: %+v", *versionInfo)
232232

233233
newManager.eventHandler = events.NewEventManager(parseEventsStoragePolicy())
234234
return newManager, nil
@@ -326,12 +326,12 @@ func (self *manager) Start() error {
326326
if err != nil {
327327
return err
328328
}
329-
glog.Infof("Starting recovery of all containers")
329+
glog.V(2).Infof("Starting recovery of all containers")
330330
err = self.detectSubcontainers("/")
331331
if err != nil {
332332
return err
333333
}
334-
glog.Infof("Recovery completed")
334+
glog.V(2).Infof("Recovery completed")
335335

336336
// Watch for new container.
337337
quitWatcher := make(chan error)
@@ -849,29 +849,25 @@ func (m *manager) registerCollectors(collectorConfigs map[string]string, cont *c
849849
if err != nil {
850850
return fmt.Errorf("failed to read config file %q for config %q, container %q: %v", k, v, cont.info.Name, err)
851851
}
852-
glog.V(3).Infof("Got config from %q: %q", v, configFile)
852+
glog.V(4).Infof("Got config from %q: %q", v, configFile)
853853

854854
if strings.HasPrefix(k, "prometheus") || strings.HasPrefix(k, "Prometheus") {
855855
newCollector, err := collector.NewPrometheusCollector(k, configFile, *applicationMetricsCountLimit, cont.handler, m.collectorHttpClient)
856856
if err != nil {
857-
glog.Infof("failed to create collector for container %q, config %q: %v", cont.info.Name, k, err)
858-
return err
857+
return fmt.Errorf("failed to create collector for container %q, config %q: %v", cont.info.Name, k, err)
859858
}
860859
err = cont.collectorManager.RegisterCollector(newCollector)
861860
if err != nil {
862-
glog.Infof("failed to register collector for container %q, config %q: %v", cont.info.Name, k, err)
863-
return err
861+
return fmt.Errorf("failed to register collector for container %q, config %q: %v", cont.info.Name, k, err)
864862
}
865863
} else {
866864
newCollector, err := collector.NewCollector(k, configFile, *applicationMetricsCountLimit, cont.handler, m.collectorHttpClient)
867865
if err != nil {
868-
glog.Infof("failed to create collector for container %q, config %q: %v", cont.info.Name, k, err)
869-
return err
866+
return fmt.Errorf("failed to create collector for container %q, config %q: %v", cont.info.Name, k, err)
870867
}
871868
err = cont.collectorManager.RegisterCollector(newCollector)
872869
if err != nil {
873-
glog.Infof("failed to register collector for container %q, config %q: %v", cont.info.Name, k, err)
874-
return err
870+
return fmt.Errorf("failed to register collector for container %q, config %q: %v", cont.info.Name, k, err)
875871
}
876872
}
877873
}
@@ -946,11 +942,11 @@ func (m *manager) createContainerLocked(containerName string, watchSource watche
946942
}
947943
devicesCgroupPath, err := handler.GetCgroupPath("devices")
948944
if err != nil {
949-
glog.Infof("Error getting devices cgroup path: %v", err)
945+
glog.Warningf("Error getting devices cgroup path: %v", err)
950946
} else {
951947
cont.nvidiaCollector, err = m.nvidiaManager.GetCollector(devicesCgroupPath)
952948
if err != nil {
953-
glog.Infof("GPU metrics may be unavailable/incomplete for container %q: %v", cont.info.Name, err)
949+
glog.V(4).Infof("GPU metrics may be unavailable/incomplete for container %q: %v", cont.info.Name, err)
954950
}
955951
}
956952

@@ -959,7 +955,7 @@ func (m *manager) createContainerLocked(containerName string, watchSource watche
959955
collectorConfigs := collector.GetCollectorConfigs(labels)
960956
err = m.registerCollectors(collectorConfigs, cont)
961957
if err != nil {
962-
glog.Infof("failed to register collectors for %q: %v", containerName, err)
958+
glog.Warningf("Failed to register collectors for %q: %v", containerName, err)
963959
}
964960

965961
// Add the container name and all its aliases. The aliases must be within the namespace of the factory.
@@ -1179,7 +1175,7 @@ func (self *manager) watchForNewContainers(quit chan error) error {
11791175
}
11801176

11811177
func (self *manager) watchForNewOoms() error {
1182-
glog.Infof("Started watching for new ooms in manager")
1178+
glog.V(2).Infof("Started watching for new ooms in manager")
11831179
outStream := make(chan *oomparser.OomInstance, 10)
11841180
oomLog, err := oomparser.New()
11851181
if err != nil {

manager/watcher/rkt/rkt.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (self *rktContainerWatcher) Stop() error {
5353
}
5454

5555
func (self *rktContainerWatcher) detectRktContainers(events chan watcher.ContainerEvent) {
56-
glog.Infof("starting detectRktContainers thread")
56+
glog.V(1).Infof("Starting detectRktContainers thread")
5757
ticker := time.Tick(10 * time.Second)
5858
curpods := make(map[string]*rktapi.Pod)
5959

@@ -92,7 +92,7 @@ func (self *rktContainerWatcher) syncRunningPods(pods []*rktapi.Pod, events chan
9292
for id, pod := range curpods {
9393
if _, ok := newpods[id]; !ok {
9494
for _, cgroup := range podToCgroup(pod) {
95-
glog.Infof("cgroup to delete = %v", cgroup)
95+
glog.V(2).Infof("cgroup to delete = %v", cgroup)
9696
self.sendDestroyEvent(cgroup, events)
9797
}
9898
}

0 commit comments

Comments
 (0)