Only keep metrics from the monitored namespaces

Signed-off-by: Michel Hollands <michel.hollands@gmail.com>
This commit is contained in:
Michel Hollands 2024-04-26 16:45:40 +01:00
parent 1871a4ef87
commit c614f41d66
2 changed files with 16 additions and 0 deletions

View File

@ -6,6 +6,15 @@
{{- join ", " $list }} {{- join ", " $list }}
{{- end }} {{- end }}
{{- define "agent.all_namespaces" -}}
{{- $list := list }}
{{- range .Values.namespacesToMonitor }}
{{- $list = append $list (printf "\"%s\"" .) }}
{{- end }}
{{- $list = append $list .Release.Namespace }}
{{- join "|" $list }}
{{- end }}
{{- define "agent.loki_write_targets" -}} {{- define "agent.loki_write_targets" -}}
{{- $list := list }} {{- $list := list }}
{{- if .Values.local.logs.enabled }} {{- if .Values.local.logs.enabled }}

View File

@ -137,6 +137,13 @@ data:
action = "keep" action = "keep"
} }
rule {
source_labels = ["namespace"]
regex = "{{ include "agent.all_namespaces" . }}""
action = "keep"
}
forward_to = [ {{ include "agent.prometheus_write_targets" . }} ] forward_to = [ {{ include "agent.prometheus_write_targets" . }} ]
} }
{{- if .Values.kubeStateMetrics.enabled }} {{- if .Values.kubeStateMetrics.enabled }}