Skip to content

Commit

Permalink
Add the ability to set extraMetricProcessingRules and discoveryRules …
Browse files Browse the repository at this point in the history
…for cadvisor
  • Loading branch information
fplantinga-guida committed Oct 17, 2024
1 parent cea68c7 commit 381f6b5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
15 changes: 15 additions & 0 deletions charts/feature-cluster-metrics/templates/_cadvisor.alloy.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,19 @@
{{- $metricAllowList := include "feature.clusterMetrics.cadvisor.allowList" . }}
{{- $metricDenyList := .Values.cadvisor.metricsTuning.excludeMetrics }}

discovery.relabel "cadvisor" {
rule {
source_labels = ["__meta_kubernetes_pod_node_name"]
action = "replace"
target_label = "instance"
}
{{- if (index .Values "cadvisor").extraDiscoveryRules }}
{{ (index .Values "cadvisor").extraDiscoveryRules | nindent 2 }}
{{- end }}
}

kubernetes.cadvisor "scrape" {
targets = discovery.relabel.cadvisor.output
clustering = true
{{- if $metricAllowList }}
keep_metrics = "up|{{ $metricAllowList | fromYamlArray | join "|" }}"
Expand Down Expand Up @@ -102,6 +114,9 @@ prometheus.relabel "cadvisor" {
target_label = "__keepme"
replacement = ""
}
{{- end }}
{{- if .Values.cadvisor.extraMetricProcessingRules }}
{{ .Values.cadvisor.extraMetricProcessingRules | indent 2 }}
{{- end }}
forward_to = argument.metrics_destinations.value
}
Expand Down
9 changes: 9 additions & 0 deletions charts/feature-cluster-metrics/tests/custom_rules_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,16 @@ tests:
forward_to = argument.metrics_destinations.value
}
discovery.relabel "cadvisor" {
rule {
source_labels = ["__meta_kubernetes_pod_node_name"]
action = "replace"
target_label = "instance"
}
}
kubernetes.cadvisor "scrape" {
targets = discovery.relabel.cadvisor.output
clustering = true
keep_metrics = "up|container_cpu_cfs_periods_total|container_cpu_cfs_throttled_periods_total|container_cpu_usage_seconds_total|container_fs_reads_bytes_total|container_fs_reads_total|container_fs_writes_bytes_total|container_fs_writes_total|container_memory_cache|container_memory_rss|container_memory_swap|container_memory_working_set_bytes|container_network_receive_bytes_total|container_network_receive_packets_dropped_total|container_network_receive_packets_total|container_network_transmit_bytes_total|container_network_transmit_packets_dropped_total|container_network_transmit_packets_total|machine_memory_bytes"
scrape_interval = "60s"
Expand Down
9 changes: 9 additions & 0 deletions charts/feature-cluster-metrics/tests/default_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@ tests:
forward_to = argument.metrics_destinations.value
}
discovery.relabel "cadvisor" {
rule {
source_labels = ["__meta_kubernetes_pod_node_name"]
action = "replace"
target_label = "instance"
}
}
kubernetes.cadvisor "scrape" {
targets = discovery.relabel.cadvisor.output
clustering = true
keep_metrics = "up|container_cpu_cfs_periods_total|container_cpu_cfs_throttled_periods_total|container_cpu_usage_seconds_total|container_fs_reads_bytes_total|container_fs_reads_total|container_fs_writes_bytes_total|container_fs_writes_total|container_memory_cache|container_memory_rss|container_memory_swap|container_memory_working_set_bytes|container_network_receive_bytes_total|container_network_receive_packets_dropped_total|container_network_receive_packets_total|container_network_transmit_bytes_total|container_network_transmit_packets_dropped_total|container_network_transmit_packets_total|machine_memory_bytes"
scrape_interval = "60s"
Expand Down

0 comments on commit 381f6b5

Please sign in to comment.