From dce6abfba93a799c43f70e114dd46a468cd104e6 Mon Sep 17 00:00:00 2001 From: aackerman Date: Tue, 23 Mar 2021 09:01:56 -0500 Subject: [PATCH] Fix documented metrics labels to work for k8s 1.16+ --- .../manifests/custom-metrics-config-map.yaml | 26 +++++++++---------- docs/config.md | 10 +++---- docs/sample-config.yaml | 16 ++++++------ 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/deploy/manifests/custom-metrics-config-map.yaml b/deploy/manifests/custom-metrics-config-map.yaml index c8f28429..d68f4ac2 100644 --- a/deploy/manifests/custom-metrics-config-map.yaml +++ b/deploy/manifests/custom-metrics-config-map.yaml @@ -6,44 +6,44 @@ metadata: data: config.yaml: | rules: - - seriesQuery: '{__name__=~"^container_.*",container_name!="POD",namespace!="",pod_name!=""}' + - seriesQuery: '{__name__=~"^container_.*",container!="POD",namespace!="",pod!=""}' seriesFilters: [] resources: overrides: namespace: resource: namespace - pod_name: + pod: resource: pod name: matches: ^container_(.*)_seconds_total$ as: "" - metricsQuery: sum(rate(<<.Series>>{<<.LabelMatchers>>,container_name!="POD"}[1m])) by (<<.GroupBy>>) - - seriesQuery: '{__name__=~"^container_.*",container_name!="POD",namespace!="",pod_name!=""}' + metricsQuery: sum(rate(<<.Series>>{<<.LabelMatchers>>,container!="POD"}[1m])) by (<<.GroupBy>>) + - seriesQuery: '{__name__=~"^container_.*",container!="POD",namespace!="",pod!=""}' seriesFilters: - isNot: ^container_.*_seconds_total$ resources: overrides: namespace: resource: namespace - pod_name: + pod: resource: pod name: matches: ^container_(.*)_total$ as: "" - metricsQuery: sum(rate(<<.Series>>{<<.LabelMatchers>>,container_name!="POD"}[1m])) by (<<.GroupBy>>) - - seriesQuery: '{__name__=~"^container_.*",container_name!="POD",namespace!="",pod_name!=""}' + metricsQuery: sum(rate(<<.Series>>{<<.LabelMatchers>>,container!="POD"}[1m])) by (<<.GroupBy>>) + - seriesQuery: '{__name__=~"^container_.*",container!="POD",namespace!="",pod!=""}' seriesFilters: - isNot: ^container_.*_total$ resources: overrides: namespace: resource: namespace - pod_name: + pod: resource: pod name: matches: ^container_(.*)$ as: "" - metricsQuery: sum(<<.Series>>{<<.LabelMatchers>>,container_name!="POD"}) by (<<.GroupBy>>) + metricsQuery: sum(<<.Series>>{<<.LabelMatchers>>,container!="POD"}) by (<<.GroupBy>>) - seriesQuery: '{namespace!="",__name__!~"^container_.*"}' seriesFilters: - isNot: .*_total$ @@ -80,9 +80,9 @@ data: resource: node namespace: resource: namespace - pod_name: + pod: resource: pod - containerLabel: container_name + containerLabel: container memory: containerQuery: sum(container_memory_working_set_bytes{<<.LabelMatchers>>}) by (<<.GroupBy>>) nodeQuery: sum(container_memory_working_set_bytes{<<.LabelMatchers>>,id='/'}) by (<<.GroupBy>>) @@ -92,9 +92,9 @@ data: resource: node namespace: resource: namespace - pod_name: + pod: resource: pod - containerLabel: container_name + containerLabel: container window: 1m externalRules: - seriesQuery: '{__name__=~"^.*_queue_(length|size)$",namespace!=""}' diff --git a/docs/config.md b/docs/config.md index 818d3bbf..e57cc87a 100644 --- a/docs/config.md +++ b/docs/config.md @@ -31,13 +31,13 @@ might look like: ```yaml rules: # this rule matches cumulative cAdvisor metrics measured in seconds -- seriesQuery: '{__name__=~"^container_.*",container_name!="POD",namespace!="",pod_name!=""}' +- seriesQuery: '{__name__=~"^container_.*",container!="POD",namespace!="",pod!=""}' resources: # skip specifying generic resource<->label mappings, and just # attach only pod and namespace resources by mapping label names to group-resources overrides: namespace: {resource: "namespace"}, - pod_name: {resource: "pod"}, + pod: {resource: "pod"}, # specify that the `container_` and `_seconds_total` suffixes should be removed. # this also introduces an implicit filter on metric family names name: @@ -48,7 +48,7 @@ rules: # This is a Go template where the `.Series` and `.LabelMatchers` string values # are available, and the delimiters are `<<` and `>>` to avoid conflicts with # the prometheus query language - metricsQuery: "sum(rate(<<.Series>>{<<.LabelMatchers>>,container_name!="POD"}[2m])) by (<<.GroupBy>>)" + metricsQuery: "sum(rate(<<.Series>>{<<.LabelMatchers>>,container!="POD"}[2m])) by (<<.GroupBy>>)" ``` Discovery @@ -83,7 +83,7 @@ For example: ```yaml # match all cAdvisor metrics that aren't measured in seconds -seriesQuery: '{__name__=~"^container_.*_total",container_name!="POD",namespace!="",pod_name!=""}' +seriesQuery: '{__name__=~"^container_.*_total",container!="POD",namespace!="",pod!=""}' seriesFilters: - isNot: "^container_.*_seconds_total" ``` @@ -211,5 +211,5 @@ For example: ```yaml # convert cumulative cAdvisor metrics into rates calculated over 2 minutes -metricsQuery: "sum(rate(<<.Series>>{<<.LabelMatchers>>,container_name!="POD"}[2m])) by (<<.GroupBy>>)" +metricsQuery: "sum(rate(<<.Series>>{<<.LabelMatchers>>,container!="POD"}[2m])) by (<<.GroupBy>>)" ``` diff --git a/docs/sample-config.yaml b/docs/sample-config.yaml index 3aa5be6d..61676918 100644 --- a/docs/sample-config.yaml +++ b/docs/sample-config.yaml @@ -10,16 +10,16 @@ rules: # can be found in pkg/config/default.go # this rule matches cumulative cAdvisor metrics measured in seconds -- seriesQuery: '{__name__=~"^container_.*",container_name!="POD",namespace!="",pod_name!=""}' +- seriesQuery: '{__name__=~"^container_.*",container!="POD",namespace!="",pod!=""}' resources: # skip specifying generic resource<->label mappings, and just # attach only pod and namespace resources by mapping label names to group-resources overrides: namespace: {resource: "namespace"}, - pod_name: {resource: "pod"}, + pod: {resource: "pod"}, # specify that the `container_` and `_seconds_total` suffixes should be removed. # this also introduces an implicit filter on metric family names - name: + name: # we use the value of the capture group implicitly as the API name # we could also explicitly write `as: "$1"` matches: "^container_(.*)_seconds_total$" @@ -27,19 +27,19 @@ rules: # This is a Go template where the `.Series` and `.LabelMatchers` string values # are available, and the delimiters are `<<` and `>>` to avoid conflicts with # the prometheus query language - metricsQuery: "sum(rate(<<.Series>>{<<.LabelMatchers>>,container_name!="POD"}[2m])) by (<<.GroupBy>>)" + metricsQuery: "sum(rate(<<.Series>>{<<.LabelMatchers>>,container!="POD"}[2m])) by (<<.GroupBy>>)" # this rule matches cumulative cAdvisor metrics not measured in seconds -- seriesQuery: '{__name__=~"^container_.*_total",container_name!="POD",namespace!="",pod_name!=""}' +- seriesQuery: '{__name__=~"^container_.*_total",container!="POD",namespace!="",pod!=""}' resources: overrides: namespace: {resource: "namespace"}, - pod_name: {resource: "pod"}, + pod: {resource: "pod"}, seriesFilters: # since this is a superset of the query above, we introduce an additional filter here - isNot: "^container_.*_seconds_total$" name: {matches: "^container_(.*)_total$"} - metricsQuery: "sum(rate(<<.Series>>{<<.LabelMatchers>>,container_name!="POD"}[2m])) by (<<.GroupBy>>)" + metricsQuery: "sum(rate(<<.Series>>{<<.LabelMatchers>>,container!="POD"}[2m])) by (<<.GroupBy>>)" # this rule matches cumulative non-cAdvisor metrics - seriesQuery: '{namespace!="",__name__!="^container_.*"}' @@ -52,7 +52,7 @@ rules: # Group will be converted to a form acceptible for use as a label automatically. template: "<<.Resource>>" # if we wanted to, we could also specify overrides here - metricsQuery: "sum(rate(<<.Series>>{<<.LabelMatchers>>,container_name!="POD"}[2m])) by (<<.GroupBy>>)" + metricsQuery: "sum(rate(<<.Series>>{<<.LabelMatchers>>,container!="POD"}[2m])) by (<<.GroupBy>>)" # this rule matches only a single metric, explicitly naming it something else # It's series query *must* return only a single metric family