prometheus-adapter: add prefix option to config for container metrics (#1844)

This commit adds the options `containerMetricsPrefix`
to the prometheus-adapter config-map generator. By default this option
is the empty string and doesn't change the current behavior. If set
however to e.g. `pa_`, the prometheus-adapter configuration will add
this prefix to all container_ queries in the resource rules.
This enables users of kube-prometheus to define a specialised service
monitor, that only expose the prometheus-adapter related container metrics with a
different configuration, like `honorTimestamps: true` or a tighter
scrape interval.

Signed-off-by: Jan Fajerski <jfajersk@redhat.com>
This commit is contained in:
Jan Fajerski
2022-09-02 17:51:30 +02:00
committed by GitHub
parent e08a1ec75a
commit 75bc89f6e3

View File

@@ -31,6 +31,7 @@ local defaults = {
nodeExporter: '4m',
windowsExporter: '4m',
},
containerMetricsPrefix:: '',
prometheusURL:: error 'must provide prometheusURL',
config:: {
@@ -39,10 +40,10 @@ local defaults = {
containerQuery: |||
sum by (<<.GroupBy>>) (
irate (
container_cpu_usage_seconds_total{<<.LabelMatchers>>,container!="",pod!=""}[%(kubelet)s]
%(containerMetricsPrefix)scontainer_cpu_usage_seconds_total{<<.LabelMatchers>>,container!="",pod!=""}[%(kubelet)s]
)
)
||| % $.rangeIntervals,
||| % { kubelet: $.rangeIntervals.kubelet, containerMetricsPrefix: $.containerMetricsPrefix },
nodeQuery: |||
sum by (<<.GroupBy>>) (
1 - irate(
@@ -57,7 +58,7 @@ local defaults = {
windows_cpu_time_total{mode="idle", job="windows-exporter",<<.LabelMatchers>>}[%(windowsExporter)s]
)
)
||| % $.rangeIntervals,
||| % { nodeExporter: $.rangeIntervals.nodeExporter, windowsExporter: $.rangeIntervals.windowsExporter, containerMetricsPrefix: $.containerMetricsPrefix },
resources: {
overrides: {
node: { resource: 'node' },
@@ -70,9 +71,9 @@ local defaults = {
memory: {
containerQuery: |||
sum by (<<.GroupBy>>) (
container_memory_working_set_bytes{<<.LabelMatchers>>,container!="",pod!=""}
%(containerMetricsPrefix)scontainer_memory_working_set_bytes{<<.LabelMatchers>>,container!="",pod!=""}
)
|||,
||| % { containerMetricsPrefix: $.containerMetricsPrefix },
nodeQuery: |||
sum by (<<.GroupBy>>) (
node_memory_MemTotal_bytes{job="node-exporter",<<.LabelMatchers>>}
@@ -84,7 +85,7 @@ local defaults = {
-
windows_memory_available_bytes{job="windows-exporter",<<.LabelMatchers>>}
)
|||,
||| % { containerMetricsPrefix: $.containerMetricsPrefix },
resources: {
overrides: {
instance: { resource: 'node' },