machine.go 5.6 KB

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