Collecting Metrics for TCP services

这个task展示如何配置Istio自动收集网格中的TCP服务的遥测。完成这个task,调用一个你的网格中的TCP服务将会生成一个新的metric。

本task中使用 Bookinfo 作为示例。

Before you begin

  • 在你的集群安装Istio并部署一个应用。
  • 这个task假设Bookinfo 被部署在default 命名空间中。如果你使用不同的命名空间,你将需要更新例子中的配置和命令。
  • 安装Prometheus 插件。Prometheus 将被用来验证task是否成功。
kubectl apply -f install/kubernetes/addons/prometheus.yaml

Prometheus 的更多细节。

Collecting new telemetry data

1.新建一个新的YAML文件来保存Istio自动生成和收集的信息metric和日志流的配置。
保存如下内容到 tcp_telemetry.yaml:

# Configuration for a metric measuring bytes sent from a server
# to a client
apiVersion: "config.istio.io/v1alpha2"
kind: metric
metadata:
  name: mongosentbytes
  namespace: default
spec:
  value: connection.sent.bytes | 0 # uses a TCP-specific attribute
  dimensions:
    source_service: source.service | "unknown"
    source_version: source.labels["version"] | "unknown"
    destination_version: destination.labels["version"] | "unknown"
  monitoredResourceType: '"UNSPECIFIED"'
---
# Configuration for a metric measuring bytes sent from a client
# to a server
apiVersion: "config.istio.io/v1alpha2"
kind: metric
metadata:
  name: mongoreceivedbytes
  namespace: default
spec:
  value: connection.received.bytes | 0 # uses a TCP-specific attribute
  dimensions:
    source_service: source.service | "unknown"
    source_version: source.labels["version"] | "unknown"
    destination_version: destination.labels["version"] | "unknown"
  monitoredResourceType: '"UNSPECIFIED"'
---
# Configuration for a Prometheus handler
apiVersion: "config.istio.io/v1alpha2"
kind: prometheus
metadata:
  name: mongohandler
  namespace: default
spec:
  metrics:
  - name: mongo_sent_bytes # Prometheus metric name
    instance_name: mongosentbytes.metric.default # Mixer instance name (fully-qualified)
    kind: COUNTER
    label_names:
    - source_service
    - source_version
    - destination_version
  - name: mongo_received_bytes # Prometheus metric name
    instance_name: mongoreceivedbytes.metric.default # Mixer instance name (fully-qualified)
    kind: COUNTER
    label_names:
    - source_service
    - source_version
    - destination_version
---
# Rule to send metric instances to a Prometheus handler
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
  name: mongoprom
  namespace: default
spec:
  match: context.protocol == "tcp"
         && destination.service == "mongodb.default.svc.cluster.local"
  actions:
  - handler: mongohandler.prometheus
    instances:
    - mongoreceivedbytes.metric
    - mongosentbytes.metric

2.推送新配置

istioctl create -f tcp_telemetry.yaml

预期输出类似:

Created config metric/default/mongosentbytes at revision 3852843
Created config metric/default/mongoreceivedbytes at revision 3852844
Created config prometheus/default/mongohandler at revision 3852845
Created config rule/default/mongoprom at revision 3852846

3.使用MongoDB部署Bookinfo 。

  • 安装 ratings 服务的v2

如果你使用开启自动注入sidecar 的集群,使用kubectl 简单部署服务:

kubectl apply -f samples/bookinfo/kube/bookinfo-ratings-v2.yaml

如果你手动注入sidecar,使用:

kubectl apply -f <(istioctl kube-inject -f samples/bookinfo/kube/bookinfo-ratings-v2.yaml)

预期结果:

deployment "ratings-v2" configured
  • 安装mongodb 服务:

如果你使用开启自动注入sidecar 的集群,使用kubectl 简单部署服务:

kubectl apply -f samples/bookinfo/kube/bookinfo-db.yaml

如果你手动注入sidecar,使用:

kubectl apply -f <(istioctl kube-inject -f samples/bookinfo/kube/bookinfo-db.yaml)

预期结果:

service "mongodb" configured
deployment "mongodb-v1" configured
  • 为发送到 v2 版的ratings 服务的流量添加路由规则:
istioctl create -f samples/bookinfo/kube/route-rule-ratings-db.yaml

预期结果:

Created config route-rule//ratings-test-v2 at revision 7216403
Created config route-rule//reviews-test-ratings-v2 at revision 7216404

4.向示例应用发送流量
对于Bookinfo ,在你浏览器访问 http://$GATEWAY_URL/productpage 或者使用如下命令:

curl http://$GATEWAY_URL/productpage

5.核实生成和收集的新的metric值。
在k8s环境中,通过执行如下命令来为Prometheus 设置端口转发:

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

通过Prometheus UI查看新的metric值。
提供的链接开启了 Prometheus UI,并执行对istio_mongo_received_bytes metric值的查询。Console(控制台)选项卡中展示的表格内容类似:

istio_mongo_received_bytes{destination_version="v1",instance="istio-mixer.istio-system:42422",job="istio-mesh",source_service="ratings.default.svc.cluster.local",source_version="v2"}  2317

注意:Istio也收集对于MongoDB指定协议的统计。例如,从ratings 服务发送的 OP_QUERY信息的全部值都被这个metric收集起来了:envoy_mongo_mongo_collection_ratings_query_total (click here to execute the query)。

Understanding TCP telemetry collection

在这个task中,你添加Istio配置来指示Mixer为网格中的所有到TCP服务的流量自动生成和报告一个新的metric。

Collecting Metrics and Logs 类似,新的配置包含 instances, a handler, and a rule 。请查看那个task的metric收集组件的完整描述。

TCP服务的Metrics标准集仅在可用于实例的有限属性集中有所不同。

TCP Attributes

通过Istio的几个指定TCP属性开启TCP策略和控制。这些属性通过服务端Envoy代理生成并在建立连接和关闭连接时转发给Mixer。另外,context属性提供区别 httptcp 协议能力的策略。
这里写图片描述

Cleanup

  • 移除新的遥测配置
istioctl delete -f tcp_telemetry.yaml
  • 移除任何 port-forward 进程:
killall kubectl
  • 如果你不打算探索接下来地任何课题,参考 Bookinfo cleanup 指南来关闭应用。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
s is a fascinating hobby for many people, particularly those interested in studying insects and their behavior. However, it's crucial to follow ethical and legal guidelines, and to ensure that bugs are collected and handled humanely. Here are some tips for collecting bugs: 1. Check local regulations: Before you start collecting bugs, check your local regulations to make sure it is legal to do so. Some areas may have restrictions on collecting certain species or collecting bugs in protected areas. 2. Use ethical and humane methods: It's important to use ethical and humane methods when collecting bugs. Avoid using harmful chemicals, and instead use gentle methods such as nets or traps. Handle the bugs carefully and avoid injuring them. 3. Respect the environment: When collecting bugs, make sure to respect the environment and the other creatures that live there. Avoid damaging plants or other habitats, and leave the area as you found it. 4. Keep accurate records: Keep accurate records of the species you collect, when and where you collected them, and any other relevant information. This can be helpful for scientific research and for tracking changes in insect populations over time. 5. Release the bugs: After you have collected and observed the bugs, release them back into their natural habitat. Make sure to do so in a safe and appropriate location, and handle them carefully to avoid injury. Remember that collecting bugs can be a fun and educational hobby, but it's important to do so responsibly and ethically. By following these guidelines, you can enjoy the hobby while also helping to protect these fascinating creatures and their habitats.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值