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 指南来关闭应用。

Collecting Stones

03-28

Trudy is playing a phone game called Collecting Stones. In this game, a robert is placed on the upper-left corner of the board, which consists of 8x8 grids. On each grid, there are less than 2000001 stones. The robert can move up, down, right, up-right and down-right, but can not move into a grid that has already been passed before. All the stones on the grids which were passed by the robert are collected and Trudy is want to know if it is possible to collect exactly M number of stones when the robert arrives at the lower-right corner.nnInput:nnThe first line of input contains a single integer T(T<=20), the number of testcases. In the first line of each testcase, there is a number M described above, and follows 8x8 numbers, which represents the number of stones on each grid. Note that M will not greater than the sum of all stones on the board.nnOutput:nnFor each testcase, output "Yes" if there exists a path for the robert to collect exactly M number of stones, output "No" otherwise.nnSample Input:n2n374n1 2 3 4 5 6 7 8n9 10 11 12 13 14 15 16n17 18 19 20 21 22 23 24n25 26 27 28 29 30 31 32n33 34 35 36 37 38 39 40n41 42 43 44 45 46 47 48n49 50 51 52 53 54 55 56n57 58 59 60 61 62 63 64n2032n1 2 3 4 5 6 7 8n9 10 11 12 13 14 15 16n17 18 19 20 21 22 23 24n25 26 27 28 29 30 31 32n33 34 35 36 37 38 39 40n41 42 43 44 45 46 47 48n49 50 51 52 53 54 55 56n57 58 59 60 61 62 63 64nSample Output:nYesnNonNote for the first sample: A possible path is 1, 10 18, 19, 20, 29, 38, 31, 40, 48, 56, 64.

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试

关闭