2024-04-23 14:54:56 +08:00
|
|
|
- job_name: "kubernetes-pods"
|
|
|
|
|
|
|
|
kubernetes_sd_configs:
|
|
|
|
- role: pod
|
|
|
|
|
|
|
|
relabel_configs:
|
2024-04-23 16:58:12 +08:00
|
|
|
# prometheus relabel to scrape only pods that have
|
2024-04-23 14:54:56 +08:00
|
|
|
# `prometheus.io/scrape: "true"` annotation.
|
|
|
|
- source_labels:
|
|
|
|
- __meta_kubernetes_pod_annotation_prometheus_io_scrape
|
|
|
|
action: keep
|
|
|
|
regex: true
|
|
|
|
|
2024-04-23 16:58:12 +08:00
|
|
|
# prometheus relabel to customize metric path based on pod
|
2024-04-23 14:54:56 +08:00
|
|
|
# `prometheus.io/path: <metric path>` annotation.
|
|
|
|
- source_labels:
|
|
|
|
- __meta_kubernetes_pod_annotation_prometheus_io_path
|
|
|
|
action: replace
|
|
|
|
target_label: __metrics_path__
|
|
|
|
regex: (.+)
|
|
|
|
|
2024-04-23 16:58:12 +08:00
|
|
|
# prometheus relabel to scrape only single, desired port for the pod
|
2024-04-23 14:54:56 +08:00
|
|
|
# based on pod `prometheus.io/port: <port>` annotation.
|
|
|
|
- source_labels:
|
|
|
|
- __address__
|
|
|
|
- __meta_kubernetes_pod_annotation_prometheus_io_port
|
|
|
|
action: replace
|
|
|
|
regex: ([^:]+)(?::\d+)?;(\d+)
|
|
|
|
replacement: $1:$2
|
|
|
|
target_label: __address__
|
|
|
|
- action: labelmap
|
|
|
|
regex: __meta_kubernetes_pod_label_(.+)
|
|
|
|
- source_labels: [__meta_kubernetes_namespace]
|
|
|
|
action: replace
|
|
|
|
target_label: namespace
|
|
|
|
- source_labels: [__meta_kubernetes_pod_name]
|
|
|
|
action: replace
|
|
|
|
target_label: pod
|