container.go 20 KB

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