第 2 章 指标和 Service Mesh


2.1. 使用指标

监控堆栈组件会在每次 OpenShift Container Platform 安装中部署,并由 Cluster Monitoring Operator (CMO) 管理。这些组件包括 Prometheus、Alertmanager、Thanos Querier 等。CMO 还部署 Telemeter 客户端,该客户端从平台 Prometheus 实例向红帽发送一个部分数据,以便为集群提供远程健康监控。

将应用程序添加到网格后,您可以使用 OpenShift Container Platform 上运行的应用程序监控集群内健康和性能,使用指标和自定义警报用于 CPU 和内存用量、网络连接和其他资源使用量。

2.1.1. 使用 Service Mesh 配置 OpenShift Monitoring

您可以将 Red Hat OpenShift Service Mesh 与用户工作负载监控集成,以便在服务网格中启用可观察性。用户工作负载监控提供对基本内置工具的访问,是运行 Kiali (用于 Istio 的专用控制台)所必需的。

先决条件

流程

  1. 创建名为 servicemonitor.yml 的 YAML 文件来监控 Istio control plane:

    ServiceMonitor 对象示例

    apiVersion: monitoring.coreos.com/v1
    kind: ServiceMonitor
    metadata:
      name: istiod-monitor
      namespace: istio-system
    spec:
      targetLabels:
      - app
      selector:
        matchLabels:
          istio: pilot
      endpoints:
      - port: http-monitoring
        interval: 30s
    Copy to Clipboard Toggle word wrap

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

    $ oc apply -f servicemonitor.yml
    Copy to Clipboard Toggle word wrap
  3. 创建名为 podmonitor.yml 的 YAML 文件,从 Istio 代理收集指标:

    PodMonitor 对象示例

    apiVersion: monitoring.coreos.com/v1
    kind: PodMonitor
    metadata:
      name: istio-proxies-monitor
      namespace: istio-system 
    1
    
    spec:
      selector:
        matchExpressions:
        - key: istio-prometheus-ignore
          operator: DoesNotExist
      podMetricsEndpoints:
      - path: /stats/prometheus
        interval: 30s
        relabelings:
        - action: keep
          sourceLabels: ["__meta_kubernetes_pod_container_name"]
          regex: "istio-proxy"
        - action: keep
          sourceLabels: ["__meta_kubernetes_pod_annotationpresent_prometheus_io_scrape"]
        - action: replace
          regex: (\d+);(([A-Fa-f0-9]{1,4}::?){1,7}[A-Fa-f0-9]{1,4})
          replacement: '[$2]:$1'
          sourceLabels: ["__meta_kubernetes_pod_annotation_prometheus_io_port","__meta_kubernetes_pod_ip"]
          targetLabel: "__address__"
        - action: replace
          regex: (\d+);((([0-9]+?)(\.|$)){4})
          replacement: '$2:$1'
          sourceLabels: ["__meta_kubernetes_pod_annotation_prometheus_io_port","__meta_kubernetes_pod_ip"]
          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}"
        - sourceLabels: ["__meta_kubernetes_namespace"]
          action: replace
          targetLabel: namespace
        - action: replace
          replacement: "the-mesh-identification-string" 
    2
    
          targetLabel: mesh_id
    Copy to Clipboard Toggle word wrap

    1
    指定 PodMonitor 对象必须应用到所有网格命名空间中,包括 Istio control plane 命名空间,因为 OpenShift Container Platform 监控会忽略 ServiceMonitorPodMonitor 对象中的 namespaceSelector spec。
    2
    指定实际的网格 ID。
  4. 运行以下命令来应用 YAML 文件:

    $ oc apply -f podmonitor.yml
    Copy to Clipboard Toggle word wrap
  5. 在 OpenShift 控制台中,进入 Observe Metrics,并运行查询 istio_requests_total

    注意

    指标 实施可能需要几分钟时间来返回结果。

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat