2015-05-26 12:47:57 -07:00
|
|
|
// +build linux
|
|
|
|
|
2014-05-23 19:45:53 +00:00
|
|
|
package cgroups
|
|
|
|
|
|
|
|
type ThrottlingData struct {
|
|
|
|
// Number of periods with throttling active
|
2014-05-28 00:01:08 +00:00
|
|
|
Periods uint64 `json:"periods,omitempty"`
|
2014-05-23 19:45:53 +00:00
|
|
|
// Number of periods when the container hit its throttling limit.
|
2014-05-28 00:01:08 +00:00
|
|
|
ThrottledPeriods uint64 `json:"throttled_periods,omitempty"`
|
2014-05-23 19:45:53 +00:00
|
|
|
// Aggregate time the container was throttled for in nanoseconds.
|
2014-05-28 00:01:08 +00:00
|
|
|
ThrottledTime uint64 `json:"throttled_time,omitempty"`
|
2014-05-23 19:45:53 +00:00
|
|
|
}
|
|
|
|
|
2016-05-04 13:09:53 -07:00
|
|
|
// CpuUsage denotes the usage of a CPU.
|
2014-09-09 10:49:57 -07:00
|
|
|
// All CPU stats are aggregate since container inception.
|
2014-05-23 19:45:53 +00:00
|
|
|
type CpuUsage struct {
|
2014-09-09 10:49:57 -07:00
|
|
|
// Total CPU time consumed.
|
|
|
|
// Units: nanoseconds.
|
|
|
|
TotalUsage uint64 `json:"total_usage,omitempty"`
|
|
|
|
// Total CPU time consumed per core.
|
|
|
|
// Units: nanoseconds.
|
2014-06-19 15:23:19 -07:00
|
|
|
PercpuUsage []uint64 `json:"percpu_usage,omitempty"`
|
2014-09-09 10:49:57 -07:00
|
|
|
// Time spent by tasks of the cgroup in kernel mode.
|
|
|
|
// Units: nanoseconds.
|
2014-06-04 06:41:03 +00:00
|
|
|
UsageInKernelmode uint64 `json:"usage_in_kernelmode"`
|
2014-09-09 10:49:57 -07:00
|
|
|
// Time spent by tasks of the cgroup in user mode.
|
|
|
|
// Units: nanoseconds.
|
2014-06-04 06:41:03 +00:00
|
|
|
UsageInUsermode uint64 `json:"usage_in_usermode"`
|
2014-05-23 19:45:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type CpuStats struct {
|
|
|
|
CpuUsage CpuUsage `json:"cpu_usage,omitempty"`
|
2014-11-17 12:16:37 -08:00
|
|
|
ThrottlingData ThrottlingData `json:"throttling_data,omitempty"`
|
2014-05-23 19:45:53 +00:00
|
|
|
}
|
|
|
|
|
2015-06-15 18:18:38 -04:00
|
|
|
type MemoryData struct {
|
|
|
|
Usage uint64 `json:"usage,omitempty"`
|
|
|
|
MaxUsage uint64 `json:"max_usage,omitempty"`
|
|
|
|
Failcnt uint64 `json:"failcnt"`
|
2016-01-26 18:05:13 -05:00
|
|
|
Limit uint64 `json:"limit"`
|
2015-06-15 18:18:38 -04:00
|
|
|
}
|
2016-01-26 18:05:13 -05:00
|
|
|
|
2014-05-23 19:45:53 +00:00
|
|
|
type MemoryStats struct {
|
2015-05-04 11:02:44 -06:00
|
|
|
// memory used for cache
|
|
|
|
Cache uint64 `json:"cache,omitempty"`
|
2015-06-15 18:18:38 -04:00
|
|
|
// usage of memory
|
|
|
|
Usage MemoryData `json:"usage,omitempty"`
|
|
|
|
// usage of memory + swap
|
|
|
|
SwapUsage MemoryData `json:"swap_usage,omitempty"`
|
2016-03-18 11:43:13 -07:00
|
|
|
// usage of kernel memory
|
2016-03-31 08:25:51 +11:00
|
|
|
KernelUsage MemoryData `json:"kernel_usage,omitempty"`
|
|
|
|
// usage of kernel TCP memory
|
|
|
|
KernelTCPUsage MemoryData `json:"kernel_tcp_usage,omitempty"`
|
|
|
|
|
|
|
|
Stats map[string]uint64 `json:"stats,omitempty"`
|
2014-05-23 19:45:53 +00:00
|
|
|
}
|
|
|
|
|
2016-01-26 18:05:13 -05:00
|
|
|
type PidsStats struct {
|
|
|
|
// number of pids in the cgroup
|
|
|
|
Current uint64 `json:"current,omitempty"`
|
2016-03-31 08:25:51 +11:00
|
|
|
// active pids hard limit
|
|
|
|
Limit uint64 `json:"limit,omitempty"`
|
2016-01-26 18:05:13 -05:00
|
|
|
}
|
|
|
|
|
2014-05-23 19:45:53 +00:00
|
|
|
type BlkioStatEntry struct {
|
2014-05-28 00:01:08 +00:00
|
|
|
Major uint64 `json:"major,omitempty"`
|
|
|
|
Minor uint64 `json:"minor,omitempty"`
|
2014-05-23 19:45:53 +00:00
|
|
|
Op string `json:"op,omitempty"`
|
2014-05-28 00:01:08 +00:00
|
|
|
Value uint64 `json:"value,omitempty"`
|
2014-05-23 19:45:53 +00:00
|
|
|
}
|
|
|
|
|
2014-05-28 00:01:08 +00:00
|
|
|
type BlkioStats struct {
|
2014-05-23 19:45:53 +00:00
|
|
|
// number of bytes tranferred to and from the block device
|
|
|
|
IoServiceBytesRecursive []BlkioStatEntry `json:"io_service_bytes_recursive,omitempty"`
|
2014-10-28 22:19:01 +00:00
|
|
|
IoServicedRecursive []BlkioStatEntry `json:"io_serviced_recursive,omitempty"`
|
2014-05-23 19:45:53 +00:00
|
|
|
IoQueuedRecursive []BlkioStatEntry `json:"io_queue_recursive,omitempty"`
|
2014-10-28 22:19:01 +00:00
|
|
|
IoServiceTimeRecursive []BlkioStatEntry `json:"io_service_time_recursive,omitempty"`
|
|
|
|
IoWaitTimeRecursive []BlkioStatEntry `json:"io_wait_time_recursive,omitempty"`
|
|
|
|
IoMergedRecursive []BlkioStatEntry `json:"io_merged_recursive,omitempty"`
|
|
|
|
IoTimeRecursive []BlkioStatEntry `json:"io_time_recursive,omitempty"`
|
2014-05-28 00:01:08 +00:00
|
|
|
SectorsRecursive []BlkioStatEntry `json:"sectors_recursive,omitempty"`
|
2014-05-23 19:45:53 +00:00
|
|
|
}
|
|
|
|
|
2015-06-15 18:18:38 -04:00
|
|
|
type HugetlbStats struct {
|
|
|
|
// current res_counter usage for hugetlb
|
|
|
|
Usage uint64 `json:"usage,omitempty"`
|
|
|
|
// maximum usage ever recorded.
|
|
|
|
MaxUsage uint64 `json:"max_usage,omitempty"`
|
2016-03-18 11:43:13 -07:00
|
|
|
// number of times hugetlb usage allocation failure.
|
2015-06-15 18:18:38 -04:00
|
|
|
Failcnt uint64 `json:"failcnt"`
|
|
|
|
}
|
|
|
|
|
2014-05-23 19:45:53 +00:00
|
|
|
type Stats struct {
|
2014-07-14 12:30:19 -07:00
|
|
|
CpuStats CpuStats `json:"cpu_stats,omitempty"`
|
|
|
|
MemoryStats MemoryStats `json:"memory_stats,omitempty"`
|
2016-01-26 18:05:13 -05:00
|
|
|
PidsStats PidsStats `json:"pids_stats,omitempty"`
|
2014-07-14 12:30:19 -07:00
|
|
|
BlkioStats BlkioStats `json:"blkio_stats,omitempty"`
|
2015-06-15 18:18:38 -04:00
|
|
|
// the map is in the format "size of hugepage: stats of the hugepage"
|
|
|
|
HugetlbStats map[string]HugetlbStats `json:"hugetlb_stats,omitempty"`
|
2014-05-23 19:45:53 +00:00
|
|
|
}
|
2014-05-28 00:01:08 +00:00
|
|
|
|
|
|
|
func NewStats() *Stats {
|
|
|
|
memoryStats := MemoryStats{Stats: make(map[string]uint64)}
|
2015-06-15 18:18:38 -04:00
|
|
|
hugetlbStats := make(map[string]HugetlbStats)
|
|
|
|
return &Stats{MemoryStats: memoryStats, HugetlbStats: hugetlbStats}
|
2014-05-28 00:01:08 +00:00
|
|
|
}
|