https://github.com/google/cadvisor (cAdvisor)
Prerequisite Concepts:
1. Time series refers to a sequence of numbers in which the values of the same statistical indicator are arranged in the chronological order of their occurrence.
2.
=: select exactly equal string labels
!=: select unequal string labels
=~: selects tags (or subtags) that match the regular expression
!~: selects tags (or subtags) that do not match the regular expression
3.
s:seconds
m:minutes
h:hours
d:days
w:weeks
y:years
Note: [5m] refers to the past 5 minutes
4. Operators
bool
and
or
unless
on
without : without(label) removes parenthesized labels and values in the result
by : by(label) keeps only the labels and values in parentheses in the result
1. Network traffic
Received bytes (within 1 minute):
sum(rate(container_network_receive_bytes_total{id="/"}[1m])) by (id)
## container_network_receive_bytes_total:Cumulative count of bytes received
(bytes received)
## id="/" : Container ID = / , query according to ID, or name=~".+" according to name
Upload bytes (within 1 minute):
sum(rate(container_network_transmit_bytes_total{id="/"}[1m])) by (id)
## container_network_transmit_bytes_total:Cumulative count of bytes transmitted
(bytes transferred)
2. Number of running containers
count(rate(container_last_seen{id=~".+",$label=~".+"}[1m]))
## container_last_seen: Last time a container was seen by the exporter
## $label : label condition, that is, query according to the item with the $label label
## .+ : wildcard
## container_group : to be studied
3. Container CPU related
sum(rate(container_cpu_system_seconds_total[1m]))
## container_cpu_system_seconds_total :Cumulative system cpu time consumed in seconds
sum(rate(container_cpu_system_seconds_total{name=~".+"}[1m]))
sum(rate(container_cpu_system_seconds_total{id="/"}[1m]))
sum(rate(process_cpu_seconds_total[1m])) * 100
## process_cpu_seconds_total :Total user and system CPU time spent in seconds
sum(rate(container_cpu_system_seconds_total{name=~".+"}[1m])) + sum(rate(container_cpu_system_seconds_total{id="/"}[1m])) + sum(rate(process_cpu_seconds_total[1m]))
CPU usage per container:
sum(rate(container_cpu_usage_seconds_total{name=~".+"}[1m])) by (name) * 100
## container_cpu_usage_seconds_total :Cumulative cpu time consumed per cpu in seconds
Sum of CPU usage of all containers:
sum(sum(rate(container_cpu_usage_seconds_total{name=~".+"}[1m])) by (name) * 100)
total CPU Usage:
(* 待验证)sum(rate(container_cpu_user_seconds_total{image!=""}[5m]) * 100)
CPU Usage per container :
(* 待验证)rate(container_cpu_user_seconds_total{image!=""}[5m]) * 100
4. Container memory
All containers:
container_memory_rss{name=~".+"}
## container_memory_rss : Size of RSS in bytes
## RSS : RSS- Resident Set Size actually uses physical memory (including the memory occupied by shared libraries)
## name = ~".+" : Query by name, or by ID, ie id=~".+"
Sum of all containers:
sum(container_memory_rss{name=~".+"})
Current memory usage of all containers:
container_memory_usage_bytes{name=~".+"}
## container_memory_usage_bytes : Current memory usage in bytes.
Sum of current memory usage of all containers:
sum(container_memory_usage_bytes{name=~".+"})