指标和 Service Mesh

使用指标

应安装监控插件 ACP Basic Monitoring(之前称为 ACP Monitoring for Prometheus)或 ACP Advanced Monitoring(之前称为 ACP Monitoring for VictoriaMetrics),以便为 Alauda Service Mesh v2 Operator 和 Istio 控制平面提供指标。

将原生应用添加到网格后,您可以通过指标和自定义告警,监控运行在 Alauda Container Platform 上的原生应用的集群内运行状况和性能,覆盖 CPU 和内存使用率、网络连接以及其他资源使用情况。

配置 Service Mesh 监控

您可以将 Alauda Service Mesh 与监控集成,以启用服务网格的可观测性。监控提供对基本内置工具的访问,并提供 Kiali(Istio 专用控制台)用于图形、运行状况和指标视图的指标。Kiali 无需这些指标也能运行,但届时将无法使用这些视图。

先决条件

  • 已安装 Alauda Service Mesh。

操作步骤

创建名为 servicemonitor.yaml 的 YAML 文件以监控 Istio 控制平面:

ServiceMonitor 对象示例

servicemonitor.yaml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: istiod-monitor
  namespace: istio-system
  labels:
    # prometheus=kube-prometheus is required in ACP prometheus.
    prometheus: kube-prometheus
spec:
  targetLabels:
  - app
  selector:
    matchLabels:
      istio: pilot
    matchExpressions:
    - key: istio.io/tag
      operator: DoesNotExist
  endpoints:
  - port: http-monitoring
    interval: 60s
  1. 排除由 IstioRevisionTag 创建的服务。这些服务会选择与该修订版本服务相同的 istiod Pod,同时选择两者会导致控制平面被抓取两次。

运行以下命令应用 YAML 文件:

kubectl apply -f servicemonitor.yaml

创建名为 podmonitor.yaml 的 YAML 文件,以收集 Istio 代理(工作负载)的指标:

PodMonitor 对象示例

podmonitor.yaml
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
  name: istio-proxies-monitor
  namespace: istio-system
  labels:
    # prometheus=kube-prometheus is required in ACP prometheus.
    prometheus: kube-prometheus
spec:
  selector:
    matchExpressions:
    - key: istio-prometheus-ignore
      operator: DoesNotExist
  namespaceSelector:
    any: true
  jobLabel: envoy-stats
  podMetricsEndpoints:
  - path: /stats/prometheus
    interval: 60s
    relabelings:
    - action: keep
      sourceLabels: [ __meta_kubernetes_pod_container_name ]
      regex: "istio-proxy"
    - action: keep
      sourceLabels: [__meta_kubernetes_pod_annotationpresent_prometheus_io_scrape]
    - sourceLabels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
      action: replace
      regex: ([^:]+)(?::\d+)?;(\d+)
      replacement: "$1:$2"
      targetLabel: __address__
    - sourceLabels: [__meta_kubernetes_pod_label_app_kubernetes_io_name, __meta_kubernetes_pod_label_app]
      separator: ";"
      targetLabel: "app"
      action: replace
      regex: "(.+);.*|.*;(.+)"
      replacement: "${1}${2}"
    - sourceLabels: [__meta_kubernetes_pod_label_app_kubernetes_io_version, __meta_kubernetes_pod_label_version]
      separator: ";"
      targetLabel: "version"
      action: replace
      regex: "(.+);.*|.*;(.+)"
      replacement: "${1}${2}"
    # additional labels
    - sourceLabels: [__meta_kubernetes_namespace]
      action: replace
      targetLabel: namespace
    # - action: replace
    #   targetLabel: mesh_id
    #   replacement: "<mesh_id>"
  1. 在 Istio 控制平面命名空间中仅创建一次 PodMonitor 对象。namespaceSelector 与 any: true 配合使用时,会抓取每个命名空间中的代理;在其他命名空间中创建副本则会再次抓取所有代理。
  2. 指定实际的网格 ID。仅当在 ambient 模式下运行,且多个集群共享同一监控数据源时,才需要 mesh_id 标签。

运行以下命令应用 YAML 文件:

kubectl apply -f podmonitor.yaml

创建名为 asm-telemetry.yaml 的 YAML 文件,以配置 Istio 代理(工作负载)的 Prometheus 指标:

Istio Telemetry 资源示例

asm-telemetry.yaml
apiVersion: telemetry.istio.io/v1
kind: Telemetry
metadata:
  name: asm-default
  namespace: istio-system
spec:
  metrics:
    - providers:
        - name: prometheus
      overrides:
        - tagOverrides:
            mesh_id:
              value: xds.node.metadata['MESH_ID']
  1. 将 mesh_id 标签添加到 Prometheus 指标。

运行以下命令应用 YAML 文件:

kubectl apply -f asm-telemetry.yaml