Exporting Metrics
Internally, Linkerd stores its metrics in a Prometheus instance that runs as part of the Viz extension. The following tutorial requires the viz extension to be installed with prometheus enabled. There are several basic approaches to exporting metrics data from Linkerd:
If you are using Prometheus as your own metrics store, we recommend taking advantage of Prometheus’s federation API, which is designed exactly for the use case of copying data from one Prometheus to another.
Simply add the following item to your in your Prometheus config file (replace {{.Namespace}}
with the namespace where the Linkerd Viz extension is running):
Alternatively, if you prefer to use Prometheus’ ServiceMonitors to configure your Prometheus, you can use this ServiceMonitor YAML (replace {{.Namespace}}
with the namespace where Linkerd Viz extension is running):
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
k8s-app: linkerd-prometheus
name: linkerd-federate
namespace: {{.Namespace}}
spec:
endpoints:
- interval: 30s
params:
match[]:
- '{job="linkerd-proxy"}'
- '{job="linkerd-controller"}'
path: /federate
port: admin-http
honorLabels: true
- action: keep
regex: '^prometheus$'
sourceLabels:
- '__meta_kubernetes_pod_container_name'
jobLabel: app
matchNames:
- {{.Namespace}}
selector:
matchLabels:
component: prometheus
That’s it! Your Prometheus cluster is now configured to federate Linkerd’s metrics from Linkerd’s internal Prometheus instance.
For more information on Prometheus’ /federate
endpoint, have a look at the Prometheus federation docs.
If you are not using Prometheus as your own long-term data store, you may be able to leverage one of Prometheus’s to automatically extract data from Linkerd’s Prometheus instance into the data store of your choice. Please refer to the Prometheus documentation for details.
If neither Prometheus federation nor Prometheus integrations are options for you, it is possible to call Prometheus’s APIs to extract data from Linkerd.
For example, you can call the federation API directly via a command like:
Note
Similar to the /federate
API, Prometheus provides a JSON query API to retrieve all metrics:
curl http://prometheus.linkerd-viz.svc.cluster.local:9090/api/v1/query?query=request_total
Finally, if you want to avoid Linkerd’s Prometheus entirely, you can query the Linkerd proxies directly on their /metrics
endpoint.
For example, to view /metrics
from a single Linkerd proxy, running in the linkerd
namespace:
and then:
Alternatively, linkerd diagnostics proxy-metrics
can be used to retrieve proxy metrics for a given workload.