Forked from bakins/gist:5bf7d4e719f36c1c555d81134d8887eb
Created
July 6, 2021 16:14
-
-
Save katoozi/307fec6e5b0b8e47987a866b2eea49c9 to your computer and use it in GitHub Desktop.
prometheus - scrape multiple containers in a pod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example scrape config for pods | |
# | |
# The relabeling allows the actual pod scrape endpoint to be configured via the | |
# following annotations: | |
# | |
# * `prometheus.io/scrape`: Only scrape pods that have a value of `true` | |
# * `prometheus.io/path`: If the metrics path is not `/metrics` override this. This | |
# will be the same for every container in the pod that is scraped. | |
# * this will scrape every container in a pod with `prometheus.io/scrape` set to true and the | |
port is name `metrics` in the container | |
# * note `prometheus.io/port` is no longer honored. You must name the port(s) to scrape `metrics` | |
# Also, in some of the issues I read, there was mention of a container role, but I couldn't get | |
# that to work - or find any more info on it. | |
- job_name: 'kubernetes-pods' | |
kubernetes_sd_configs: | |
- role: pod | |
relabel_configs: | |
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape] | |
action: keep | |
regex: true | |
- source_labels: [__meta_kubernetes_pod_container_port_name] | |
action: keep | |
regex: metrics | |
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path] | |
action: replace | |
target_label: __metrics_path__ | |
regex: (.+) | |
- source_labels: [ __address__, __meta_kubernetes_pod_container_port_number] | |
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: kubernetes_namespace | |
- source_labels: [__meta_kubernetes_pod_name] | |
action: replace | |
target_label: kubernetes_pod_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment