×

监控堆栈组件在每个 OpenShift Container Platform 安装中默认部署,并由集群监控运算符 (CMO) 管理。这些组件包括 Prometheus、Alertmanager、Thanos Querier 等。CMO 还部署 Telemeter 客户端,该客户端将平台 Prometheus 实例中的部分数据发送给 Red Hat,以方便集群的远程健康监控。

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

使用服务网格配置 OpenShift 监控

您可以将 Red Hat OpenShift Service Mesh 与用户工作负载监控集成。

前提条件
步骤
  1. 创建一个名为 servicemonitor.yml 的 YAML 文件来监控 Istio 控制平面

    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
  2. 运行以下命令应用 YAML 文件

    $ oc apply -f servicemonitor.yml
  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__"
        - action: labeldrop
          regex: "__meta_kubernetes_pod_label_(.+)"
        - sourceLabels: ["__meta_kubernetes_namespace"]
          action: replace
          targetLabel: namespace
        - sourceLabels: ["__meta_kubernetes_pod_name"]
          action: replace
          targetLabel: pod_name
    1 由于 OpenShift Container Platform 监控会忽略 ServiceMonitorPodMonitor 对象中的 namespaceSelector 规范,因此必须在所有网格命名空间(包括 Istio 控制平面命名空间)中应用 PodMonitor 对象。
  4. 运行以下命令应用 YAML 文件

    $ oc apply -f podmonitor.yml
  5. 在 OpenShift 控制台中,转到**观察** → **指标**,并运行查询 istio_requests_total

    查询返回结果可能需要几分钟时间。**指标** 实现可能需要几分钟才能返回结果。