Skip to content

Commit

Permalink
prometheus-adapter: add prefix option to config for container metrics (
Browse files Browse the repository at this point in the history
…#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 <[email protected]>
  • Loading branch information
jan--f authored Sep 2, 2022
1 parent e08a1ec commit 75bc89f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions jsonnet/kube-prometheus/components/prometheus-adapter.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ local defaults = {
nodeExporter: '4m',
windowsExporter: '4m',
},
containerMetricsPrefix:: '',

prometheusURL:: error 'must provide prometheusURL',
config:: {
Expand All @@ -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(
Expand All @@ -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' },
Expand All @@ -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>>}
Expand All @@ -84,7 +85,7 @@ local defaults = {
-
windows_memory_available_bytes{job="windows-exporter",<<.LabelMatchers>>}
)
|||,
||| % { containerMetricsPrefix: $.containerMetricsPrefix },
resources: {
overrides: {
instance: { resource: 'node' },
Expand Down

0 comments on commit 75bc89f

Please sign in to comment.