Prometheus

Exporting Metrics

If you have an existing Prometheus cluster, it is very easy to export Linkerd’srich telemetry data to your cluster. Simply add the following item to yourscrape_configs in your Prometheus config file (replace {{.Namespace}} withthe namespace where Linkerd is running):

  1. - job_name: 'linkerd-controller'
  2. kubernetes_sd_configs:
  3. - role: pod
  4. namespaces:
  5. names: ['{{.Namespace}}']
  6. relabel_configs:
  7. - source_labels:
  8. - __meta_kubernetes_pod_label_linkerd_io_control_plane_component
  9. - __meta_kubernetes_pod_container_port_name
  10. action: keep
  11. regex: (.*);admin-http$
  12. - source_labels: [__meta_kubernetes_pod_container_name]
  13. action: replace
  14. target_label: component
  15. - job_name: 'linkerd-proxy'
  16. kubernetes_sd_configs:
  17. - role: pod
  18. relabel_configs:
  19. - source_labels:
  20. - __meta_kubernetes_pod_container_name
  21. - __meta_kubernetes_pod_container_port_name
  22. - __meta_kubernetes_pod_label_linkerd_io_control_plane_ns
  23. action: keep
  24. regex: ^linkerd-proxy;linkerd-metrics;{{.Namespace}}$
  25. - source_labels: [__meta_kubernetes_namespace]
  26. action: replace
  27. target_label: namespace
  28. - source_labels: [__meta_kubernetes_pod_name]
  29. action: replace
  30. target_label: pod
  31. # special case k8s' "job" label, to not interfere with prometheus' "job"
  32. # label
  33. # __meta_kubernetes_pod_label_linkerd_io_proxy_job=foo =>
  34. # k8s_job=foo
  35. - source_labels: [__meta_kubernetes_pod_label_linkerd_io_proxy_job]
  36. action: replace
  37. target_label: k8s_job
  38. # __meta_kubernetes_pod_label_linkerd_io_proxy_deployment=foo =>
  39. # deployment=foo
  40. - action: labelmap
  41. regex: __meta_kubernetes_pod_label_linkerd_io_proxy_(.+)
  42. # drop all labels that we just made copies of in the previous labelmap
  43. - action: labeldrop
  44. regex: __meta_kubernetes_pod_label_linkerd_io_proxy_(.+)
  45. # __meta_kubernetes_pod_label_linkerd_io_foo=bar =>
  46. # foo=bar
  47. - action: labelmap
  48. regex: __meta_kubernetes_pod_label_linkerd_io_(.+)

That’s it! Your Prometheus cluster is now configured to scrape Linkerd’smetrics.

Linkerd’s proxy metrics will have the label job="linkerd-proxy". Linkerd’scontrol-plane metrics will have the label job="linkerd-controller".

For more information on specific metric and label definitions, have a look atProxy Metrics.

原文: https://linkerd.io/2/observability/prometheus/