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
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。