prometheus-adapter 添加自定义指标
概述
prometheus-adapter 添加自定义指标方法
方法一
通常 rancher-monitoring-prometheus-adapter ConfigMap 是由 rancher-monitoring 的 Helm Chart 管理并生成,不建议直接对该 ConfigMap 进行修改,否则可能会在 rancher-monitoring 更新时被覆盖。
对于需要通过 Prometheus Adapter 暴露给 HPA 的自定义指标,建议通过 Rancher Monitoring 的 Helm Values 配置,在 Rancher UI - Apps - Installed Apps下,编辑 rancher-monitoring,切换到 Edit YAML,在如下位置添加该配置:
1 | prometheus-adapter: |
方法二
参考此文档,官方还有一种配置方法,通过 rules.existing 指定一个独立的 Configmap 文件,这样后续只需要在该 Configmap 里修改配置即可,参考如下:
1)由于 existing 会替代 Prometheus Adapter 原有的 default/custom/external/resource rules,所以需要先将原有的配置导出:
1 | kubectl -n cattle-monitoring-system get configmaps rancher-monitoring-prometheus-adapter -ojsonpath='{.data.config\.yaml}' > config.yaml |
2)可以手动编辑该 config.yaml,增加自己的 Rule,接着创建独立 Configmap 文件,例如命名为 rancher-monitoring-prometheus-adapter-custom:
1 | kubectl -n cattle-monitoring-system create configmap \ |
3)编辑 rancher-monitoring YAML,还是相同的位置,将 rules.custom 去掉,并增加 rules.existing:
1 | prometheus-adapter: |
4)接着等待 monitoring 更新即可,更新完成后,后续可以直接编辑 rancher-monitoring-prometheus-adapter-custom 文件。更新了 config.yaml 配置后,prometheus-adapter 需要手动重启来生效配置,目前所有版本都不支持在线修改指标。