Querying Metrics from Prometheus

这个task向你展示如何使用Prometheus 查询Istio Metric。在这个task中,你将安装Prometheus Istio插件并使用基于web的界面去查询metric值。
这个task中将使用 Bookinfo 作为示例应用。

Before you begin

  • 在你的集群中安装Istio并部署一个应用

Querying Istio Metrics

1.为了查询由Mixer提供的metrics,首先安装Prometheus插件。
在k8s环境中,执行:

kubectl apply -f install/kubernetes/addons/prometheus.yaml

2.确认你的集群中服务正在运行
在k8s环境中,执行:

kubectl -n istio-system get svc prometheus

结果类似:

NAME         CLUSTER-IP     EXTERNAL-IP   PORT(S)    AGE
prometheus   10.59.241.54   <none>        9090/TCP   2m

3.向网格发送流量
对于Bookinfo,在你的浏览器访问 http://$GATEWAY_URL/productpage 或者执行以下命令:

curl http://$GATEWAY_URL/productpage

注意:$GATEWAY_URL 是在 Bookinfo 指南中设置的值。

4.打开Prometheus的UI界面
在k8s环境中,执行:

kubectl -n istio-system port-forward $(kubectl -n istio-system get pod -l app=prometheus -o jsonpath='{.items[0].metadata.name}') 9090:9090 & 

在你的浏览器访问 http://localhost:9090/graph

5.执行一次Prometheus查询
在页面顶部的 “Expression”输入框中,输入:istio_request_count 然后点击 Execute 按钮。
结果将类似:
这里写图片描述

Other queries to try:

- Total count of all requests to `productpage` service:

  ```
  istio_request_count{destination_service="productpage.default.svc.cluster.local"}
  ```

- Total count of all requests to `v3` of the `reviews` service:

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

  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 `productpage` services:

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

About the Prometheus Add-on

Mixer自带一个内嵌的 Prometheus 适配器来暴露一个生成metric值的端点。Prometheus附加组件是一个为了调节Mixer端点去收集公开指标的预配置Prometheus服务器。它提供了一个持久存储和查询Istio metric的机制。
配置好的Prometheus插件搜刮三个端点:
1.istio-mesh (istio-mixer.istio-system:42422): 所有Mixer生成的网格metrics
2.mixer (istio-mixer.istio-system:9093): 所有Mixer指定metrics。被用来监控Mixer自己。
3.envoy (istio-mixer.istio-system:9102): 收集由Envoy生成的统计数据(从statsd转换到prometheus)。

更多关于查询Prometheus的,请阅读他们的 querying docs.

扫描二维码关注公众号,回复: 1304464 查看本文章

Cleanup

  • 在k8s环境,执行如下命令移除Prometheus插件:
kubectl delete -f install/kubernetes/addons/prometheus.yaml
  • 移除可能还在运行的任何 kubectl port-forward 进程
killall kubectl
  • 如果你不打算探索接下来地任何课题,参考 Bookinfo cleanup 指南来关闭应用。

猜你喜欢

转载自blog.csdn.net/ybt_c_index/article/details/80353980