共计 2264 个字符,预计需要花费 6 分钟才能阅读完成。
adapter 的配置以 configmap 的模式,被挂载到 adapter 的 pod 中:
# kubectl get cm adapter-config -n monitoring
NAME DATA AGE
adapter-config 1 2d
一. 配置文件的构造
整个配置蕴含 2 个重要的局部:
- rules 局部:用于 custom.metrics.k8s.io,用以自定义指标的 HPA 伸缩;
- resourceRule 局部:用于 metrics.k8s.io,用以 cpu、mem 指标的 HPA 伸缩;
rules:
- seriesQuery: '{__name__=~"^container_.*",container_name!="POD",namespace!="",pod!=""}'
seriesFilters: []
resources:
overrides:
namespace:
resource: namespace
pod:
resource: pods
name:
matches: ^container_(.*)_seconds_total$
as: ""metricsQuery: sum(rate(<<.Series>>{<<.LabelMatchers>>,container_name!="POD"}[1m])) by (<<.GroupBy>>)
---
resourceRules:
cpu:
containerQuery: sum(rate(container_cpu_usage_seconds_total{<<.LabelMatchers>>}[1m])) by (<<.GroupBy>>)
nodeQuery: sum(rate(container_cpu_usage_seconds_total{<<.LabelMatchers>>, id='/'}[1m])) by (<<.GroupBy>>)
resources:
overrides:
instance:
resource: nodes
namespace:
resource: namespace
pod:
resource: pods
containerLabel: container_name
二. rules 配置的构造
rules:
- seriesQuery: '{__name__=~"^container_.*",container!="POD",namespace!="",pod!="”}'
seriesFilters: []
resources:
overrides:
namespace: {resource: "namespace"},
pod: {resource: "pod"},
name:
matches: "^container_(.*)_seconds_total$"
metricsQuery: "sum(rate(<<.Series>>{<<.LabelMatchers>>,container!="POD"}[2m])) by (<<.GroupBy>>)"
每个 rule 通常由 4 局部形成:
-
Discovery: 筛选 series,包含:
- seriesQuery
- seriesFilter
-
Association: 将 prom 的 label 与 resource 类型关联起来
- resources
-
Naming: 自定义输入的指标名称
- name
-
Querying: Go template 用于定义 PromQL 表达式
- metricsQuery
三.rules 配置详解
rules 定义了指标的转换规则,用作 custom.metrics.k8s.io HPA 应用。
rules:
- seriesQuery: '{__name__=~"^container_.*",container_name!="POD",namespace!="",pod!=""}'
seriesFilters: []
resources:
overrides:
namespace:
resource: namespace
pod:
resource: pods
name:
matches: ^container_(.*)_seconds_total$
as: ""metricsQuery: sum(rate(<<.Series>>{<<.LabelMatchers>>,container_name!="POD"}[1m])) by (<<.GroupBy>>)
- seriesQuery: 用于筛选 series;
-
seriesFilters: 用于过滤掉不关怀的 series;
- is <regex>: 只获取 regex 匹配到的指标名称;
- isNot <regex>:
-
resource: 将 series 中的标签与指标资源类型关联起来
- namespace: 将 series 中的 namespace 字段,与资源中的 namespace 字段关联;
- pod: 将 series 中的 pod 字段,与资源中的 pods 字段关联;
-
name: 用于给指标重命名,比方以_total 结尾的指标,去掉后缀
- matches: 匹配源指标名;
- as: 指标指标名称,默认 =$1,即第一个分组;
-
metricsQuery: 查问语句
- <<.Series>>=seriesQuery 的后果;
- LabelMatches,通常是 pod/namespace;
- GroupBy,通常是 pod 名称;
参考:
1.https://juejin.cn/post/6844903967218991117
2.config 介绍:https://github.com/kubernetes-sigs/prometheus-adapter/blob/master/docs/config.md
正文完
发表至: prometheus
2023-03-28