istio.io/content/zh/docs/tasks/observability/metrics/querying-metrics/index.md

4.3 KiB
Raw Permalink Blame History

title description weight keywords aliases
通过 Prometheus 查询度量指标 本任务介绍如何通过 Prometheus 查询 Istio 度量指标。 30
telemetry
metrics
/zh/docs/tasks/telemetry/querying-metrics/
/zh/docs/tasks/telemetry/metrics/querying-metrics/

本任务介绍如何通过 Prometheus 查询 Istio 度量指标。作为任务的一部分,你将通过 web 界面查询度量指标值。

本任务以 Bookinfo 样本应用作为案例。

开始之前

在自身集群中安装 Istio 并部署一个应用。

查询 Istio 度量指标

  1. 验证自身集群中运行着 prometheus 服务。

    在 Kubernetes 环境中,执行如下命令:

    {{< text bash >}} $ kubectl -n istio-system get svc prometheus NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE prometheus 10.59.241.54 9090/TCP 2m {{< /text >}}

  2. 向网格发送流量。

    以 Bookinfo 为例,在 web 浏览器中访问 http://$GATEWAY_URL/productpage 或执行如下命令:

    {{< text bash >}} $ curl http://$GATEWAY_URL/productpage {{< /text >}}

    {{< tip >}} $GATEWAY_URL 是在 Bookinfo 应用中设置的值。 {{< /tip >}}

  3. 打开 Prometheus UI。

    在 Kubernetes 环境中,执行如下命令:

    {{< 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 >}}

    在 web 浏览器中访问 http://localhost:9090/graph

  4. 执行一个 Prometheus 查询。

    在 web 页面顶部的 "Expression" 对话框中,输入文本: istio_requests_total。然后点击 Execute 按钮。

结果类似于:

{{< image link="./prometheus_query_result.png" caption="Prometheus Query Result" >}}

其他查询:

  • 请求 productpage 服务的总次数:

    {{< text plain >}} istio_requests_total{destination_service="productpage.default.svc.cluster.local"} {{< /text >}}

  • 请求 reviews 服务 V3 版本的总次数:

    {{< text plain >}} istio_requests_total{destination_service="reviews.default.svc.cluster.local", destination_version="v3"} {{< /text >}}

    该查询返回所有请求 reviews 服务 v3 版本的当前总次数。

  • 过去 5 分钟 productpage 服务所有实例的请求频次:

    {{< text plain >}} rate(istio_requests_total{destination_service=~"productpage.*", response_code="200"}[5m]) {{< /text >}}

关于 Prometheus 插件

Mixer 自带一个内嵌的 Prometheus 适配器对外暴露一个端点负责提供度量指标值服务。Prometheus 插件是一个提前配置好的 Prometheus 服务器,旨在通过 Mixer 端点收集对外暴露的度量指标。插件提供了持久化存储和 Istio 度量指标查询机制。

Prometheus 插件预配抓捕如下端点:

  1. istio-telemetry.istio-system:42422: istio-mesh 任务返回所有 Mixer 生成的度量指标。
  2. istio-telemetry.istio-system:15014: istio-telemetry 任务返回所有 Mixer 特殊的度量指标。该端点用于监控 Mixer 本身。
  3. istio-proxy:15090: envoy-stats 任务返回 Envoy 生成的原始状态。Prometheus 被配置来查找对外暴露了 envoy-prom 端点的 pods。在收集过程中插件配置过滤掉大量 envoy 度量指标,从而限制插件进程的数据量。
  4. istio-pilot.istio-system:15014: pilot 任务返回 Pilot 生成的度量指标。
  5. istio-galley.istio-system:15014: galley 任务返回 Galley 生成的度量指标。
  6. istio-policy.istio-system:15014: istio-policy 任务返回所有策略相关的度量指标。
  7. istio-citadel.istio-system:15014: istio-citadel 任务返回所有 Citadel 生成的度量指标。

更多关于 Prometheus 查询的信息,请阅读 querying docs.

清除

  • 删除所有可能运行着的 kubectl port-forward 进程:

    {{< text bash >}} $ killall kubectl {{< /text >}}

  • 若不再执行后续任务,参考 Bookinfo cleanup 命令关闭应用。