2

I want to reduce the number of metrics that are scraped under Kube-state-metrics. When I use the following configuration:

  metric_relabel_configs:
  - source_labels: [__name__]
    separator: ;
    regex: kube_pod_(status_phase|container_resource_requests_memory_bytes|container_resource_requests_cpu_cores|owner|labels|container_resource_limits_memory_bytes|container_resource_limits_cpu_cores)
    replacement: $1
    action: keep

It is working and I can see only the metrics I selected above. But when I try to add another rule:

metric_relabel_configs:
  - source_labels: [__name__]
    separator: ;
    regex: kube_pod_(status_phase|container_resource_requests_memory_bytes|container_resource_requests_cpu_cores|owner|labels|container_resource_limits_memory_bytes|container_resource_limits_cpu_cores)
    replacement: $1
    action: keep
  - source_labels: [__name__]
    separator: ;
    regex: kube_replicaset_(owner)
    replacement: $1
    action: keep

It will remove everything, including the first rule that used to work. How should it be correctly written so that I can create multiple rules for keeping selective metrics?

Tomer Leibovich
  • 467
  • 1
  • 5
  • 13

2 Answers2

1

Figured out that both conditions can't be together, only one keep can be.

Tomer Leibovich
  • 467
  • 1
  • 5
  • 13
  • what if you need another condition, i.e. from only foo namespace. How could we set the filter here? – star Jan 24 '23 at 06:07
0

I did some test , this works for me.

            metric_relabel_configs:
            - source_labels: [ __name__ ]
              regex: "metrics_name_foo"
              action: keep
            - source_labels: [ namespace ]
              regex: "istio-system"
              action: keep
star
  • 691
  • 7
  • 12