promQL 之 聚合函数
聚合函数
格式:<aggr-op>([parameter,] <vector expression>) [without|by (<label list>)]
-
sum 求和
sum(kube_pod_container_status_restarts_total) -
max 求最大值
max(kube_pod_container_status_restarts_total) -
mix 求最小值
min(kube_pod_container_status_restarts_total) -
avg 求平均
avg(kube_pod_container_status_restarts_total) -
count 计数
count(kube_pod_container_status_restarts_total) -
count_values 计数(符合指定值)
示例中对重启次数为0 的 进行计数
stdvar(0,kube_pod_container_status_restarts_total) -
bottomk 统计后3
bottomk(3,kube_pod_container_status_restarts_total) -
topk 统计前3
topk(3,kube_pod_container_status_restarts_total) -
quantile 统计分位数
什么是分位数?
quantile(0,kube_pod_container_status_restarts_total) -
stddev 求标准方差
什么是标准方差?
stddev(kube_pod_container_status_restarts_total) -
stdvar 求方差
stdvar(kube_pod_container_status_restarts_total)
上面是聚合函数的基本使用,promQL还支持使用 without,by 等参数对结果进行过滤
如果你使用过 sql 语句可以把它理解为groupby
sum(kube_pod_container_status_restarts_total) by(namespace)
sum(kube_pod_container_status_restarts_total) without(pod)
浙公网安备 33010602011771号