Istio 通过 Prometheus 查询度量指标

半兽人 发表于: 2021-11-23   最后更新时间: 2021-11-23 23:45:52  
{{totalSubscript}} 订阅, 1,386 游览

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

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

开始之前

查询 Istio 度量指标

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

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

    $ kubectl -n istio-system get svc prometheus
    NAME         CLUSTER-IP     EXTERNAL-IP   PORT(S)    AGE
    prometheus   10.59.241.54   <none>        9090/TCP   2m
    
  2. 向网格发送流量。

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

    $ curl http://$GATEWAY_URL/productpage
    

    $GATEWAY_URL 是在 Bookinfo 应用中设置的值。

  3. 打开 Prometheus UI。

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

    $ istioctl dashboard prometheus
    

    点击标题中 Prometheus 右侧的 Graph。

  4. 执行一个 Prometheus 查询。

    在 web 页面顶部的 “Expression” 对话框中,输入文本:

    istio_requests_total
    

    然后点击 Execute 按钮。

结果类似于:

Prometheus 查询结果

您还可以通过选择 Execute 按钮下方的“图形”选项卡以图形方式查看查询结果。

Prometheus 查询结果 - Graphical

其他查询尝试:

  • 请求 productpage 服务的总次数:

    istio_requests_total{destination_service="productpage.default.svc.cluster.local"}
    
  • 请求 reviews 服务 V3 版本的总次数:

    istio_requests_total{destination_service="reviews.default.svc.cluster.local", destination_version="v3"}
    

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

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

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

关于 Prometheus 插件

Prometheus 插件是预先配置抓取 Istio 端点收集指标的 Prometheus 服务器。它提供了一种持久存储和查询 Istio 指标的机制。

更新于 2021-11-23
在线,2小时前登录

查看istio更多相关的文章或提一个关于istio的问题,也可以与我们一起分享文章