Kube:Istio:在Mixer中上报metrics数据
Posted UpInTheVir
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Kube:Istio:在Mixer中上报metrics数据相关的知识,希望对你有一定的参考价值。
Kube:Istio:在Mixer中上报metrics数据
. 在Envoy中访问metrics数据
[root@k8s-192-168-0-52-kube01 ~]# kubectl get pod productpage-v1-7dffc94c79-lm9f7 -o jsonpath='{.status.containerStatuses[0].containerID}' | cut -c 10-21
989c557216df
[root@k8s-192-168-0-53-kube02 ~]# docker inspect -f {{.State.Pid}} 989c557216df
22266
[root@k8s-192-168-0-53-kube02 ~]# nsenter -t 22266 -n
[root@k8s-192-168-0-53-kube02 ~]# curl http://127.0.0.1:15000/stats|more
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
cluster.in.9080.bind_errors: 0
cluster.in.9080.internal.upstream_rq_200: 1
cluster.in.9080.internal.upstream_rq_2xx: 1
通过envoy的http://127.0.0.1:15000/stats位置,可以访问该proxy的metrics信息。
. 将Envoy的metrics数据上报至Mixer
- args:
- proxy
- sidecar
- --configPath
- /etc/istio/proxy
- --binaryPath
- /usr/local/bin/envoy
- --serviceCluster
- ratings
- --drainDuration
- 45s
- --parentShutdownDuration
- 1m0s
- --discoveryAddress
- istio-pilot.istio-system:8080
- --discoveryRefreshDelay
- 1s
- --zipkinAddress
- zipkin.istio-system:9411
- --connectTimeout
- 10s
- --statsdUdpAddress
- istio-mixer.istio-system:9125
- --proxyAdminPort
- "15000"
- --controlPlaneAuthPolicy
- NONE
- istio-mixer.istio-system:9125。
envoy通过连接mixer的9125端口上报metrics数据。
- name: statsd-to-prometheus
image: prom/statsd-exporter:v0.5.0
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9102
- containerPort: 9125
protocol: UDP
args:
- '-statsd.mapping-config=/etc/statsd/mapping.conf'
volumeMounts:
- name: config-volume
mountPath: /etc/statsd
mixer pod中的statsd-exporter容器的9125端口用于接收envoy上报的metrics数据。
mixer pod中的statsd-exporter容器的9102端口用于暴露经exporter转换后的prometheus格式的metrics数据。
. 在Mixer中访问Envoy上报的metrics数据
[root@k8s-192-168-0-52-kube01 ~]# curl http://10.16.1.4:9102/metrics |more
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
# HELP envoy_cluster_in_27017_membership_change Metric autogenerated by statsd_exporter.
# TYPE envoy_cluster_in_27017_membership_change counter
envoy_cluster_in_27017_membership_change 8
# HELP envoy_cluster_in_27017_membership_healthy Metric autogenerated by statsd_exporter.
# TYPE envoy_cluster_in_27017_membership_healthy gauge
envoy_cluster_in_27017_membership_healthy 1
# HELP envoy_cluster_in_27017_membership_total Metric autogenerated by statsd_exporter.
# TYPE envoy_cluster_in_27017_membership_total gauge
envoy_cluster_in_27017_membership_total 1
通过mixer的http://10.16.1.4:9102/metrics位置,可以访问经过转换后的,envoy上报给mixer的metrics数据。
. 在Prometheus中接收接收Mixer转换后的Envoy上报的metrics数据
- job_name: 'envoy'
# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 5s
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
kubernetes_sd_configs:
- role: endpoints
relabel_configs:
- source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name]
action: keep
regex: istio-system;istio-mixer;statsd-prom
prometheus通过mixer的statsd-prom端口接收metrics信息。
. 通过Mixer的Prometheus handler上报metrics数据
# 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
配置2个metrics,分别为:
mongo_sent_bytes。
mongo_received_bytes。
# 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"'
mongo_sent_bytes从名称为mongosentbytes.metric.default的instance中接收metrics数据。
mongo_received_bytes从名称为mongoreceivedbytes.metric.default的instance中接收metrics数据。
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
instance中服务名为mongodb.default.svc.cluster.local的tcp类型的数据会发送到handler。
. 在Mixer中访问Prometheus handler上报的metrics数据
[root@k8s-192-168-0-52-kube01 ~]# curl http://10.16.1.4:42422/metrics |grep istio_mongo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
# HELP istio_mongo_received_bytes mongo_received_bytes
# TYPE istio_mongo_received_bytes counter
istio_mongo_received_bytes{destination_version="v1",source_service="unknown",source_version="unknown"} 2760
# HELP istio_mongo_sent_bytes mongo_sent_bytes
# TYPE istio_mongo_sent_bytes counter
istio_mongo_sent_bytes{destination_version="v1",source_service="unknown",source_version="unknown"} 3432
100 100k 100 100k 0 0 23.3M 0 --:--:-- --:--:-- --:--:-- 32.7M
通过mixer的http://10.16.1.4:42422/metrics位置,可以访问prometheus handler上报给mixer的metrics数据。
. 在Prometheus中接收Mixer通过Prometheus handler上报的metrics数据
- job_name: 'istio-mesh'
# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 5s
kubernetes_sd_configs:
- role: endpoints
relabel_configs:
- source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name]
action: keep
regex: istio-system;istio-mixer;prometheus
prometheus通过mixer的prometheus端口接收metrics信息。
以上是关于Kube:Istio:在Mixer中上报metrics数据的主要内容,如果未能解决你的问题,请参考以下文章
idou老师教你学Istio 20 : Istio全景监控与拓扑
Istio 1.3 发布,HTTP 遥测不再需要 Mixer