github.com/google/cadvisor@v0.49.1/info/v1/machine.go (about)

     1  // Copyright 2014 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 v1
    16  
    17  import "time"
    18  
    19  type FsInfo struct {
    20  	// Block device associated with the filesystem.
    21  	Device string `json:"device"`
    22  	// DeviceMajor is the major identifier of the device, used for correlation with blkio stats
    23  	DeviceMajor uint64 `json:"-"`
    24  	// DeviceMinor is the minor identifier of the device, used for correlation with blkio stats
    25  	DeviceMinor uint64 `json:"-"`
    26  
    27  	// Total number of bytes available on the filesystem.
    28  	Capacity uint64 `json:"capacity"`
    29  
    30  	// Type of device.
    31  	Type string `json:"type"`
    32  
    33  	// Total number of inodes available on the filesystem.
    34  	Inodes uint64 `json:"inodes"`
    35  
    36  	// HasInodes when true, indicates that Inodes info will be available.
    37  	HasInodes bool `json:"has_inodes"`
    38  }
    39  
    40  type Node struct {
    41  	Id int `json:"node_id"`
    42  	// Per-node memory
    43  	Memory    uint64          `json:"memory"`
    44  	HugePages []HugePagesInfo `json:"hugepages"`
    45  	Cores     []Core          `json:"cores"`
    46  	Caches    []Cache         `json:"caches"`
    47  	Distances []uint64        `json:"distances"`
    48  }
    49  
    50  type Core struct {
    51  	Id           int     `json:"core_id"`
    52  	Threads      []int   `json:"thread_ids"`
    53  	Caches       []Cache `json:"caches"`
    54  	UncoreCaches []Cache `json:"uncore_caches"`
    55  	SocketID     int     `json:"socket_id"`
    56  }
    57  
    58  type Cache struct {
    59  	// Id of memory cache
    60  	Id int `json:"id"`
    61  	// Size of memory cache in bytes.
    62  	Size uint64 `json:"size"`
    63  	// Type of memory cache: data, instruction, or unified.
    64  	Type string `json:"type"`
    65  	// Level (distance from cpus) in a multi-level cache hierarchy.
    66  	Level int `json:"level"`
    67  }
    68  
    69  func (n *Node) FindCore(id int) (bool, int) {
    70  	for i, n := range n.Cores {
    71  		if n.Id == id {
    72  			return true, i
    73  		}
    74  	}
    75  	return false, -1
    76  }
    77  
    78  // FindCoreByThread returns bool if found Core with same thread as provided and it's index in Node Core array.
    79  // If it's not found, returns false and -1.
    80  func (n *Node) FindCoreByThread(thread int) (bool, int) {
    81  	for i, n := range n.Cores {
    82  		for _, t := range n.Threads {
    83  			if t == thread {
    84  				return true, i
    85  			}
    86  		}
    87  	}
    88  	return false, -1
    89  }
    90  
    91  func (n *Node) AddThread(thread int, core int) {
    92  	var coreIdx int
    93  	if core == -1 {
    94  		// Assume one hyperthread per core when topology data is missing.
    95  		core = thread
    96  	}
    97  	ok, coreIdx := n.FindCore(core)
    98  
    99  	if !ok {
   100  		// New core
   101  		core := Core{Id: core}
   102  		n.Cores = append(n.Cores, core)
   103  		coreIdx = len(n.Cores) - 1
   104  	}
   105  	n.Cores[coreIdx].Threads = append(n.Cores[coreIdx].Threads, thread)
   106  }
   107  
   108  func (n *Node) AddNodeCache(c Cache) {
   109  	n.Caches = append(n.Caches, c)
   110  }
   111  
   112  func (n *Node) AddPerCoreCache(c Cache) {
   113  	for idx := range n.Cores {
   114  		n.Cores[idx].Caches = append(n.Cores[idx].Caches, c)
   115  	}
   116  }
   117  
   118  type HugePagesInfo struct {
   119  	// huge page size (in kB)
   120  	PageSize uint64 `json:"page_size"`
   121  
   122  	// number of huge pages
   123  	NumPages uint64 `json:"num_pages"`
   124  }
   125  
   126  type DiskInfo struct {
   127  	// device name
   128  	Name string `json:"name"`
   129  
   130  	// Major number
   131  	Major uint64 `json:"major"`
   132  
   133  	// Minor number
   134  	Minor uint64 `json:"minor"`
   135  
   136  	// Size in bytes
   137  	Size uint64 `json:"size"`
   138  
   139  	// I/O Scheduler - one of "none", "noop", "cfq", "deadline"
   140  	Scheduler string `json:"scheduler"`
   141  }
   142  
   143  type NetInfo struct {
   144  	// Device name
   145  	Name string `json:"name"`
   146  
   147  	// Mac Address
   148  	MacAddress string `json:"mac_address"`
   149  
   150  	// Speed in MBits/s
   151  	Speed int64 `json:"speed"`
   152  
   153  	// Maximum Transmission Unit
   154  	Mtu int64 `json:"mtu"`
   155  }
   156  
   157  type CloudProvider string
   158  
   159  const (
   160  	GCE             CloudProvider = "GCE"
   161  	AWS             CloudProvider = "AWS"
   162  	Azure           CloudProvider = "Azure"
   163  	UnknownProvider CloudProvider = "Unknown"
   164  )
   165  
   166  type InstanceType string
   167  
   168  const (
   169  	UnknownInstance = "Unknown"
   170  )
   171  
   172  type InstanceID string
   173  
   174  const (
   175  	UnNamedInstance InstanceID = "None"
   176  )
   177  
   178  type MachineInfo struct {
   179  	// The time of this information point.
   180  	Timestamp time.Time `json:"timestamp"`
   181  
   182  	// Vendor id of CPU.
   183  	CPUVendorID string `json:"vendor_id"`
   184  
   185  	// The number of cores in this machine.
   186  	NumCores int `json:"num_cores"`
   187  
   188  	// The number of physical cores in this machine.
   189  	NumPhysicalCores int `json:"num_physical_cores"`
   190  
   191  	// The number of cpu sockets in this machine.
   192  	NumSockets int `json:"num_sockets"`
   193  
   194  	// Maximum clock speed for the cores, in KHz.
   195  	CpuFrequency uint64 `json:"cpu_frequency_khz"`
   196  
   197  	// The amount of memory (in bytes) in this machine
   198  	MemoryCapacity uint64 `json:"memory_capacity"`
   199  
   200  	// The amount of swap (in bytes) in this machine
   201  	SwapCapacity uint64 `json:"swap_capacity"`
   202  
   203  	// Memory capacity and number of DIMMs by memory type
   204  	MemoryByType map[string]*MemoryInfo `json:"memory_by_type"`
   205  
   206  	NVMInfo NVMInfo `json:"nvm"`
   207  
   208  	// HugePages on this machine.
   209  	HugePages []HugePagesInfo `json:"hugepages"`
   210  
   211  	// The machine id
   212  	MachineID string `json:"machine_id"`
   213  
   214  	// The system uuid
   215  	SystemUUID string `json:"system_uuid"`
   216  
   217  	// The boot id
   218  	BootID string `json:"boot_id"`
   219  
   220  	// Filesystems on this machine.
   221  	Filesystems []FsInfo `json:"filesystems"`
   222  
   223  	// Disk map
   224  	DiskMap map[string]DiskInfo `json:"disk_map"`
   225  
   226  	// Network devices
   227  	NetworkDevices []NetInfo `json:"network_devices"`
   228  
   229  	// Machine Topology
   230  	// Describes cpu/memory layout and hierarchy.
   231  	Topology []Node `json:"topology"`
   232  
   233  	// Cloud provider the machine belongs to.
   234  	CloudProvider CloudProvider `json:"cloud_provider"`
   235  
   236  	// Type of cloud instance (e.g. GCE standard) the machine is.
   237  	InstanceType InstanceType `json:"instance_type"`
   238  
   239  	// ID of cloud instance (e.g. instance-1) given to it by the cloud provider.
   240  	InstanceID InstanceID `json:"instance_id"`
   241  }
   242  
   243  func (m *MachineInfo) Clone() *MachineInfo {
   244  	memoryByType := m.MemoryByType
   245  	if len(m.MemoryByType) > 0 {
   246  		memoryByType = make(map[string]*MemoryInfo)
   247  		for memoryType, memoryInfo := range m.MemoryByType {
   248  			memoryByType[memoryType] = memoryInfo
   249  		}
   250  	}
   251  	diskMap := m.DiskMap
   252  	if len(m.DiskMap) > 0 {
   253  		diskMap = make(map[string]DiskInfo)
   254  		for k, info := range m.DiskMap {
   255  			diskMap[k] = info
   256  		}
   257  	}
   258  	copy := MachineInfo{
   259  		CPUVendorID:      m.CPUVendorID,
   260  		Timestamp:        m.Timestamp,
   261  		NumCores:         m.NumCores,
   262  		NumPhysicalCores: m.NumPhysicalCores,
   263  		NumSockets:       m.NumSockets,
   264  		CpuFrequency:     m.CpuFrequency,
   265  		MemoryCapacity:   m.MemoryCapacity,
   266  		SwapCapacity:     m.SwapCapacity,
   267  		MemoryByType:     memoryByType,
   268  		NVMInfo:          m.NVMInfo,
   269  		HugePages:        m.HugePages,
   270  		MachineID:        m.MachineID,
   271  		SystemUUID:       m.SystemUUID,
   272  		BootID:           m.BootID,
   273  		Filesystems:      m.Filesystems,
   274  		DiskMap:          diskMap,
   275  		NetworkDevices:   m.NetworkDevices,
   276  		Topology:         m.Topology,
   277  		CloudProvider:    m.CloudProvider,
   278  		InstanceType:     m.InstanceType,
   279  		InstanceID:       m.InstanceID,
   280  	}
   281  	return &copy
   282  }
   283  
   284  type MemoryInfo struct {
   285  	// The amount of memory (in bytes).
   286  	Capacity uint64 `json:"capacity"`
   287  
   288  	// Number of memory DIMMs.
   289  	DimmCount uint `json:"dimm_count"`
   290  }
   291  
   292  type NVMInfo struct {
   293  	// The total NVM capacity in bytes for memory mode.
   294  	MemoryModeCapacity uint64 `json:"memory_mode_capacity"`
   295  
   296  	//The total NVM capacity in bytes for app direct mode.
   297  	AppDirectModeCapacity uint64 `json:"app direct_mode_capacity"`
   298  
   299  	// Average power budget in watts for NVM devices configured in BIOS.
   300  	AvgPowerBudget uint `json:"avg_power_budget"`
   301  }
   302  
   303  type VersionInfo struct {
   304  	// Kernel version.
   305  	KernelVersion string `json:"kernel_version"`
   306  
   307  	// OS image being used for cadvisor container, or host image if running on host directly.
   308  	ContainerOsVersion string `json:"container_os_version"`
   309  
   310  	// Docker version.
   311  	DockerVersion string `json:"docker_version"`
   312  
   313  	// Docker API Version
   314  	DockerAPIVersion string `json:"docker_api_version"`
   315  
   316  	// cAdvisor version.
   317  	CadvisorVersion string `json:"cadvisor_version"`
   318  	// cAdvisor git revision.
   319  	CadvisorRevision string `json:"cadvisor_revision"`
   320  }
   321  
   322  type MachineInfoFactory interface {
   323  	GetMachineInfo() (*MachineInfo, error)
   324  	GetVersionInfo() (*VersionInfo, error)
   325  }