2015-05-14 06:42:16 +08:00
|
|
|
// +build linux
|
|
|
|
|
2014-05-24 03:45:53 +08:00
|
|
|
package cgroups
|
|
|
|
|
|
|
|
type ThrottlingData struct {
|
|
|
|
// Number of periods with throttling active
|
2014-05-28 08:01:08 +08:00
|
|
|
Periods uint64 `json:"periods,omitempty"`
|
2014-05-24 03:45:53 +08:00
|
|
|
// Number of periods when the container hit its throttling limit.
|
2014-05-28 08:01:08 +08:00
|
|
|
ThrottledPeriods uint64 `json:"throttled_periods,omitempty"`
|
2014-05-24 03:45:53 +08:00
|
|
|
// Aggregate time the container was throttled for in nanoseconds.
|
2014-05-28 08:01:08 +08:00
|
|
|
ThrottledTime uint64 `json:"throttled_time,omitempty"`
|
2014-05-24 03:45:53 +08:00
|
|
|
}
|
|
|
|
|
2016-04-12 16:12:23 +08:00
|
|
|
// CpuUsage denotes the usage of a CPU.
|
2014-08-31 00:58:27 +08:00
|
|
|
// All CPU stats are aggregate since container inception.
|
2014-05-24 03:45:53 +08:00
|
|
|
type CpuUsage struct {
|
2014-08-31 00:58:27 +08:00
|
|
|
// Total CPU time consumed.
|
|
|
|
// Units: nanoseconds.
|
|
|
|
TotalUsage uint64 `json:"total_usage,omitempty"`
|
|
|
|
// Total CPU time consumed per core.
|
|
|
|
// Units: nanoseconds.
|
2014-06-19 18:35:36 +08:00
|
|
|
PercpuUsage []uint64 `json:"percpu_usage,omitempty"`
|
2014-08-31 00:58:27 +08:00
|
|
|
// Time spent by tasks of the cgroup in kernel mode.
|
|
|
|
// Units: nanoseconds.
|
2014-06-04 14:41:03 +08:00
|
|
|
UsageInKernelmode uint64 `json:"usage_in_kernelmode"`
|
2014-08-31 00:58:27 +08:00
|
|
|
// Time spent by tasks of the cgroup in user mode.
|
|
|
|
// Units: nanoseconds.
|
2014-06-04 14:41:03 +08:00
|
|
|
UsageInUsermode uint64 `json:"usage_in_usermode"`
|
2014-05-24 03:45:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type CpuStats struct {
|
|
|
|
CpuUsage CpuUsage `json:"cpu_usage,omitempty"`
|
2014-11-12 07:34:55 +08:00
|
|
|
ThrottlingData ThrottlingData `json:"throttling_data,omitempty"`
|
2014-05-24 03:45:53 +08:00
|
|
|
}
|
|
|
|
|
2015-05-15 17:37:58 +08:00
|
|
|
type MemoryData struct {
|
|
|
|
Usage uint64 `json:"usage,omitempty"`
|
|
|
|
MaxUsage uint64 `json:"max_usage,omitempty"`
|
|
|
|
Failcnt uint64 `json:"failcnt"`
|
2016-02-04 03:00:48 +08:00
|
|
|
Limit uint64 `json:"limit"`
|
2015-05-15 17:37:58 +08:00
|
|
|
}
|
2016-02-04 03:00:48 +08:00
|
|
|
|
2014-05-24 03:45:53 +08:00
|
|
|
type MemoryStats struct {
|
2015-04-03 15:50:13 +08:00
|
|
|
// memory used for cache
|
|
|
|
Cache uint64 `json:"cache,omitempty"`
|
2015-05-15 17:37:58 +08:00
|
|
|
// usage of memory
|
|
|
|
Usage MemoryData `json:"usage,omitempty"`
|
|
|
|
// usage of memory + swap
|
|
|
|
SwapUsage MemoryData `json:"swap_usage,omitempty"`
|
2016-02-20 01:23:25 +08:00
|
|
|
// usage of kernel memory
|
2016-03-20 19:04:02 +08: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-24 03:45:53 +08:00
|
|
|
}
|
|
|
|
|
2015-12-14 21:33:56 +08:00
|
|
|
type PidsStats struct {
|
|
|
|
// number of pids in the cgroup
|
|
|
|
Current uint64 `json:"current,omitempty"`
|
2016-03-13 01:53:20 +08:00
|
|
|
// active pids hard limit
|
2016-03-14 14:45:12 +08:00
|
|
|
Limit uint64 `json:"limit,omitempty"`
|
2015-12-14 21:33:56 +08:00
|
|
|
}
|
|
|
|
|
2014-05-24 03:45:53 +08:00
|
|
|
type BlkioStatEntry struct {
|
2014-05-28 08:01:08 +08:00
|
|
|
Major uint64 `json:"major,omitempty"`
|
|
|
|
Minor uint64 `json:"minor,omitempty"`
|
2014-05-24 03:45:53 +08:00
|
|
|
Op string `json:"op,omitempty"`
|
2014-05-28 08:01:08 +08:00
|
|
|
Value uint64 `json:"value,omitempty"`
|
2014-05-24 03:45:53 +08:00
|
|
|
}
|
|
|
|
|
2014-05-28 08:01:08 +08:00
|
|
|
type BlkioStats struct {
|
2014-05-24 03:45:53 +08:00
|
|
|
// number of bytes tranferred to and from the block device
|
|
|
|
IoServiceBytesRecursive []BlkioStatEntry `json:"io_service_bytes_recursive,omitempty"`
|
2014-10-20 17:25:03 +08:00
|
|
|
IoServicedRecursive []BlkioStatEntry `json:"io_serviced_recursive,omitempty"`
|
2014-05-24 03:45:53 +08:00
|
|
|
IoQueuedRecursive []BlkioStatEntry `json:"io_queue_recursive,omitempty"`
|
2014-10-20 17:25:03 +08: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 08:01:08 +08:00
|
|
|
SectorsRecursive []BlkioStatEntry `json:"sectors_recursive,omitempty"`
|
2014-05-24 03:45:53 +08:00
|
|
|
}
|
|
|
|
|
2015-04-27 16:34:36 +08: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-02-20 01:23:25 +08:00
|
|
|
// number of times hugetlb usage allocation failure.
|
2015-04-27 16:34:36 +08:00
|
|
|
Failcnt uint64 `json:"failcnt"`
|
|
|
|
}
|
|
|
|
|
2014-05-24 03:45:53 +08:00
|
|
|
type Stats struct {
|
2014-07-14 07:14:05 +08:00
|
|
|
CpuStats CpuStats `json:"cpu_stats,omitempty"`
|
|
|
|
MemoryStats MemoryStats `json:"memory_stats,omitempty"`
|
2015-12-14 21:33:56 +08:00
|
|
|
PidsStats PidsStats `json:"pids_stats,omitempty"`
|
2014-07-14 07:14:05 +08:00
|
|
|
BlkioStats BlkioStats `json:"blkio_stats,omitempty"`
|
2015-04-27 16:34:36 +08:00
|
|
|
// the map is in the format "size of hugepage: stats of the hugepage"
|
|
|
|
HugetlbStats map[string]HugetlbStats `json:"hugetlb_stats,omitempty"`
|
2014-05-24 03:45:53 +08:00
|
|
|
}
|
2014-05-28 08:01:08 +08:00
|
|
|
|
|
|
|
func NewStats() *Stats {
|
|
|
|
memoryStats := MemoryStats{Stats: make(map[string]uint64)}
|
2015-04-27 16:34:36 +08:00
|
|
|
hugetlbStats := make(map[string]HugetlbStats)
|
|
|
|
return &Stats{MemoryStats: memoryStats, HugetlbStats: hugetlbStats}
|
2014-05-28 08:01:08 +08:00
|
|
|
}
|