github.com/getong/docker@v1.13.1/api/types/stats.go (about)

     1  // Package types is used for API stability in the types and response to the
     2  // consumers of the API stats endpoint.
     3  package types
     4  
     5  import "time"
     6  
     7  // ThrottlingData stores CPU throttling stats of one running container.
     8  // Not used on Windows.
     9  type ThrottlingData struct {
    10  	// Number of periods with throttling active
    11  	Periods uint64 `json:"periods"`
    12  	// Number of periods when the container hits its throttling limit.
    13  	ThrottledPeriods uint64 `json:"throttled_periods"`
    14  	// Aggregate time the container was throttled for in nanoseconds.
    15  	ThrottledTime uint64 `json:"throttled_time"`
    16  }
    17  
    18  // CPUUsage stores All CPU stats aggregated since container inception.
    19  type CPUUsage struct {
    20  	// Total CPU time consumed.
    21  	// Units: nanoseconds (Linux)
    22  	// Units: 100's of nanoseconds (Windows)
    23  	TotalUsage uint64 `json:"total_usage"`
    24  
    25  	// Total CPU time consumed per core (Linux). Not used on Windows.
    26  	// Units: nanoseconds.
    27  	PercpuUsage []uint64 `json:"percpu_usage,omitempty"`
    28  
    29  	// Time spent by tasks of the cgroup in kernel mode (Linux).
    30  	// Time spent by all container processes in kernel mode (Windows).
    31  	// Units: nanoseconds (Linux).
    32  	// Units: 100's of nanoseconds (Windows). Not populated for Hyper-V Containers.
    33  	UsageInKernelmode uint64 `json:"usage_in_kernelmode"`
    34  
    35  	// Time spent by tasks of the cgroup in user mode (Linux).
    36  	// Time spent by all container processes in user mode (Windows).
    37  	// Units: nanoseconds (Linux).
    38  	// Units: 100's of nanoseconds (Windows). Not populated for Hyper-V Containers
    39  	UsageInUsermode uint64 `json:"usage_in_usermode"`
    40  }
    41  
    42  // CPUStats aggregates and wraps all CPU related info of container
    43  type CPUStats struct {
    44  	// CPU Usage. Linux and Windows.
    45  	CPUUsage CPUUsage `json:"cpu_usage"`
    46  
    47  	// System Usage. Linux only.
    48  	SystemUsage uint64 `json:"system_cpu_usage,omitempty"`
    49  
    50  	// Throttling Data. Linux only.
    51  	ThrottlingData ThrottlingData `json:"throttling_data,omitempty"`
    52  }
    53  
    54  // MemoryStats aggregates all memory stats since container inception on Linux.
    55  // Windows returns stats for commit and private working set only.
    56  type MemoryStats struct {
    57  	// Linux Memory Stats
    58  
    59  	// current res_counter usage for memory
    60  	Usage uint64 `json:"usage,omitempty"`
    61  	// maximum usage ever recorded.
    62  	MaxUsage uint64 `json:"max_usage,omitempty"`
    63  	// TODO(vishh): Export these as stronger types.
    64  	// all the stats exported via memory.stat.
    65  	Stats map[string]uint64 `json:"stats,omitempty"`
    66  	// number of times memory usage hits limits.
    67  	Failcnt uint64 `json:"failcnt,omitempty"`
    68  	Limit   uint64 `json:"limit,omitempty"`
    69  
    70  	// Windows Memory Stats
    71  	// See https://technet.microsoft.com/en-us/magazine/ff382715.aspx
    72  
    73  	// committed bytes
    74  	Commit uint64 `json:"commitbytes,omitempty"`
    75  	// peak committed bytes
    76  	CommitPeak uint64 `json:"commitpeakbytes,omitempty"`
    77  	// private working set
    78  	PrivateWorkingSet uint64 `json:"privateworkingset,omitempty"`
    79  }
    80  
    81  // BlkioStatEntry is one small entity to store a piece of Blkio stats
    82  // Not used on Windows.
    83  type BlkioStatEntry struct {
    84  	Major uint64 `json:"major"`
    85  	Minor uint64 `json:"minor"`
    86  	Op    string `json:"op"`
    87  	Value uint64 `json:"value"`
    88  }
    89  
    90  // BlkioStats stores All IO service stats for data read and write.
    91  // This is a Linux specific structure as the differences between expressing
    92  // block I/O on Windows and Linux are sufficiently significant to make
    93  // little sense attempting to morph into a combined structure.
    94  type BlkioStats struct {
    95  	// number of bytes transferred to and from the block device
    96  	IoServiceBytesRecursive []BlkioStatEntry `json:"io_service_bytes_recursive"`
    97  	IoServicedRecursive     []BlkioStatEntry `json:"io_serviced_recursive"`
    98  	IoQueuedRecursive       []BlkioStatEntry `json:"io_queue_recursive"`
    99  	IoServiceTimeRecursive  []BlkioStatEntry `json:"io_service_time_recursive"`
   100  	IoWaitTimeRecursive     []BlkioStatEntry `json:"io_wait_time_recursive"`
   101  	IoMergedRecursive       []BlkioStatEntry `json:"io_merged_recursive"`
   102  	IoTimeRecursive         []BlkioStatEntry `json:"io_time_recursive"`
   103  	SectorsRecursive        []BlkioStatEntry `json:"sectors_recursive"`
   104  }
   105  
   106  // StorageStats is the disk I/O stats for read/write on Windows.
   107  type StorageStats struct {
   108  	ReadCountNormalized  uint64 `json:"read_count_normalized,omitempty"`
   109  	ReadSizeBytes        uint64 `json:"read_size_bytes,omitempty"`
   110  	WriteCountNormalized uint64 `json:"write_count_normalized,omitempty"`
   111  	WriteSizeBytes       uint64 `json:"write_size_bytes,omitempty"`
   112  }
   113  
   114  // NetworkStats aggregates the network stats of one container
   115  type NetworkStats struct {
   116  	// Bytes received. Windows and Linux.
   117  	RxBytes uint64 `json:"rx_bytes"`
   118  	// Packets received. Windows and Linux.
   119  	RxPackets uint64 `json:"rx_packets"`
   120  	// Received errors. Not used on Windows. Note that we dont `omitempty` this
   121  	// field as it is expected in the >=v1.21 API stats structure.
   122  	RxErrors uint64 `json:"rx_errors"`
   123  	// Incoming packets dropped. Windows and Linux.
   124  	RxDropped uint64 `json:"rx_dropped"`
   125  	// Bytes sent. Windows and Linux.
   126  	TxBytes uint64 `json:"tx_bytes"`
   127  	// Packets sent. Windows and Linux.
   128  	TxPackets uint64 `json:"tx_packets"`
   129  	// Sent errors. Not used on Windows. Note that we dont `omitempty` this
   130  	// field as it is expected in the >=v1.21 API stats structure.
   131  	TxErrors uint64 `json:"tx_errors"`
   132  	// Outgoing packets dropped. Windows and Linux.
   133  	TxDropped uint64 `json:"tx_dropped"`
   134  	// Endpoint ID. Not used on Linux.
   135  	EndpointID string `json:"endpoint_id,omitempty"`
   136  	// Instance ID. Not used on Linux.
   137  	InstanceID string `json:"instance_id,omitempty"`
   138  }
   139  
   140  // PidsStats contains the stats of a container's pids
   141  type PidsStats struct {
   142  	// Current is the number of pids in the cgroup
   143  	Current uint64 `json:"current,omitempty"`
   144  	// Limit is the hard limit on the number of pids in the cgroup.
   145  	// A "Limit" of 0 means that there is no limit.
   146  	Limit uint64 `json:"limit,omitempty"`
   147  }
   148  
   149  // Stats is Ultimate struct aggregating all types of stats of one container
   150  type Stats struct {
   151  	// Common stats
   152  	Read    time.Time `json:"read"`
   153  	PreRead time.Time `json:"preread"`
   154  
   155  	// Linux specific stats, not populated on Windows.
   156  	PidsStats  PidsStats  `json:"pids_stats,omitempty"`
   157  	BlkioStats BlkioStats `json:"blkio_stats,omitempty"`
   158  
   159  	// Windows specific stats, not populated on Linux.
   160  	NumProcs     uint32       `json:"num_procs"`
   161  	StorageStats StorageStats `json:"storage_stats,omitempty"`
   162  
   163  	// Shared stats
   164  	CPUStats    CPUStats    `json:"cpu_stats,omitempty"`
   165  	PreCPUStats CPUStats    `json:"precpu_stats,omitempty"` // "Pre"="Previous"
   166  	MemoryStats MemoryStats `json:"memory_stats,omitempty"`
   167  }
   168  
   169  // StatsJSON is newly used Networks
   170  type StatsJSON struct {
   171  	Stats
   172  
   173  	Name string `json:"name,omitempty"`
   174  	ID   string `json:"id,omitempty"`
   175  
   176  	// Networks request version >=1.21
   177  	Networks map[string]NetworkStats `json:"networks,omitempty"`
   178  }