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. "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. Filesystems: mi.Filesystems,
  70. DiskMap: mi.DiskMap,
  71. NetworkDevices: mi.NetworkDevices,
  72. Topology: mi.Topology,
  73. CloudProvider: mi.CloudProvider,
  74. InstanceType: mi.InstanceType,
  75. }
  76. }
  77. // MachineStats contains usage statistics for the entire machine.
  78. type MachineStats struct {
  79. // The time of this stat point.
  80. Timestamp time.Time `json:"timestamp"`
  81. // In nanoseconds (aggregated)
  82. Cpu *v1.CpuStats `json:"cpu,omitempty"`
  83. // In nanocores per second (instantaneous)
  84. CpuInst *CpuInstStats `json:"cpu_inst,omitempty"`
  85. // Memory statistics
  86. Memory *v1.MemoryStats `json:"memory,omitempty"`
  87. // Network statistics
  88. Network *NetworkStats `json:"network,omitempty"`
  89. // Filesystem statistics
  90. Filesystem []MachineFsStats `json:"filesystem,omitempty"`
  91. // Task load statistics
  92. Load *v1.LoadStats `json:"load_stats,omitempty"`
  93. }
  94. // MachineFsStats contains per filesystem capacity and usage information.
  95. type MachineFsStats struct {
  96. // The block device name associated with the filesystem.
  97. Device string `json:"device"`
  98. // Type of filesystem.
  99. Type string `json:"type"`
  100. // Number of bytes that can be consumed on this filesystem.
  101. Capacity *uint64 `json:"capacity,omitempty"`
  102. // Number of bytes that is currently consumed on this filesystem.
  103. Usage *uint64 `json:"usage,omitempty"`
  104. // Number of bytes available for non-root user on this filesystem.
  105. Available *uint64 `json:"available,omitempty"`
  106. // Number of inodes that are available on this filesystem.
  107. InodesFree *uint64 `json:"inodes_free,omitempty"`
  108. // DiskStats for this device.
  109. DiskStats `json:"inline"`
  110. }
  111. // DiskStats contains per partition usage information.
  112. // This information is only available at the machine level.
  113. type DiskStats struct {
  114. // Number of reads completed
  115. // This is the total number of reads completed successfully.
  116. ReadsCompleted *uint64 `json:"reads_completed,omitempty"`
  117. // Number of reads merged
  118. // Reads and writes which are adjacent to each other may be merged for
  119. // efficiency. Thus two 4K reads may become one 8K read before it is
  120. // ultimately handed to the disk, and so it will be counted (and queued)
  121. // as only one I/O. This field lets you know how often this was done.
  122. ReadsMerged *uint64 `json:"reads_merged,omitempty"`
  123. // Number of sectors read
  124. // This is the total number of sectors read successfully.
  125. SectorsRead *uint64 `json:"sectors_read,omitempty"`
  126. // Time spent reading
  127. // This is the total number of milliseconds spent by all reads (as
  128. // measured from __make_request() to end_that_request_last()).
  129. ReadDuration *time.Duration `json:"read_duration,omitempty"`
  130. // Number of writes completed
  131. // This is the total number of writes completed successfully.
  132. WritesCompleted *uint64 `json:"writes_completed,omitempty"`
  133. // Number of writes merged
  134. // See the description of reads merged.
  135. WritesMerged *uint64 `json:"writes_merged,omitempty"`
  136. // Number of sectors written
  137. // This is the total number of sectors written successfully.
  138. SectorsWritten *uint64 `json:"sectors_written,omitempty"`
  139. // Time spent writing
  140. // This is the total number of milliseconds spent by all writes (as
  141. // measured from __make_request() to end_that_request_last()).
  142. WriteDuration *time.Duration `json:"write_duration,omitempty"`
  143. // Number of I/Os currently in progress
  144. // The only field that should go to zero. Incremented as requests are
  145. // given to appropriate struct request_queue and decremented as they finish.
  146. IoInProgress *uint64 `json:"io_in_progress,omitempty"`
  147. // Time spent doing I/Os
  148. // This field increases so long as field 9 is nonzero.
  149. IoDuration *time.Duration `json:"io_duration,omitempty"`
  150. // weighted time spent doing I/Os
  151. // This field is incremented at each I/O start, I/O completion, I/O
  152. // merge, or read of these stats by the number of I/Os in progress
  153. // (field 9) times the number of milliseconds spent doing I/O since the
  154. // last update of this field. This can provide an easy measure of both
  155. // I/O completion time and the backlog that may be accumulating.
  156. WeightedIoDuration *time.Duration `json:"weighted_io_duration,omitempty"`
  157. }