machine.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. package v1
  15. type FsInfo struct {
  16. // Block device associated with the filesystem.
  17. Device string `json:"device"`
  18. // DeviceMajor is the major identifier of the device, used for correlation with blkio stats
  19. DeviceMajor uint64 `json:"-"`
  20. // DeviceMinor is the minor identifier of the device, used for correlation with blkio stats
  21. DeviceMinor uint64 `json:"-"`
  22. // Total number of bytes available on the filesystem.
  23. Capacity uint64 `json:"capacity"`
  24. // Type of device.
  25. Type string `json:"type"`
  26. // Total number of inodes available on the filesystem.
  27. Inodes uint64 `json:"inodes"`
  28. // HasInodes when true, indicates that Inodes info will be available.
  29. HasInodes bool `json:"has_inodes"`
  30. }
  31. type Node struct {
  32. Id int `json:"node_id"`
  33. // Per-node memory
  34. Memory uint64 `json:"memory"`
  35. Cores []Core `json:"cores"`
  36. Caches []Cache `json:"caches"`
  37. }
  38. type Core struct {
  39. Id int `json:"core_id"`
  40. Threads []int `json:"thread_ids"`
  41. Caches []Cache `json:"caches"`
  42. }
  43. type Cache struct {
  44. // Size of memory cache in bytes.
  45. Size uint64 `json:"size"`
  46. // Type of memory cache: data, instruction, or unified.
  47. Type string `json:"type"`
  48. // Level (distance from cpus) in a multi-level cache hierarchy.
  49. Level int `json:"level"`
  50. }
  51. func (self *Node) FindCore(id int) (bool, int) {
  52. for i, n := range self.Cores {
  53. if n.Id == id {
  54. return true, i
  55. }
  56. }
  57. return false, -1
  58. }
  59. func (self *Node) AddThread(thread int, core int) {
  60. var coreIdx int
  61. if core == -1 {
  62. // Assume one hyperthread per core when topology data is missing.
  63. core = thread
  64. }
  65. ok, coreIdx := self.FindCore(core)
  66. if !ok {
  67. // New core
  68. core := Core{Id: core}
  69. self.Cores = append(self.Cores, core)
  70. coreIdx = len(self.Cores) - 1
  71. }
  72. self.Cores[coreIdx].Threads = append(self.Cores[coreIdx].Threads, thread)
  73. }
  74. func (self *Node) AddNodeCache(c Cache) {
  75. self.Caches = append(self.Caches, c)
  76. }
  77. func (self *Node) AddPerCoreCache(c Cache) {
  78. for idx := range self.Cores {
  79. self.Cores[idx].Caches = append(self.Cores[idx].Caches, c)
  80. }
  81. }
  82. type HugePagesInfo struct {
  83. // huge page size (in kB)
  84. PageSize uint64 `json:"page_size"`
  85. // number of huge pages
  86. NumPages uint64 `json:"num_pages"`
  87. }
  88. type DiskInfo struct {
  89. // device name
  90. Name string `json:"name"`
  91. // Major number
  92. Major uint64 `json:"major"`
  93. // Minor number
  94. Minor uint64 `json:"minor"`
  95. // Size in bytes
  96. Size uint64 `json:"size"`
  97. // I/O Scheduler - one of "none", "noop", "cfq", "deadline"
  98. Scheduler string `json:"scheduler"`
  99. }
  100. type NetInfo struct {
  101. // Device name
  102. Name string `json:"name"`
  103. // Mac Address
  104. MacAddress string `json:"mac_address"`
  105. // Speed in MBits/s
  106. Speed int64 `json:"speed"`
  107. // Maximum Transmission Unit
  108. Mtu int64 `json:"mtu"`
  109. }
  110. type CloudProvider string
  111. const (
  112. GCE CloudProvider = "GCE"
  113. AWS = "AWS"
  114. Azure = "Azure"
  115. Baremetal = "Baremetal"
  116. UnknownProvider = "Unknown"
  117. )
  118. type InstanceType string
  119. const (
  120. NoInstance InstanceType = "None"
  121. UnknownInstance = "Unknown"
  122. )
  123. type InstanceID string
  124. const (
  125. UnNamedInstance InstanceID = "None"
  126. )
  127. type MachineInfo struct {
  128. // The number of cores in this machine.
  129. NumCores int `json:"num_cores"`
  130. // Maximum clock speed for the cores, in KHz.
  131. CpuFrequency uint64 `json:"cpu_frequency_khz"`
  132. // The amount of memory (in bytes) in this machine
  133. MemoryCapacity uint64 `json:"memory_capacity"`
  134. // HugePages on this machine.
  135. HugePages []HugePagesInfo `json:"hugepages"`
  136. // The machine id
  137. MachineID string `json:"machine_id"`
  138. // The system uuid
  139. SystemUUID string `json:"system_uuid"`
  140. // The boot id
  141. BootID string `json:"boot_id"`
  142. // Filesystems on this machine.
  143. Filesystems []FsInfo `json:"filesystems"`
  144. // Disk map
  145. DiskMap map[string]DiskInfo `json:"disk_map"`
  146. // Network devices
  147. NetworkDevices []NetInfo `json:"network_devices"`
  148. // Machine Topology
  149. // Describes cpu/memory layout and hierarchy.
  150. Topology []Node `json:"topology"`
  151. // Cloud provider the machine belongs to.
  152. CloudProvider CloudProvider `json:"cloud_provider"`
  153. // Type of cloud instance (e.g. GCE standard) the machine is.
  154. InstanceType InstanceType `json:"instance_type"`
  155. // ID of cloud instance (e.g. instance-1) given to it by the cloud provider.
  156. InstanceID InstanceID `json:"instance_id"`
  157. }
  158. type VersionInfo struct {
  159. // Kernel version.
  160. KernelVersion string `json:"kernel_version"`
  161. // OS image being used for cadvisor container, or host image if running on host directly.
  162. ContainerOsVersion string `json:"container_os_version"`
  163. // Docker version.
  164. DockerVersion string `json:"docker_version"`
  165. // Docker API Version
  166. DockerAPIVersion string `json:"docker_api_version"`
  167. // cAdvisor version.
  168. CadvisorVersion string `json:"cadvisor_version"`
  169. // cAdvisor git revision.
  170. CadvisorRevision string `json:"cadvisor_revision"`
  171. }
  172. type MachineInfoFactory interface {
  173. GetMachineInfo() (*MachineInfo, error)
  174. GetVersionInfo() (*VersionInfo, error)
  175. }