第 1 章 健康指标


您可以使用指标来监控组件的健康状况。

请参阅以下文档:

1.1. 使用 metrics 服务

您可以使用 metrics (指标) 来监控 Red Hat Advanced Cluster Management for Kubernetes 中的组件健康状况。在 Metrics chronicle 概述中记录了许多自定义指标。

1.1.1. 访问 hub 集群指标服务

要查看收集的指标,您必须在 hub 集群上公开 metrics 服务。如果您的指标已在 Grafana 仪表板中公开,这个过程是可选的。

在 OpenShift Container Platform 控制台中查找 metrics 服务。点 Observe > Metrics

如果您没有在 Grafana 仪表板、Grafana Explorer 或 OpenShift Container Platform 控制台中看到指标,则 Prometheus 可能无法配置为提取指标。继续使用 Scrapping with Prometheus 来公开您的指标。

1.1.2. Scraping with Prometheus

您可以使用 Prometheus 来公开从产品控制台公开的指标。请参阅 hub 和受管集群指标的步骤。

1.1.2.1. 提取 hub 集群

请参阅以下流程来公开 hub 集群的指标。这些文件位于 openshift-monitoring 命名空间中:

  1. 创建用于收集服务和公开指标的 ServiceMonitor。请参阅以下 YAML 示例:

    apiVersion: monitoring.coreos.com/v1
    kind: ServiceMonitor
    metadata:
      name: hub-subscription-metrics
      namespace: openshift-monitoring
    spec:
      endpoints:
      - port: metrics
      namespaceSelector:
        matchNames:
        - open-cluster-management
      selector:
        matchLabels:
          app: hub-subscription-metrics
    Copy to Clipboard Toggle word wrap
  2. 运行以下命令以应用该文件:

    oc apply -f
    Copy to Clipboard Toggle word wrap
  3. 创建用于设置监控权限的角色。请参阅以下 YAML 文件:

    apiVersion: rbac.authorization.k8s.io/v1
    kind: Role
    metadata:
      name: prometheus-k8s-monitoring
      namespace: open-cluster-management
    rules:
    - apiGroups:
      - ""
      resources:
      - services
      - endpoints
      - pods
      verbs:
      - get
      - list
      - watch
    - apiGroups:
      - extensions
      resources:
      - ingresses
      verbs:
      - get
      - list
      - watch
    - apiGroups:
      - networking.k8s.io
      resources:
      - ingresses
      verbs:
      - get
      - list
      - watch
    Copy to Clipboard Toggle word wrap
  4. 运行以下命令以应用该文件:

    oc apply -f
    Copy to Clipboard Toggle word wrap
  5. 创建一个 RoleBinding,将角色绑定绑定到 Prometheus monitoring ServiceAccount,如下例所示:

    apiVersion: rbac.authorization.k8s.io/v1
    kind: RoleBinding
    metadata:
      name: prometheus-k8s-monitoring-binding
      namespace: open-cluster-management
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: Role
      name: prometheus-k8s-monitoring
    subjects:
    - kind: ServiceAccount
      name: prometheus-k8s
      namespace: monitoring
    Copy to Clipboard Toggle word wrap
  6. 运行以下命令以应用该文件:

    oc apply -f
    Copy to Clipboard Toggle word wrap
  7. 要验证,请在仪表板中运行以下查询以查找 Subscription Operator Metrics Service 报告的指标:

    {service="hub-subscription-metrics"}
    Copy to Clipboard Toggle word wrap

1.1.2.2. 提取受管集群

