container.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  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. import (
  16. "reflect"
  17. "time"
  18. )
  19. type CpuSpec struct {
  20. Limit uint64 `json:"limit"`
  21. MaxLimit uint64 `json:"max_limit"`
  22. Mask string `json:"mask,omitempty"`
  23. Quota uint64 `json:"quota,omitempty"`
  24. Period uint64 `json:"period,omitempty"`
  25. }
  26. type MemorySpec struct {
  27. // The amount of memory requested. Default is unlimited (-1).
  28. // Units: bytes.
  29. Limit uint64 `json:"limit,omitempty"`
  30. // The amount of guaranteed memory. Default is 0.
  31. // Units: bytes.
  32. Reservation uint64 `json:"reservation,omitempty"`
  33. // The amount of swap space requested. Default is unlimited (-1).
  34. // Units: bytes.
  35. SwapLimit uint64 `json:"swap_limit,omitempty"`
  36. }
  37. type ProcessSpec struct {
  38. Limit uint64 `json:"limit,omitempty"`
  39. }
  40. type ContainerSpec struct {
  41. // Time at which the container was created.
  42. CreationTime time.Time `json:"creation_time,omitempty"`
  43. // Metadata labels associated with this container.
  44. Labels map[string]string `json:"labels,omitempty"`
  45. // Metadata envs associated with this container. Only whitelisted envs are added.
  46. Envs map[string]string `json:"envs,omitempty"`
  47. HasCpu bool `json:"has_cpu"`
  48. Cpu CpuSpec `json:"cpu,omitempty"`
  49. HasMemory bool `json:"has_memory"`
  50. Memory MemorySpec `json:"memory,omitempty"`
  51. HasNetwork bool `json:"has_network"`
  52. HasProcesses bool `json:"has_processes"`
  53. Processes ProcessSpec `json:"processes,omitempty"`
  54. HasFilesystem bool `json:"has_filesystem"`
  55. // HasDiskIo when true, indicates that DiskIo stats will be available.
  56. HasDiskIo bool `json:"has_diskio"`
  57. HasCustomMetrics bool `json:"has_custom_metrics"`
  58. CustomMetrics []MetricSpec `json:"custom_metrics,omitempty"`
  59. // Image name used for this container.
  60. Image string `json:"image,omitempty"`
  61. }
  62. // Container reference contains enough information to uniquely identify a container
  63. type ContainerReference struct {
  64. // The container id
  65. Id string `json:"id,omitempty"`
  66. // The absolute name of the container. This is unique on the machine.
  67. Name string `json:"name"`
  68. // Other names by which the container is known within a certain namespace.
  69. // This is unique within that namespace.
  70. Aliases []string `json:"aliases,omitempty"`
  71. // Namespace under which the aliases of a container are unique.
  72. // An example of a namespace is "docker" for Docker containers.
  73. Namespace string `json:"namespace,omitempty"`
  74. }
  75. // Sorts by container name.
  76. type ContainerReferenceSlice []ContainerReference
  77. func (self ContainerReferenceSlice) Len() int { return len(self) }
  78. func (self ContainerReferenceSlice) Swap(i, j int) { self[i], self[j] = self[j], self[i] }
  79. func (self ContainerReferenceSlice) Less(i, j int) bool { return self[i].Name < self[j].Name }
  80. // ContainerInfoRequest is used when users check a container info from the REST API.
  81. // It specifies how much data users want to get about a container
  82. type ContainerInfoRequest struct {
  83. // Max number of stats to return. Specify -1 for all stats currently available.
  84. // Default: 60
  85. NumStats int `json:"num_stats,omitempty"`
  86. // Start time for which to query information.
  87. // If omitted, the beginning of time is assumed.
  88. Start time.Time `json:"start,omitempty"`
  89. // End time for which to query information.
  90. // If omitted, current time is assumed.
  91. End time.Time `json:"end,omitempty"`
  92. }
  93. // Returns a ContainerInfoRequest with all default values specified.
  94. func DefaultContainerInfoRequest() ContainerInfoRequest {
  95. return ContainerInfoRequest{
  96. NumStats: 60,
  97. }
  98. }
  99. func (self *ContainerInfoRequest) Equals(other ContainerInfoRequest) bool {
  100. return self.NumStats == other.NumStats &&
  101. self.Start.Equal(other.Start) &&
  102. self.End.Equal(other.End)
  103. }
  104. type ContainerInfo struct {
  105. ContainerReference
  106. // The direct subcontainers of the current container.
  107. Subcontainers []ContainerReference `json:"subcontainers,omitempty"`
  108. // The isolation used in the container.
  109. Spec ContainerSpec `json:"spec,omitempty"`
  110. // Historical statistics gathered from the container.
  111. Stats []*ContainerStats `json:"stats,omitempty"`
  112. }
  113. // TODO(vmarmol): Refactor to not need this equality comparison.
  114. // ContainerInfo may be (un)marshaled by json or other en/decoder. In that
  115. // case, the Timestamp field in each stats/sample may not be precisely
  116. // en/decoded. This will lead to small but acceptable differences between a
  117. // ContainerInfo and its encode-then-decode version. Eq() is used to compare
  118. // two ContainerInfo accepting small difference (<10ms) of Time fields.
  119. func (self *ContainerInfo) Eq(b *ContainerInfo) bool {
  120. // If both self and b are nil, then Eq() returns true
  121. if self == nil {
  122. return b == nil
  123. }
  124. if b == nil {
  125. return self == nil
  126. }
  127. // For fields other than time.Time, we will compare them precisely.
  128. // This would require that any slice should have same order.
  129. if !reflect.DeepEqual(self.ContainerReference, b.ContainerReference) {
  130. return false
  131. }
  132. if !reflect.DeepEqual(self.Subcontainers, b.Subcontainers) {
  133. return false
  134. }
  135. if !self.Spec.Eq(&b.Spec) {
  136. return false
  137. }
  138. for i, expectedStats := range b.Stats {
  139. selfStats := self.Stats[i]
  140. if !expectedStats.Eq(selfStats) {
  141. return false
  142. }
  143. }
  144. return true
  145. }
  146. func (self *ContainerSpec) Eq(b *ContainerSpec) bool {
  147. // Creation within 1s of each other.
  148. diff := self.CreationTime.Sub(b.CreationTime)
  149. if (diff > time.Second) || (diff < -time.Second) {
  150. return false
  151. }
  152. if self.HasCpu != b.HasCpu {
  153. return false
  154. }
  155. if !reflect.DeepEqual(self.Cpu, b.Cpu) {
  156. return false
  157. }
  158. if self.HasMemory != b.HasMemory {
  159. return false
  160. }
  161. if !reflect.DeepEqual(self.Memory, b.Memory) {
  162. return false
  163. }
  164. if self.HasNetwork != b.HasNetwork {
  165. return false
  166. }
  167. if self.HasFilesystem != b.HasFilesystem {
  168. return false
  169. }
  170. if self.HasDiskIo != b.HasDiskIo {
  171. return false
  172. }
  173. if self.HasCustomMetrics != b.HasCustomMetrics {
  174. return false
  175. }
  176. return true
  177. }
  178. func (self *ContainerInfo) StatsAfter(ref time.Time) []*ContainerStats {
  179. n := len(self.Stats) + 1
  180. for i, s := range self.Stats {
  181. if s.Timestamp.After(ref) {
  182. n = i
  183. break
  184. }
  185. }
  186. if n > len(self.Stats) {
  187. return nil
  188. }
  189. return self.Stats[n:]
  190. }
  191. func (self *ContainerInfo) StatsStartTime() time.Time {
  192. var ret time.Time
  193. for _, s := range self.Stats {
  194. if s.Timestamp.Before(ret) || ret.IsZero() {
  195. ret = s.Timestamp
  196. }
  197. }
  198. return ret
  199. }
  200. func (self *ContainerInfo) StatsEndTime() time.Time {
  201. var ret time.Time
  202. for i := len(self.Stats) - 1; i >= 0; i-- {
  203. s := self.Stats[i]
  204. if s.Timestamp.After(ret) {
  205. ret = s.Timestamp
  206. }
  207. }
  208. return ret
  209. }
  210. // This mirrors kernel internal structure.
  211. type LoadStats struct {
  212. // Number of sleeping tasks.
  213. NrSleeping uint64 `json:"nr_sleeping"`
  214. // Number of running tasks.
  215. NrRunning uint64 `json:"nr_running"`
  216. // Number of tasks in stopped state
  217. NrStopped uint64 `json:"nr_stopped"`
  218. // Number of tasks in uninterruptible state
  219. NrUninterruptible uint64 `json:"nr_uninterruptible"`
  220. // Number of tasks waiting on IO
  221. NrIoWait uint64 `json:"nr_io_wait"`
  222. }
  223. // CPU usage time statistics.
  224. type CpuUsage struct {
  225. // Total CPU usage.
  226. // Unit: nanoseconds.
  227. Total uint64 `json:"total"`
  228. // Per CPU/core usage of the container.
  229. // Unit: nanoseconds.
  230. PerCpu []uint64 `json:"per_cpu_usage,omitempty"`
  231. // Time spent in user space.
  232. // Unit: nanoseconds.
  233. User uint64 `json:"user"`
  234. // Time spent in kernel space.
  235. // Unit: nanoseconds.
  236. System uint64 `json:"system"`
  237. }
  238. // Cpu Completely Fair Scheduler statistics.
  239. type CpuCFS struct {
  240. // Total number of elapsed enforcement intervals.
  241. Periods uint64 `json:"periods"`
  242. // Total number of times tasks in the cgroup have been throttled.
  243. ThrottledPeriods uint64 `json:"throttled_periods"`
  244. // Total time duration for which tasks in the cgroup have been throttled.
  245. // Unit: nanoseconds.
  246. ThrottledTime uint64 `json:"throttled_time"`
  247. }
  248. // Cpu Aggregated scheduler statistics
  249. type CpuSchedstat struct {
  250. // https://www.kernel.org/doc/Documentation/scheduler/sched-stats.txt
  251. // time spent on the cpu
  252. RunTime uint64 `json:"run_time"`
  253. // time spent waiting on a runqueue
  254. RunqueueTime uint64 `json:"runqueue_time"`
  255. // # of timeslices run on this cpu
  256. RunPeriods uint64 `json:"run_periods"`
  257. }
  258. // All CPU usage metrics are cumulative from the creation of the container
  259. type CpuStats struct {
  260. Usage CpuUsage `json:"usage"`
  261. CFS CpuCFS `json:"cfs"`
  262. Schedstat CpuSchedstat `json:"schedstat"`
  263. // Smoothed average of number of runnable threads x 1000.
  264. // We multiply by thousand to avoid using floats, but preserving precision.
  265. // Load is smoothed over the last 10 seconds. Instantaneous value can be read
  266. // from LoadStats.NrRunning.
  267. LoadAverage int32 `json:"load_average"`
  268. }
  269. type PerDiskStats struct {
  270. Device string `json:"device"`
  271. Major uint64 `json:"major"`
  272. Minor uint64 `json:"minor"`
  273. Stats map[string]uint64 `json:"stats"`
  274. }
  275. type DiskIoStats struct {
  276. IoServiceBytes []PerDiskStats `json:"io_service_bytes,omitempty"`
  277. IoServiced []PerDiskStats `json:"io_serviced,omitempty"`
  278. IoQueued []PerDiskStats `json:"io_queued,omitempty"`
  279. Sectors []PerDiskStats `json:"sectors,omitempty"`
  280. IoServiceTime []PerDiskStats `json:"io_service_time,omitempty"`
  281. IoWaitTime []PerDiskStats `json:"io_wait_time,omitempty"`
  282. IoMerged []PerDiskStats `json:"io_merged,omitempty"`
  283. IoTime []PerDiskStats `json:"io_time,omitempty"`
  284. }
  285. type MemoryStats struct {
  286. // Current memory usage, this includes all memory regardless of when it was
  287. // accessed.
  288. // Units: Bytes.
  289. Usage uint64 `json:"usage"`
  290. // Maximum memory usage recorded.
  291. // Units: Bytes.
  292. MaxUsage uint64 `json:"max_usage"`
  293. // Number of bytes of page cache memory.
  294. // Units: Bytes.
  295. Cache uint64 `json:"cache"`
  296. // The amount of anonymous and swap cache memory (includes transparent
  297. // hugepages).
  298. // Units: Bytes.
  299. RSS uint64 `json:"rss"`
  300. // The amount of swap currently used by the processes in this cgroup
  301. // Units: Bytes.
  302. Swap uint64 `json:"swap"`
  303. // The amount of memory used for mapped files (includes tmpfs/shmem)
  304. MappedFile uint64 `json:"mapped_file"`
  305. // The amount of working set memory, this includes recently accessed memory,
  306. // dirty memory, and kernel memory. Working set is <= "usage".
  307. // Units: Bytes.
  308. WorkingSet uint64 `json:"working_set"`
  309. Failcnt uint64 `json:"failcnt"`
  310. ContainerData MemoryStatsMemoryData `json:"container_data,omitempty"`
  311. HierarchicalData MemoryStatsMemoryData `json:"hierarchical_data,omitempty"`
  312. }
  313. type MemoryStatsMemoryData struct {
  314. Pgfault uint64 `json:"pgfault"`
  315. Pgmajfault uint64 `json:"pgmajfault"`
  316. }
  317. type InterfaceStats struct {
  318. // The name of the interface.
  319. Name string `json:"name"`
  320. // Cumulative count of bytes received.
  321. RxBytes uint64 `json:"rx_bytes"`
  322. // Cumulative count of packets received.
  323. RxPackets uint64 `json:"rx_packets"`
  324. // Cumulative count of receive errors encountered.
  325. RxErrors uint64 `json:"rx_errors"`
  326. // Cumulative count of packets dropped while receiving.
  327. RxDropped uint64 `json:"rx_dropped"`
  328. // Cumulative count of bytes transmitted.
  329. TxBytes uint64 `json:"tx_bytes"`
  330. // Cumulative count of packets transmitted.
  331. TxPackets uint64 `json:"tx_packets"`
  332. // Cumulative count of transmit errors encountered.
  333. TxErrors uint64 `json:"tx_errors"`
  334. // Cumulative count of packets dropped while transmitting.
  335. TxDropped uint64 `json:"tx_dropped"`
  336. }
  337. type NetworkStats struct {
  338. InterfaceStats `json:",inline"`
  339. Interfaces []InterfaceStats `json:"interfaces,omitempty"`
  340. // TCP connection stats (Established, Listen...)
  341. Tcp TcpStat `json:"tcp"`
  342. // TCP6 connection stats (Established, Listen...)
  343. Tcp6 TcpStat `json:"tcp6"`
  344. // UDP connection stats
  345. Udp UdpStat `json:"udp"`
  346. // UDP6 connection stats
  347. Udp6 UdpStat `json:"udp6"`
  348. }
  349. type TcpStat struct {
  350. // Count of TCP connections in state "Established"
  351. Established uint64
  352. // Count of TCP connections in state "Syn_Sent"
  353. SynSent uint64
  354. // Count of TCP connections in state "Syn_Recv"
  355. SynRecv uint64
  356. // Count of TCP connections in state "Fin_Wait1"
  357. FinWait1 uint64
  358. // Count of TCP connections in state "Fin_Wait2"
  359. FinWait2 uint64
  360. // Count of TCP connections in state "Time_Wait
  361. TimeWait uint64
  362. // Count of TCP connections in state "Close"
  363. Close uint64
  364. // Count of TCP connections in state "Close_Wait"
  365. CloseWait uint64
  366. // Count of TCP connections in state "Listen_Ack"
  367. LastAck uint64
  368. // Count of TCP connections in state "Listen"
  369. Listen uint64
  370. // Count of TCP connections in state "Closing"
  371. Closing uint64
  372. }
  373. type UdpStat struct {
  374. // Count of UDP sockets in state "Listen"
  375. Listen uint64
  376. // Count of UDP packets dropped by the IP stack
  377. Dropped uint64
  378. // Count of packets Queued for Receieve
  379. RxQueued uint64
  380. // Count of packets Queued for Transmit
  381. TxQueued uint64
  382. }
  383. type FsStats struct {
  384. // The block device name associated with the filesystem.
  385. Device string `json:"device,omitempty"`
  386. // Type of the filesytem.
  387. Type string `json:"type"`
  388. // Number of bytes that can be consumed by the container on this filesystem.
  389. Limit uint64 `json:"capacity"`
  390. // Number of bytes that is consumed by the container on this filesystem.
  391. Usage uint64 `json:"usage"`
  392. // Base Usage that is consumed by the container's writable layer.
  393. // This field is only applicable for docker container's as of now.
  394. BaseUsage uint64 `json:"base_usage"`
  395. // Number of bytes available for non-root user.
  396. Available uint64 `json:"available"`
  397. // HasInodes when true, indicates that Inodes info will be available.
  398. HasInodes bool `json:"has_inodes"`
  399. // Number of Inodes
  400. Inodes uint64 `json:"inodes"`
  401. // Number of available Inodes
  402. InodesFree uint64 `json:"inodes_free"`
  403. // Number of reads completed
  404. // This is the total number of reads completed successfully.
  405. ReadsCompleted uint64 `json:"reads_completed"`
  406. // Number of reads merged
  407. // Reads and writes which are adjacent to each other may be merged for
  408. // efficiency. Thus two 4K reads may become one 8K read before it is
  409. // ultimately handed to the disk, and so it will be counted (and queued)
  410. // as only one I/O. This field lets you know how often this was done.
  411. ReadsMerged uint64 `json:"reads_merged"`
  412. // Number of sectors read
  413. // This is the total number of sectors read successfully.
  414. SectorsRead uint64 `json:"sectors_read"`
  415. // Number of milliseconds spent reading
  416. // This is the total number of milliseconds spent by all reads (as
  417. // measured from __make_request() to end_that_request_last()).
  418. ReadTime uint64 `json:"read_time"`
  419. // Number of writes completed
  420. // This is the total number of writes completed successfully.
  421. WritesCompleted uint64 `json:"writes_completed"`
  422. // Number of writes merged
  423. // See the description of reads merged.
  424. WritesMerged uint64 `json:"writes_merged"`
  425. // Number of sectors written
  426. // This is the total number of sectors written successfully.
  427. SectorsWritten uint64 `json:"sectors_written"`
  428. // Number of milliseconds spent writing
  429. // This is the total number of milliseconds spent by all writes (as
  430. // measured from __make_request() to end_that_request_last()).
  431. WriteTime uint64 `json:"write_time"`
  432. // Number of I/Os currently in progress
  433. // The only field that should go to zero. Incremented as requests are
  434. // given to appropriate struct request_queue and decremented as they finish.
  435. IoInProgress uint64 `json:"io_in_progress"`
  436. // Number of milliseconds spent doing I/Os
  437. // This field increases so long as field 9 is nonzero.
  438. IoTime uint64 `json:"io_time"`
  439. // weighted number of milliseconds spent doing I/Os
  440. // This field is incremented at each I/O start, I/O completion, I/O
  441. // merge, or read of these stats by the number of I/Os in progress
  442. // (field 9) times the number of milliseconds spent doing I/O since the
  443. // last update of this field. This can provide an easy measure of both
  444. // I/O completion time and the backlog that may be accumulating.
  445. WeightedIoTime uint64 `json:"weighted_io_time"`
  446. }
  447. type AcceleratorStats struct {
  448. // Make of the accelerator (nvidia, amd, google etc.)
  449. Make string `json:"make"`
  450. // Model of the accelerator (tesla-p100, tesla-k80 etc.)
  451. Model string `json:"model"`
  452. // ID of the accelerator.
  453. ID string `json:"id"`
  454. // Total accelerator memory.
  455. // unit: bytes
  456. MemoryTotal uint64 `json:"memory_total"`
  457. // Total accelerator memory allocated.
  458. // unit: bytes
  459. MemoryUsed uint64 `json:"memory_used"`
  460. // Percent of time over the past sample period during which
  461. // the accelerator was actively processing.
  462. DutyCycle uint64 `json:"duty_cycle"`
  463. }
  464. type ProcessStats struct {
  465. // Number of processes
  466. ProcessCount uint64 `json:"process_count"`
  467. // Number of open file descriptors
  468. FdCount uint64 `json:"fd_count"`
  469. // Number of sockets
  470. SocketCount uint64 `json:"socket_count"`
  471. // Number of threads currently in container
  472. ThreadsCurrent uint64 `json:"threads_current,omitempty"`
  473. // Maxium number of threads allowed in container
  474. ThreadsMax uint64 `json:"threads_max,omitempty"`
  475. }
  476. type ContainerStats struct {
  477. // The time of this stat point.
  478. Timestamp time.Time `json:"timestamp"`
  479. Cpu CpuStats `json:"cpu,omitempty"`
  480. DiskIo DiskIoStats `json:"diskio,omitempty"`
  481. Memory MemoryStats `json:"memory,omitempty"`
  482. Network NetworkStats `json:"network,omitempty"`
  483. // Filesystem statistics
  484. Filesystem []FsStats `json:"filesystem,omitempty"`
  485. // Task load stats
  486. TaskStats LoadStats `json:"task_stats,omitempty"`
  487. // Metrics for Accelerators. Each Accelerator corresponds to one element in the array.
  488. Accelerators []AcceleratorStats `json:"accelerators,omitempty"`
  489. // ProcessStats for Containers
  490. Processes ProcessStats `json:"processes,omitempty"`
  491. // Custom metrics from all collectors
  492. CustomMetrics map[string][]MetricVal `json:"custom_metrics,omitempty"`
  493. }
  494. func timeEq(t1, t2 time.Time, tolerance time.Duration) bool {
  495. // t1 should not be later than t2
  496. if t1.After(t2) {
  497. t1, t2 = t2, t1
  498. }
  499. diff := t2.Sub(t1)
  500. if diff <= tolerance {
  501. return true
  502. }
  503. return false
  504. }
  505. const (
  506. // 10ms, i.e. 0.01s
  507. timePrecision time.Duration = 10 * time.Millisecond
  508. )
  509. // This function is useful because we do not require precise time
  510. // representation.
  511. func (a *ContainerStats) Eq(b *ContainerStats) bool {
  512. if !timeEq(a.Timestamp, b.Timestamp, timePrecision) {
  513. return false
  514. }
  515. return a.StatsEq(b)
  516. }
  517. // Checks equality of the stats values.
  518. func (a *ContainerStats) StatsEq(b *ContainerStats) bool {
  519. // TODO(vmarmol): Consider using this through reflection.
  520. if !reflect.DeepEqual(a.Cpu, b.Cpu) {
  521. return false
  522. }
  523. if !reflect.DeepEqual(a.Memory, b.Memory) {
  524. return false
  525. }
  526. if !reflect.DeepEqual(a.DiskIo, b.DiskIo) {
  527. return false
  528. }
  529. if !reflect.DeepEqual(a.Network, b.Network) {
  530. return false
  531. }
  532. if !reflect.DeepEqual(a.Processes, b.Processes) {
  533. return false
  534. }
  535. if !reflect.DeepEqual(a.Filesystem, b.Filesystem) {
  536. return false
  537. }
  538. return true
  539. }
  540. // Event contains information general to events such as the time at which they
  541. // occurred, their specific type, and the actual event. Event types are
  542. // differentiated by the EventType field of Event.
  543. type Event struct {
  544. // the absolute container name for which the event occurred
  545. ContainerName string `json:"container_name"`
  546. // the time at which the event occurred
  547. Timestamp time.Time `json:"timestamp"`
  548. // the type of event. EventType is an enumerated type
  549. EventType EventType `json:"event_type"`
  550. // the original event object and all of its extraneous data, ex. an
  551. // OomInstance
  552. EventData EventData `json:"event_data,omitempty"`
  553. }
  554. // EventType is an enumerated type which lists the categories under which
  555. // events may fall. The Event field EventType is populated by this enum.
  556. type EventType string
  557. const (
  558. EventOom EventType = "oom"
  559. EventOomKill = "oomKill"
  560. EventContainerCreation = "containerCreation"
  561. EventContainerDeletion = "containerDeletion"
  562. )
  563. // Extra information about an event. Only one type will be set.
  564. type EventData struct {
  565. // Information about an OOM kill event.
  566. OomKill *OomKillEventData `json:"oom,omitempty"`
  567. }
  568. // Information related to an OOM kill instance
  569. type OomKillEventData struct {
  570. // process id of the killed process
  571. Pid int `json:"pid"`
  572. // The name of the killed process
  573. ProcessName string `json:"process_name"`
  574. }