machine.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. package v2
  15. import (
  16. // TODO(rjnagal): Move structs from v1.
  17. "time"
  18. v1 "github.com/google/cadvisor/info/v1"
  19. )
  20. type Attributes struct {
  21. // Kernel version.
  22. KernelVersion string `json:"kernel_version"`
  23. // OS image being used for cadvisor container, or host image if running on host directly.
  24. ContainerOsVersion string `json:"container_os_version"`
  25. // Docker version.
  26. DockerVersion string `json:"docker_version"`
  27. // Docker API version.
  28. DockerAPIVersion string `json:"docker_api_version"`
  29. // cAdvisor version.
  30. CadvisorVersion string `json:"cadvisor_version"`
  31. // The number of cores in this machine.
  32. NumCores int `json:"num_cores"`
  33. // Maximum clock speed for the cores, in KHz.
  34. CpuFrequency uint64 `json:"cpu_frequency_khz"`
  35. // The amount of memory (in bytes) in this machine
  36. MemoryCapacity uint64 `json:"memory_capacity"`
  37. // The machine id
  38. MachineID string `json:"machine_id"`
  39. // The system uuid
  40. SystemUUID string `json:"system_uuid"`
  41. // HugePages on this machine.
  42. HugePages []v1.HugePagesInfo `json:"hugepages"`
  43. // Filesystems on this machine.
  44. Filesystems []v1.FsInfo `json:"filesystems"`
  45. // Disk map
  46. DiskMap map[string]v1.DiskInfo `json:"disk_map"`
  47. // Network devices
  48. NetworkDevices []v1.NetInfo `json:"network_devices"`
  49. // Machine Topology
  50. // Describes cpu/memory layout and hierarchy.
  51. Topology []v1.Node `json:"topology"`
  52. // Cloud provider the machine belongs to
  53. CloudProvider v1.CloudProvider `json:"cloud_provider"`
  54. // Type of cloud instance (e.g. GCE standard) the machine is.
  55. InstanceType v1.InstanceType `json:"instance_type"`
  56. }
  57. func GetAttributes(mi *v1.MachineInfo, vi *v1.VersionInfo) Attributes {
  58. return Attributes{
  59. KernelVersion: vi.KernelVersion,
  60. ContainerOsVersion: vi.ContainerOsVersion,
  61. DockerVersion: vi.DockerVersion,
  62. DockerAPIVersion: vi.DockerAPIVersion,
  63. CadvisorVersion: vi.CadvisorVersion,
  64. NumCores: mi.NumCores,
  65. CpuFrequency: mi.CpuFrequency,
  66. MemoryCapacity: mi.MemoryCapacity,
  67. MachineID: mi.MachineID,
  68. SystemUUID: mi.SystemUUID,
  69. HugePages: mi.HugePages,
  70. Filesystems: mi.Filesystems,
  71. DiskMap: mi.DiskMap,
  72. NetworkDevices: mi.NetworkDevices,
  73. Topology: mi.Topology,
  74. CloudProvider: mi.CloudProvider,
  75. InstanceType: mi.InstanceType,
  76. }
  77. }
  78. // MachineStats contains usage statistics for the entire machine.
  79. type MachineStats struct {
  80. // The time of this stat point.
  81. Timestamp time.Time `json:"timestamp"`
  82. // In nanoseconds (aggregated)
  83. Cpu *v1.CpuStats `json:"cpu,omitempty"`
  84. // In nanocores per second (instantaneous)
  85. CpuInst *CpuInstStats `json:"cpu_inst,omitempty"`
  86. // Memory statistics
  87. Memory *v1.MemoryStats `json:"memory,omitempty"`
  88. // Network statistics
  89. Network *NetworkStats `json:"network,omitempty"`
  90. // Filesystem statistics
  91. Filesystem []MachineFsStats `json:"filesystem,omitempty"`
  92. // Task load statistics
  93. Load *v1.LoadStats `json:"load_stats,omitempty"`
  94. }
  95. // MachineFsStats contains per filesystem capacity and usage information.
  96. type MachineFsStats struct {
  97. // The block device name associated with the filesystem.
  98. Device string `json:"device"`
  99. // Type of filesystem.
  100. Type string `json:"type"`
  101. // Number of bytes that can be consumed on this filesystem.
  102. Capacity *uint64 `json:"capacity,omitempty"`
  103. // Number of bytes that is currently consumed on this filesystem.
  104. Usage *uint64 `json:"usage,omitempty"`
  105. // Number of bytes available for non-root user on this filesystem.
  106. Available *uint64 `json:"available,omitempty"`
  107. // Number of inodes that are available on this filesystem.
  108. InodesFree *uint64 `json:"inodes_free,omitempty"`
  109. // DiskStats for this device.
  110. DiskStats `json:"inline"`
  111. }
  112. // DiskStats contains per partition usage information.
  113. // This information is only available at the machine level.
  114. type DiskStats struct {
  115. // Number of reads completed
  116. // This is the total number of reads completed successfully.
  117. ReadsCompleted *uint64 `json:"reads_completed,omitempty"`
  118. // Number of reads merged
  119. // Reads and writes which are adjacent to each other may be merged for
  120. // efficiency. Thus two 4K reads may become one 8K read before it is
  121. // ultimately handed to the disk, and so it will be counted (and queued)
  122. // as only one I/O. This field lets you know how often this was done.
  123. ReadsMerged *uint64 `json:"reads_merged,omitempty"`
  124. // Number of sectors read
  125. // This is the total number of sectors read successfully.
  126. SectorsRead *uint64 `json:"sectors_read,omitempty"`
  127. // Time spent reading
  128. // This is the total number of milliseconds spent by all reads (as
  129. // measured from __make_request() to end_that_request_last()).
  130. ReadDuration *time.Duration `json:"read_duration,omitempty"`
  131. // Number of writes completed
  132. // This is the total number of writes completed successfully.
  133. WritesCompleted *uint64 `json:"writes_completed,omitempty"`
  134. // Number of writes merged
  135. // See the description of reads merged.
  136. WritesMerged *uint64 `json:"writes_merged,omitempty"`
  137. // Number of sectors written
  138. // This is the total number of sectors written successfully.
  139. SectorsWritten *uint64 `json:"sectors_written,omitempty"`
  140. // Time spent writing
  141. // This is the total number of milliseconds spent by all writes (as
  142. // measured from __make_request() to end_that_request_last()).
  143. WriteDuration *time.Duration `json:"write_duration,omitempty"`
  144. // Number of I/Os currently in progress
  145. // The only field that should go to zero. Incremented as requests are
  146. // given to appropriate struct request_queue and decremented as they finish.
  147. IoInProgress *uint64 `json:"io_in_progress,omitempty"`
  148. // Time spent doing I/Os
  149. // This field increases so long as field 9 is nonzero.
  150. IoDuration *time.Duration `json:"io_duration,omitempty"`
  151. // weighted time spent doing I/Os
  152. // This field is incremented at each I/O start, I/O completion, I/O
  153. // merge, or read of these stats by the number of I/Os in progress
  154. // (field 9) times the number of milliseconds spent doing I/O since the
  155. // last update of this field. This can provide an easy measure of both
  156. // I/O completion time and the backlog that may be accumulating.
  157. WeightedIoDuration *time.Duration `json:"weighted_io_duration,omitempty"`
  158. }