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.

Cleanup

  • 在k8s环境,执行如下命令移除Prometheus插件:
kubectl delete -f install/kubernetes/addons/prometheus.yaml
  • 移除可能还在运行的任何 kubectl port-forward 进程
killall kubectl
  • 如果你不打算探索接下来地任何课题,参考 Bookinfo cleanup 指南来关闭应用。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Prometheus 是一个开源的监控系统,它专注于收集并存储基于时间序列的数据,常用于监控服务器、应用程序和基础设施的性能指标。Prometheus 提供了强大的查询语言 PromQL,使得用户能够灵活地查询和可视化监控数据。 在 Prometheus 中,监控项(也称为度量或 metrics)主要包括以下几个关键元素: 1. **指标(Metrics)**: 这是 Promethues 中最基本的监控单元,通常表示一个系统的某种度量,如 CPU 使用率、内存占用、网络流量等。每个指标都有一个唯一的名称(metric name),并附带标签(label)来提供更详细的上下文信息。 2. **标签示例(Label Examples)**: 每个指标都包含一组预定义的标签,这些标签提供了关于指标值来源或性质的信息,比如服务实例名称、主机名、时间戳等。 3. **度量类型(Value Types)**: 包括 gauge(随时间变化的值)、counter(累计计数)、summary(统计信息,如均值、95%分位数)、histogram(时间间隔内的计数值分布)等。 4. **采集器(Collectors)**: Prometheus 通过各种插件(collectors)来获取指标数据,这些插件可以是内建的(如 Node Exporter 对操作系统的监控),也可以是自定义的(用户编写的脚本或第三方服务提供的 API)。 5. **查询和告警(Querying and Alerting)**: 用户可以使用 PromQL 来查询指标历史数据,设置阈值以触发告警,当指标超出预设范围时,系统会发送通知或执行其他自动化操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值