第 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 命名空间中:
创建用于收集服务和公开指标的
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运行以下命令以应用该文件:
oc apply -f创建用于设置监控权限的
角色。请参阅以下 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运行以下命令以应用该文件:
oc apply -f创建一个
RoleBinding,将角色绑定绑定到 Prometheus monitoringServiceAccount,如下例所示: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运行以下命令以应用该文件:
oc apply -f要验证,请在仪表板中运行以下查询以查找 Subscription Operator Metrics Service 报告的指标:
{service="hub-subscription-metrics"}
1.1.2.2. 提取受管集群 复制链接链接已复制到粘贴板!
请参阅以下步骤为受管集群公开指标。这些文件位于 openshift-monitoring 命名空间中:
创建
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运行以下命令以应用您的文件:
oc apply -f创建用于设置监控权限的
角色。请参阅以下 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运行以下命令以应用该文件:
oc apply -f创建一个
RoleBinding,将Role绑定到 Prometheus monitoringServiceAccount: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运行以下命令以应用该文件:
oc apply -f运行以下查询来查找 Subscription Operator Metrics Service 报告的指标,在
Prometheus仪表板中验证:{service="mc-subscription-metrics"}
1.1.3. 提取独立集群 复制链接链接已复制到粘贴板!
创建
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创建用于设置监控权限的
角色:oc apply -fapiVersion: 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创建一个
RoleBinding,将Role绑定到 Prometheus monitoringServiceAccount。请参阅以下 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运行以下命令以应用该文件:
oc apply -f运行以下查询来查找 Subscription Operator Metrics Service 报告的指标,在
Prometheus仪表板中验证:{service="standalone-subscription-metrics"}