mirror of https://github.com/istio/istio.io.git
119 lines
4.5 KiB
Markdown
119 lines
4.5 KiB
Markdown
---
|
|
title: Querying Metrics from Prometheus
|
|
description: This task shows you how to query for Istio Metrics using Prometheus.
|
|
weight: 30
|
|
keywords: [telemetry,metrics]
|
|
aliases:
|
|
- /docs/tasks/telemetry/querying-metrics/
|
|
---
|
|
|
|
This task shows you how to query for Istio Metrics using Prometheus. As part of
|
|
this task, you will use the web-based interface for querying metric values.
|
|
|
|
The [Bookinfo](/docs/examples/bookinfo/) sample application is used as
|
|
the example application throughout this task.
|
|
|
|
## Before you begin
|
|
|
|
[Install Istio](/docs/setup/) in your cluster and deploy an
|
|
application.
|
|
|
|
## Querying Istio Metrics
|
|
|
|
1. Verify that the `prometheus` service is running in your cluster.
|
|
|
|
In Kubernetes environments, execute the following command:
|
|
|
|
{{< text bash >}}
|
|
$ kubectl -n istio-system get svc prometheus
|
|
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
|
prometheus 10.59.241.54 <none> 9090/TCP 2m
|
|
{{< /text >}}
|
|
|
|
1. Send traffic to the mesh.
|
|
|
|
For the Bookinfo sample, visit `http://$GATEWAY_URL/productpage` in your web
|
|
browser or issue the following command:
|
|
|
|
{{< text bash >}}
|
|
$ curl http://$GATEWAY_URL/productpage
|
|
{{< /text >}}
|
|
|
|
{{< tip >}}
|
|
`$GATEWAY_URL` is the value set in the [Bookinfo](/docs/examples/bookinfo/) example.
|
|
{{< /tip >}}
|
|
|
|
1. Open the Prometheus UI.
|
|
|
|
In Kubernetes environments, execute the following command:
|
|
|
|
{{< text bash >}}
|
|
$ kubectl -n istio-system port-forward $(kubectl -n istio-system get pod -l app=prometheus -o jsonpath='{.items[0].metadata.name}') 9090:9090 &
|
|
{{< /text >}}
|
|
|
|
Visit [http://localhost:9090/graph](http://localhost:9090/graph) in your web browser.
|
|
|
|
1. Execute a Prometheus query.
|
|
|
|
In the "Expression" input box at the top of the web page, enter the text:
|
|
`istio_requests_total`. Then, click the **Execute** button.
|
|
|
|
The results will be similar to:
|
|
|
|
{{< image link="./prometheus_query_result.png" caption="Prometheus Query Result" >}}
|
|
|
|
Other queries to try:
|
|
|
|
- Total count of all requests to the `productpage` service:
|
|
|
|
{{< text plain >}}
|
|
istio_requests_total{destination_service="productpage.default.svc.cluster.local"}
|
|
{{< /text >}}
|
|
|
|
- Total count of all requests to `v3` of the `reviews` service:
|
|
|
|
{{< text plain >}}
|
|
istio_requests_total{destination_service="reviews.default.svc.cluster.local", destination_version="v3"}
|
|
{{< /text >}}
|
|
|
|
This query returns the current total count of all requests to the v3 of the `reviews` service.
|
|
|
|
- Rate of requests over the past 5 minutes to all instances of the `productpage` service:
|
|
|
|
{{< text plain >}}
|
|
rate(istio_requests_total{destination_service=~"productpage.*", response_code="200"}[5m])
|
|
{{< /text >}}
|
|
|
|
### About the Prometheus add-on
|
|
|
|
Mixer comes with a built-in [Prometheus](https://prometheus.io) adapter that
|
|
exposes an endpoint serving generated metric values. The Prometheus add-on is a
|
|
Prometheus server that comes preconfigured to scrape Mixer endpoints to collect
|
|
the exposed metrics. It provides a mechanism for persistent storage and querying
|
|
of Istio metrics.
|
|
|
|
The configured Prometheus add-on scrapes the following endpoints:
|
|
|
|
1. `istio-telemetry.istio-system:42422`: The `istio-mesh` job returns all Mixer-generated metrics.
|
|
1. `istio-telemetry.istio-system:15014`: The `istio-telemetry` job returns all Mixer-specific metrics. Use this endpoint to monitor Mixer itself.
|
|
1. `istio-proxy:15090`: The `envoy-stats` job returns raw stats generated by Envoy. Prometheus is configured to look for pods with the `envoy-prom` endpoint exposed. The add-on configuration filters out a large number of envoy metrics during collection in an attempt to limit the scale of data by the add-on processes.
|
|
1. `istio-pilot.istio-system:15014`: The `pilot` job returns the Pilot-generated metrics.
|
|
1. `istio-galley.istio-system:15014`: The `galley` job returns the Galley-generated metrics.
|
|
1. `istio-policy.istio-system:15014`: The `istio-policy` job returns all policy-related metrics.
|
|
1. `istio-citadel.istio-system:15014`: The `istio-citadel` job returns all Citadel-generated metrics.
|
|
|
|
For more on querying Prometheus, please read their [querying
|
|
docs](https://prometheus.io/docs/querying/basics/).
|
|
|
|
## Cleanup
|
|
|
|
- Remove any `kubectl port-forward` processes that may still be running:
|
|
|
|
{{< text bash >}}
|
|
$ killall kubectl
|
|
{{< /text >}}
|
|
|
|
- If you are not planning to explore any follow-on tasks, refer to the
|
|
[Bookinfo cleanup](/docs/examples/bookinfo/#cleanup) instructions
|
|
to shutdown the application.
|