请参阅以下步骤为受管集群公开指标。这些文件位于 openshift-monitoring 命名空间中:

  1. 创建 ServiceMonitor 以收集服务公开指标。请参阅以下 YAML 文件示例:

    apiVersion: monitoring.coreos.com/v1
    kind: ServiceMonitor
    metadata:
      name: mc-subscription-metrics
      namespace: openshift-monitoring
    spec:
      endpoints:
      - port: metrics
      namespaceSelector:
        matchNames:
        - open-cluster-management-agent-addon
      selector:
        matchLabels:
          app: mc-subscription-metrics
    Copy to Clipboard Toggle word wrap
  2. 运行以下命令以应用您的文件:

    oc apply -f
    Copy to Clipboard Toggle word wrap
  3. 创建用于设置监控权限的角色。请参阅以下 YAML 文件示例:

    apiVersion: rbac.authorization.k8s.io/v1
    kind: Role
    metadata:
      name: prometheus-k8s-monitoring
      namespace: open-cluster-management-agent-addon
    rules:
    - apiGroups:
      - ""
      resources:
      - services
      - endpoints
      - pods
      verbs:
      - get
      - list
      - watch
    - apiGroups:
      - extensions
      resources:
      - ingresses
      verbs:
      - get
      - list
      - watch
    - apiGroups:
      - networking.k8s.io
      resources:
      - ingresses
      verbs:
      - get
      - list
      - watch
    Copy to Clipboard Toggle word wrap
  4. 运行以下命令以应用该文件:

    oc apply -f
    Copy to Clipboard Toggle word wrap
  5. 创建一个 RoleBinding,将 Role 绑定到 Prometheus monitoring ServiceAccount

    apiVersion: rbac.authorization.k8s.io/v1
    kind: RoleBinding
    metadata:
      name: prometheus-k8s-monitoring-binding
      namespace: open-cluster-management-agent-addon
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: Role
      name: prometheus-k8s-monitoring
    subjects:
    - kind: ServiceAccount
      name: prometheus-k8s
      namespace: monitoring
    Copy to Clipboard Toggle word wrap
  6. 运行以下命令以应用该文件:

    oc apply -f
    Copy to Clipboard Toggle word wrap
  7. 运行以下查询来查找 Subscription Operator Metrics Service 报告的指标,在 Prometheus 仪表板中验证:

    {service="mc-subscription-metrics"}
    Copy to Clipboard Toggle word wrap

1.1.3. 提取独立集群

  1. 创建 ServiceMonitor 以收集服务公开指标:

    apiVersion: monitoring.coreos.com/v1
    kind: ServiceMonitor
    metadata:
      name: standalone-subscription-metrics
      namespace: openshift-monitoring
    spec:
      endpoints:
      - port: metrics
      namespaceSelector:
        matchNames:
        - open-cluster-management
      selector:
        matchLabels:
          app: standalone-subscription-metrics
    Copy to Clipboard Toggle word wrap
  2. 创建用于设置监控权限的角色:

    oc apply -f
    Copy to Clipboard Toggle word wrap
    apiVersion: rbac.authorization.k8s.io/v1
    kind: Role
    metadata:
      name: prometheus-k8s-monitoring
      namespace: open-cluster-management
    rules:
    - apiGroups:
      - ""
      resources:
      - services
      - endpoints
      - pods
      verbs:
      - get
      - list
      - watch
    - apiGroups:
      - extensions
      resources:
      - ingresses
      verbs:
      - get
      - list
      - watch
    - apiGroups:
      - networking.k8s.io
      resources:
      - ingresses
      verbs:
      - get
      - list
      - watch
    Copy to Clipboard Toggle word wrap
  3. 创建一个 RoleBinding,将 Role 绑定到 Prometheus monitoring ServiceAccount。请参阅以下 YAML 文件示例:

    apiVersion: rbac.authorization.k8s.io/v1
    kind: RoleBinding
    metadata:
      name: prometheus-k8s-monitoring-binding
      namespace: open-cluster-management
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: Role
      name: prometheus-k8s-monitoring
    subjects:
    - kind: ServiceAccount
      name: prometheus-k8s
      namespace: monitoring
    Copy to Clipboard Toggle word wrap
  4. 运行以下命令以应用该文件:

    oc apply -f
    Copy to Clipboard Toggle word wrap
  5. 运行以下查询来查找 Subscription Operator Metrics Service 报告的指标,在 Prometheus 仪表板中验证:

    {service="standalone-subscription-metrics"}
    Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2025 Red Hat