Istio为网格内的全部服务通讯生成详细的遥测。这种遥测功能提供了服务行为的可观察性,使运维同窗能够对应用程序进行故障排除,维护和优化,而不会给服务开发人员带来任何额外负担。经过Istio,能够全面了解受监控的服务如何与其余服务以及与Istio组件自己进行交互。后端
Istio生成如下遥测类型,以提供总体服务网格可观察性:api
本文咱们主要讲述metrcis。网络
在大多数状况下,指标是可观察性的起点。它们的收集成本低,存储成本低,便于快速分析,而且是衡量总体健康情况的好方法。
为了监控服务行为,Istio会为Istio服务网格内,外全部服务流量生成指标。这些度量标准提供有关行为的信息,例如总流量,流量中的错误率以及请求的响应时间。
除了监控网格内服务的行为外,监控网格自己的行为也很重要。 Istio组件根据本身的内部行为导出度量标准,以提供有关网格控制平面的运行情况和功能的看法。app
下面咱们详细讲下如下:运维
代理级别指标tcp
Istio指标收集从Sidecar代理(Envoy)开始。每一个代理都会生成一组丰富的指标,用于衡量经过代理的全部流量(入站和出站)。代理还提供有关代理自己的管理功能的详细统计信息,包括配置和运行情况信息。分布式
Envoy生成的度量标准以Envoy资源(例如侦听器和集群)的粒度提供对网格的监视。所以,须要了解网状服务和Envoy资源之间的链接才能监视Envoy指标。ide
Istio使咱们能够选择在每一个工做负载实例中生成和收集哪些Envoy指标。默认状况下,Istio仅启用Envoy生成的统计信息的一小部分,以免过多的度量标准后端并减小与度量标准收集相关的CPU开销。可是,咱们能够在须要时轻松扩展收集的代理指标集。这样能够针对性地调试网络行为,同时下降mesh监控的总成本。性能
Envoy官方文档包括Envoy统计信息收集的详细概述。 Envoy Statistics上的操做指南提供了有关控制代理级度量标准生成的更多信息。优化
代理级别指标示例:
envoy_cluster_internal_upstream_rq{response_code_class="2xx",cluster_name="xds-grpc"} 7163 envoy_cluster_upstream_rq_completed{cluster_name="xds-grpc"} 7164 envoy_cluster_ssl_connection_error{cluster_name="xds-grpc"} 0 envoy_cluster_lb_subsets_removed{cluster_name="xds-grpc"} 0 envoy_cluster_internal_upstream_rq{response_code="503",cluster_name="xds-grpc"} 1
服务级别指标
除了代理级别的度量标准以外,Istio还提供了一组面向服务的度量标准,用于监控服务通讯。这些指标涵盖了四个基本的服务监视需求:延迟,流量,错误和饱和度。 Istio附带了一组默认的仪表板,用于根据这些指标监视服务行为。
默认状况下,标准Istio指标会导出到Prometheus。
服务级别指标的使用彻底是可选的。运维同窗能够选择关闭这些指标的生成和收集,以知足他们的个性化需求。
服务级别指标示例:
istio_requests_total{ connection_security_policy="mutual_tls", destination_app="details", destination_canonical_service="details", destination_canonical_revision="v1", destination_principal="cluster.local/ns/default/sa/default", destination_service="details.default.svc.cluster.local", destination_service_name="details", destination_service_namespace="default", destination_version="v1", destination_workload="details-v1", destination_workload_namespace="default", reporter="destination", request_protocol="http", response_code="200", response_flags="-", source_app="productpage", source_canonical_service="productpage", source_canonical_revision="v1", source_principal="cluster.local/ns/default/sa/default", source_version="v1", source_workload="productpage-v1", source_workload_namespace="default" } 214
控制层指标
Istio控制平面还提供了一系列自我监控指标。这些度量标准容许监视Istio自己的行为(与网格内服务的行为不一样)。
主要包括pilot,galley等组件指标。更多相关信息能够参阅官方文档。
所谓最佳实践,只要包括如下两个方面:
好比为了聚合实例和容器之间的度量,使用如下recording rules更新默认的Prometheus配置:
groups: - name: "istio.recording-rules" interval: 5s rules: - record: "workload:istio_requests_total" expr: | sum without(instance, namespace, pod) (istio_requests_total) - record: "workload:istio_request_duration_milliseconds_count" expr: | sum without(instance, namespace, pod) (istio_request_duration_milliseconds_count) - record: "workload:istio_request_duration_milliseconds_sum" expr: | sum without(instance, namespace, pod) (istio_request_duration_milliseconds_sum) - record: "workload:istio_request_duration_milliseconds_bucket" expr: | sum without(instance, namespace, pod) (istio_request_duration_milliseconds_bucket) - record: "workload:istio_request_bytes_count" expr: | sum without(instance, namespace, pod) (istio_request_bytes_count) - record: "workload:istio_request_bytes_sum" expr: | sum without(instance, namespace, pod) (istio_request_bytes_sum) - record: "workload:istio_request_bytes_bucket" expr: | sum without(instance, namespace, pod) (istio_request_bytes_bucket) - record: "workload:istio_response_bytes_count" expr: | sum without(instance, namespace, pod) (istio_response_bytes_count) - record: "workload:istio_response_bytes_sum" expr: | sum without(instance, namespace, pod) (istio_response_bytes_sum) - record: "workload:istio_response_bytes_bucket" expr: | sum without(instance, namespace, pod) (istio_response_bytes_bucket) - record: "workload:istio_tcp_connections_opened_total" expr: | sum without(instance, namespace, pod) (istio_tcp_connections_opened_total) - record: "workload:istio_tcp_connections_closed_total" expr: | sum without(instance, namespace, pod) (istio_tcp_connections_opened_total) - record: "workload:istio_tcp_sent_bytes_total_count" expr: | sum without(instance, namespace, pod) (istio_tcp_sent_bytes_total_count) - record: "workload:istio_tcp_sent_bytes_total_sum" expr: | sum without(instance, namespace, pod) (istio_tcp_sent_bytes_total_sum) - record: "workload:istio_tcp_sent_bytes_total_bucket" expr: | sum without(instance, namespace, pod) (istio_tcp_sent_bytes_total_bucket) - record: "workload:istio_tcp_received_bytes_total_count" expr: | sum without(instance, namespace, pod) (istio_tcp_received_bytes_total_count) - record: "workload:istio_tcp_received_bytes_total_sum" expr: | sum without(instance, namespace, pod) (istio_tcp_received_bytes_total_sum) - record: "workload:istio_tcp_received_bytes_total_bucket" expr: | sum without(instance, namespace, pod) (istio_tcp_received_bytes_total_bucket)
暴露指标
默认条件下,istio经过为控制平面和数据平面的Pod增长注解的方式,告诉Prometheus采集指标的端口和路径。
好比控制层istiod组件:
apiVersion: v1 kind: Pod metadata: annotations: prometheus.io/port: "15014" prometheus.io/scrape: "true" sidecar.istio.io/inject: "false" labels: app: istiod
istiod 在端口15014暴露metrcis。
对于istio-ingressgateway :
apiVersion: v1 kind: Pod metadata: annotations: prometheus.io/path: /stats/prometheus prometheus.io/port: "15090" prometheus.io/scrape: "true" sidecar.istio.io/inject: "false" labels: app: istio-ingressgateway
istio-ingressgateway 在端口15090暴露metrcis。
对于数据平面的代理:
apiVersion: v1 kind: Pod metadata: annotations: prometheus.io/path: /stats/prometheus prometheus.io/port: "15020" prometheus.io/scrape: "true" labels: app: helloworld
proxy 在端口15020暴露metrcis。
因为ingressgateway和代理均为基于envoy实现,因此其metrcis路径均为/stats/prometheus。
Prometheus配置
此时咱们配置咱们的prometheus收集这些数据便可。实际上,就是典型的prometheus k8s 服务发现功能,具体就是对于pod的自动发现。
以下:
scrape_configs: - job_name: kubernetes-pods kubernetes_sd_configs: - role: pod relabel_configs: - action: keep regex: true source_labels: - __meta_kubernetes_pod_annotation_prometheus_io_scrape - action: replace regex: (.+) source_labels: - __meta_kubernetes_pod_annotation_prometheus_io_path target_label: __metrics_path__ - action: replace regex: ([^:]+)(?::d+)?;(d+) replacement: $1:$2 source_labels: - __address__ - __meta_kubernetes_pod_annotation_prometheus_io_port target_label: __address__ - action: labelmap regex: __meta_kubernetes_pod_label_(.+) - action: replace source_labels: - __meta_kubernetes_namespace target_label: kubernetes_namespace - action: replace source_labels: - __meta_kubernetes_pod_name target_label: kubernetes_pod_name
至此指标已经收集到咱们的监控系统中了,接下来就是展现。
Grafana是一个开源监视解决方案,可用于为Istio配置仪表板。您可使用Grafana监视Istio以及服务网格中应用程序的运行情况。
虽然您能够构建本身的仪表板,但Istio提供了一组预配置的仪表板,用于网格和控制平面的全部最重要的指标。
好比控制层平面监控,具体效果以下: