github.com/google/cadvisor@v0.49.1/integration/tests/api/machinestats_test.go (about) 1 // Copyright 2015 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package api 16 17 import ( 18 "testing" 19 "time" 20 21 "github.com/stretchr/testify/assert" 22 "github.com/stretchr/testify/require" 23 24 "github.com/google/cadvisor/integration/framework" 25 "github.com/opencontainers/runc/libcontainer/cgroups" 26 ) 27 28 func TestMachineStatsIsReturned(t *testing.T) { 29 fm := framework.New(t) 30 defer fm.Cleanup() 31 32 machineStats, err := fm.Cadvisor().ClientV2().MachineStats() 33 if err != nil { 34 t.Fatal(err) 35 } 36 37 as := assert.New(t) 38 for _, stat := range machineStats { 39 as.NotEqual(stat.Timestamp, time.Time{}) 40 as.True(stat.Cpu.Usage.Total > 0) 41 // PerCPU CPU usage is not supported in cgroupv2 (cpuacct.usage_percpu) 42 // https://github.com/google/cadvisor/issues/3065 43 if !cgroups.IsCgroup2UnifiedMode() { 44 as.True(len(stat.Cpu.Usage.PerCpu) > 0) 45 } 46 if stat.CpuInst != nil { 47 as.True(stat.CpuInst.Usage.Total > 0) 48 } 49 as.True(stat.Memory.Usage > 0) 50 for _, nStat := range stat.Network.Interfaces { 51 as.NotEqual(nStat.Name, "") 52 as.NotEqual(nStat.RxBytes, 0) 53 } 54 for _, fsStat := range stat.Filesystem { 55 as.NotEqual(fsStat.Device, "") 56 as.NotNil(fsStat.Capacity) 57 as.NotNil(fsStat.Usage) 58 as.NotNil(fsStat.ReadsCompleted) 59 require.NotEmpty(t, fsStat.Type) 60 if fsStat.Type == "vfs" { 61 as.NotNil(fsStat.InodesFree) 62 } 63 } 64 } 65 }