Kubernetes/Compute Resources/Workload A 集合规则包括以下条件:
动态收集的一组指标。
使用 PromQL 表达式定义的条件。
集合的间隔,该集合必须设为 true。
一个匹配表达式,用于选择需要评估收集规则的集群。
默认情况下,集合规则每 30 秒或以特定时间间隔在受管集群上持续评估。集合间隔和时间间隔中的最低值具有高优先权。当收集规则条件在 for 属性指定的持续时间内保留后,收集规则将启动,由规则指定的指标会在受管集群上自动收集。指标集合会在受管集群上不再存在集合规则条件后自动停止,至少有 15 分钟。
集合规则分组为名为 gather_rules 的参数部分,该部分可启用或禁用作为组。Red Hat Advanced Cluster Management 安装包含集合规则组 SNOResourceUsage,它有两个默认集合规则: HighCPUUsage 和 HighMemoryUsage。HighCPUUsage 集合规则从节点 CPU 使用率超过 70% 时开始。如果单节点 OpenShift 集群的总内存使用率超过可用节点内存的 70%,则 HighMemoryUsage 集合规则开始。目前,前面提到的阈值是固定的,且无法更改。当集合规则开始超过 for 属性指定的间隔时,系统会自动开始收集 dynamic_metrics 中指定的指标。
在以下 YAML 文件中查看 collect_rules 部分的动态指标列表:
collect_rules:
- group: SNOResourceUsage
annotations:
description: >
By default, a {sno} cluster does not collect pod and container resource metrics. Once a {sno} cluster
reaches a level of resource consumption, these granular metrics are collected dynamically.
When the cluster resource consumption is consistently less than the threshold for a period of time,
collection of the granular metrics stops.
selector:
matchExpressions:
- key: clusterType
operator: In
values: ["{sno}"]
rules:
- collect: SNOHighCPUUsage
annotations:
description: >
Collects the dynamic metrics specified if the cluster cpu usage is constantly more than 70% for 2 minutes
expr: (1 - avg(rate(node_cpu_seconds_total{mode=\"idle\"}[5m]))) * 100 > 70
for: 2m
dynamic_metrics:
names:
- container_cpu_cfs_periods_total
- container_cpu_cfs_throttled_periods_total
- kube_pod_container_resource_limits
- kube_pod_container_resource_requests
- namespace_workload_pod:kube_pod_owner:relabel
- node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate
- node_namespace_pod_container:container_cpu_usage_seconds_total:sum_rate
- collect: SNOHighMemoryUsage
annotations:
description: >
Collects the dynamic metrics specified if the cluster memory usage is constantly more than 70% for 2 minutes
expr: (1 - sum(:node_memory_MemAvailable_bytes:sum) / sum(kube_node_status_allocatable{resource=\"memory\"})) * 100 > 70
for: 2m
dynamic_metrics:
names:
- kube_pod_container_resource_limits
- kube_pod_container_resource_requests
- namespace_workload_pod:kube_pod_owner:relabel
matches:
- __name__="container_memory_cache",container!=""
- __name__="container_memory_rss",container!=""
- __name__="container_memory_swap",container!=""
- __name__="container_memory_working_set_bytes",container!=""
collect_rules:-group: SNOResourceUsage
annotations:description:>
By default, a {sno} cluster does not collect pod and container resource metrics. Once a {sno} cluster
reaches a level of resource consumption, these granular metrics are collected dynamically.
When the cluster resource consumption is consistently less than the threshold for a period of time,
collection of the granular metrics stops.selector:matchExpressions:-key: clusterType
operator: In
values:["{sno}"]rules:-collect: SNOHighCPUUsage
annotations:description:>
Collects the dynamic metrics specified if the cluster cpu usage is constantly more than 70% for 2 minutesexpr: (1 - avg(rate(node_cpu_seconds_total{mode=\"idle\"}[5m]))) * 100 > 70
for: 2m
dynamic_metrics:names:- container_cpu_cfs_periods_total
- container_cpu_cfs_throttled_periods_total
- kube_pod_container_resource_limits
- kube_pod_container_resource_requests
- namespace_workload_pod:kube_pod_owner:relabel
- node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate
- node_namespace_pod_container:container_cpu_usage_seconds_total:sum_rate
-collect: SNOHighMemoryUsage
annotations:description:>
Collects the dynamic metrics specified if the cluster memory usage is constantly more than 70% for 2 minutesexpr: (1 - sum(:node_memory_MemAvailable_bytes:sum) / sum(kube_node_status_allocatable{resource=\"memory\"})) * 100 > 70
for: 2m
dynamic_metrics:names:- kube_pod_container_resource_limits
- kube_pod_container_resource_requests
- namespace_workload_pod:kube_pod_owner:relabel
matches:- __name__="container_memory_cache",container!=""
- __name__="container_memory_rss",container!=""
- __name__="container_memory_swap",container!=""
- __name__="container_memory_working_set_bytes",container!=""
Copy to ClipboardCopied!Toggle word wrapToggle overflow