From 0b580ff32d9ea6b35c0e9e6ecdd9aa4340c700a5 Mon Sep 17 00:00:00 2001 From: Vishnu Kannan Date: Fri, 23 May 2014 19:45:53 +0000 Subject: [PATCH] Added stats.go which provides strong types for all stats that will be exported by libcontainer. This commit only introduces the strong type. Docker-DCO-1.1-Signed-off-by: Vishnu Kannan (github: vishh) --- cgroups/stats.go | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 cgroups/stats.go diff --git a/cgroups/stats.go b/cgroups/stats.go new file mode 100644 index 00000000..fbcd5dd2 --- /dev/null +++ b/cgroups/stats.go @@ -0,0 +1,59 @@ +package cgroups + +type ThrottlingData struct { + // Number of periods with throttling active + Periods int64 `json:"periods,omitempty"` + // Number of periods when the container hit its throttling limit. + ThrottledPeriods int64 `json:"throttled_periods,omitempty"` + // Aggregate time the container was throttled for in nanoseconds. + ThrottledTime int64 `json:"throttled_time,omitempty"` +} + +type CpuUsage struct { + // percentage of available CPUs currently being used. + PercentUsage int64 `json:"percent_usage,omitempty"` + // nanoseconds of cpu time consumed over the last 100 ms. + CurrentUsage int64 `json:"current_usage,omitempty"` +} + +type CpuStats struct { + CpuUsage CpuUsage `json:"cpu_usage,omitempty"` + ThrottlingData ThrottlingData `json:"throlling_data,omitempty"` +} + +type MemoryStats struct { + // current res_counter usage for memory + Usage int64 `json:"usage,omitempty"` + // maximum usage ever recorded. + MaxUsage int64 `json:"max_usage,omitempty"` + // TODO(vishh): Export these as stronger types. + // all the stats exported via memory.stat. + Stats map[string]int64 `json:"stats,omitempty"` +} + +type BlkioStatEntry struct { + Major int64 `json:"major,omitempty"` + Minor int64 `json:"minor,omitempty"` + Op string `json:"op,omitempty"` + Value int64 `json:"value,omitempty"` +} + +type BlockioStats struct { + // number of bytes tranferred to and from the block device + IoServiceBytesRecursive []BlkioStatEntry `json:"io_service_bytes_recursive,omitempty"` + IoServicedRecursive []BlkioStatEntry `json:"io_serviced_recusrive,omitempty"` + IoQueuedRecursive []BlkioStatEntry `json:"io_queue_recursive,omitempty"` +} + +// TODO(Vishh): Remove freezer from stats since it does not logically belong in stats. +type FreezerStats struct { + ParentState string `json:"parent_state,omitempty"` + SelfState string `json:"self_state,omitempty"` +} + +type Stats struct { + CpuStats CpuStats `json:"cpu_stats,omitempty"` + MemoryStats MemoryStats `json:"memory_stats,omitempty"` + BlockioStats BlockioStats `json:"blockio_stats,omitempty"` + FreezerStats FreezerStats `json:"freezer_stats,omitempty"` +}