config_k8s.yaml 1.0 KB

12345678910111213141516171819202122232425262728
  1. prometheus:
  2. config:
  3. scrape_configs:
  4. - job_name: apps
  5. kubernetes_sd_configs:
  6. - role: pod
  7. selectors:
  8. - role: pod
  9. # only scrape data from pods running on the same node as collector
  10. field: "spec.nodeName=${NODE_NAME}"
  11. relabel_configs:
  12. # scrape pods annotated with "prometheus.io/scrape: true"
  13. - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
  14. regex: "true"
  15. action: keep
  16. # read the port from "prometheus.io/port: <port>" annotation and update scraping address accordingly
  17. - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
  18. action: replace
  19. target_label: __address__
  20. regex: ([^:]+)(?::\d+)?;(\d+)
  21. # escaped $1:$2
  22. replacement: $$1:$$2
  23. - source_labels: [__meta_kubernetes_namespace]
  24. action: replace
  25. target_label: kubernetes_namespace
  26. - source_labels: [__meta_kubernetes_pod_name]
  27. action: replace
  28. target_label: kubernetes_pod_name