Exporting Metrics

    Internally, Linkerd stores its metrics in a Prometheus instance that runs aspart of the control plane. There are several basic approaches to exportingmetrics data from Linkerd:

    If you are using Prometheus as your own metrics store, we recommend takingadvantage of Prometheus’s federation API, which is designed exactly for theuse case of copying data from one Prometheus to another.

    Simply add the following item to your in your Prometheusconfig file (replace {{.Namespace}} with the namespace where Linkerd isrunning):

    Alternatively, if you prefer to use Prometheus’ ServiceMonitors to configureyour Prometheus, you can use this ServiceMonitor YAML (replace {{.Namespace}}with the namespace where Linkerd is running):

    1. apiVersion: monitoring.coreos.com/v1
    2. kind: ServiceMonitor
    3. metadata:
    4. labels:
    5. k8s-app: linkerd-prometheus
    6. name: linkerd-federate
    7. namespace: {{.Namespace}}
    8. spec:
    9. endpoints:
    10. - interval: 30s
    11. params:
    12. match[]:
    13. - '{job="linkerd-proxy"}'
    14. - '{job="linkerd-controller"}'
    15. path: /federate
    16. port: admin-http
    17. honorLabels: true
    18. - action: keep
    19. regex: '^prometheus$'
    20. sourceLabels:
    21. - '__meta_kubernetes_pod_container_name'
    22. jobLabel: app
    23. matchNames:
    24. - {{.Namespace}}
    25. selector:
    26. matchLabels:
    27. linkerd.io/control-plane-component: prometheus

    Once the metrics are in your Prometheus, Linkerd’s proxy metrics will have thelabel job="linkerd-proxy" and Linkerd’s control plane metrics will have thelabel job="linkerd-controller". For more information on specific metric andlabel definitions, have a look at Proxy Metrics.

    For more information on Prometheus’ /federate endpoint, have a look at the.

    If you are not using Prometheus as your own long-term data store, you may beable to leverage one of Prometheus’s manyintegrations toautomatically extract data from Linkerd’s Prometheus instance into the datastore of your choice. Please refer to the Prometheus documentation for details.

    If neither Prometheus federation nor Prometheus integrations are options foryou, it is possible to call Prometheus’s APIs to extract data from Linkerd.

    NoteIf your data store is outside the Kubernetes cluster, it is likely thatyou’ll want to set upat a domain name of your choice with authentication.

    Similar to the /federate API, Prometheus provides a JSON query API toretrieve all metrics:

    1. curl http://linkerd-prometheus.linkerd.svc.cluster.local:9090/api/v1/query?query=request_total

    Finally, if you want to avoid Linkerd’s Prometheus entirely, you can query theLinkerd proxies directly on their /metrics endpoint.

    For example, to view /metrics from a single Linkerd proxy, running in thelinkerd namespace: