日志记录警报


Red Hat OpenShift Logging 6.3

配置日志记录警报.

Red Hat OpenShift Documentation Team

摘要

本文档提供有关配置日志记录警报的信息。

第 1 章 默认日志记录警报

日志记录警报作为 Red Hat OpenShift Logging Operator 安装的一部分安装。警报取决于日志收集和日志存储后端导出的指标。如果在安装 Red Hat OpenShift Logging Operator 时选择 Enable operator recommended cluster monitoring 选项来启用这些指标。

默认日志记录警报发送到 openshift-monitoring 命名空间中的 OpenShift Container Platform 监控堆栈 Alertmanager,除非您禁用了本地 Alertmanager 实例。

1.1. 从 Administrator 视角访问 Alerting UI

您可以通过 OpenShift Container Platform Web 控制台的 Administrator 视角访问 Alerting 用户界面(UI)。

先决条件

  • 有管理员权限。
  • 访问 OpenShift Container Platform web 控制台。

流程

  • Administrator 视角中,进入 ObserveAlerting。此视角中的 Alerting UI 中的三个主要页面是 AlertsSilencesAlerting 规则 页面。

1.2. Red Hat OpenShift Logging Operator 警报

以下警报由 Vector 收集器生成。您可以在 OpenShift Container Platform Web 控制台中查看这些警报。

Expand
表 1.1. Vector 收集器警报
警报消息描述重要性

CollectorNodeDown

Prometheus could not scrape vector <instance> for more than 10m.

向量报告 Prometheus 无法提取特定的 Vector 实例。

Critical

DiskBufferUsage

收集器可能会消耗太多的节点磁盘,<value>

收集器在主机上消耗太多的节点磁盘。

Warning

CollectorHigh403ForbiddenResponseRate

在命名空间 <namespace> 中为收集器 <instance> 检测到的 "HTTP 403 Forbidden" 响应的高率(用于输出 <label>)。403 响应的速度在最后 2 分钟内是 <rate>,持续 5 分钟。这可能表示授权问题。

对于输出 "<output>",在命名空间 <namespace> 中至少使用 "HTTP 403 Forbidden" 用于收集器 "<intance>" 的发送请求,至少 10%。

Critical

1.3. Loki Operator 警报

以下警报由 Loki Operator 生成。您可以在 OpenShift Container Platform Web 控制台中查看这些警报。

Expand
表 1.2. Loki Operator 警报
警报消息描述重要性

LokiRequestErrors

{{ $labels.job }} {{ $labels.route }} 正在遇到 <value>% 错误。

至少 10% 的请求会导致 5xx 服务器错误。

critical

LokiStackWriteRequestErrors

<value>% of write requests from {{ $labels.job }} in <namespace> are returned with server errors。

至少 10% 的写入 lokistack-gateway 的请求会导致 5xx 服务器错误。

critical

LokiStackReadRequestErrors

<value>% 的查询请求来自 {{ $labels.job }} 中的查询请求,以服务器错误返回。

至少 10% 的查询请求到 lokistack-gateway 会导致 5xx 服务器错误。

critical

LokiRequestPanics

{{ $labels.job }} 正在增加 <value> panics。

触发 panic。

critical

LokiRequestLatency

{{ $labels.job }} {{ $labels.route }} 正在遇到 <value>s 99th percentile 延迟。

99th percentile 遇到超过 1 秒的延迟。

critical

LokiTenantRateLimit

{{ $labels.job }} {{ $labels.route }} 正在遇到 429 错误。

至少 10% 的请求收到速率限制错误代码。

warning

LokiStorageSlowWrite

存储路径会经历缓慢的写入响应率。

存储路径遇到的读取响应率缓慢。

warning

LokiWritePathHighLoad

写入路径会出现高负载。

写入路径会出现高负载,从而导致后向存储清除。

warning

LokiReadPathHighLoad

读取路径会经历高负载。

读取路径具有大量查询,从而导致响应时间较长。

warning

LokiDiscardedSamplesWarning

命名空间 "<namespace>" 中的 Loki 在 ingestion 过程中丢弃 "<tenant>" 租户中的示例。因为 "<reason>" 的速率为每秒 <value> 样本,所以会丢弃样本。

Loki 在 ingestion 过程中丢弃示例,因为它们无法验证。

warning

LokistackSchemaUpgradesRequired

LokiStack "{{ $labels.stack_name }}" in namespace "<namespace>" 使用不包含最新的 schema 版本的存储 schema 配置。建议您更新 schema 配置,将 schema 版本更新至最新的

一个或多个部署的 LokiStacks 包含过时的存储模式配置。

warning

第 2 章 自定义日志记录警报

您可以配置 LokiStack 部署,以生成自定义的警报和记录的指标。如果要使用自定义 警报和记录规则,您必须启用 LokiStack 规则器组件。

LokiStack 基于日志的警报和记录的指标通过向 ruler 组件提供 LogQL (Grafana 文档)表达式来触发。

要提供这些表达式,您必须创建一个包含 警报规则的 AlertingRule 自定义资源(CR),或包含与 Prometheus 兼容的 记录规则RecordingRule CR (Prometheus 文档)。

管理员可以为 application, audit, 或 infrastructure 租户配置基于日志的警报或记录指标数据。没有管理员权限的用户可为他们有权访问的应用程序租户配置基于日志的警报或记录指标。

应用程序、审计和基础架构警报默认发送到 openshift-monitoring 命名空间中的 OpenShift Container Platform 监控堆栈 Alertmanager,除非您禁用了本地 Alertmanager 实例。如果启用了用于监控 openshift-user-workload-monitoring 命名空间中的用户定义的项目的 Alertmanager,应用程序警报默认发送到此命名空间中的 Alertmanager。

2.1. 配置规则器

启用 LokiStack 规则器组件时,用户可以定义触发日志记录警报或记录指标的 LogQL (Grafana 文档)表达式组。

管理员可以通过修改 LokiStack 自定义资源(CR) 来启用规则器。

先决条件

  • 已安装 Red Hat OpenShift Logging Operator 和 Loki Operator。
  • 您已创建了 LokiStack CR。
  • 有管理员权限。

流程

  • 通过确保 LokiStack CR 具有以下 spec 配置来启用规则器:

    apiVersion: loki.grafana.com/v1
    kind: LokiStack
    metadata:
      name: <name>
      namespace: <namespace>
    spec:
    # ...
      rules:
        enabled: true 
    1
    
        selector: 
    2
    
          matchLabels:
            <label_name>: "true" 
    3
    
        namespaceSelector: 
    4
    
          matchLabels:
            <label_name>: "true" 
    5
    Copy to Clipboard Toggle word wrap
    1
    在集群中启用 Loki 警报和记录规则。
    2
    指定警报和记录资源的选择器。
    3
    添加可添加到要启用日志记录警报和指标的命名空间的自定义标签。
    4
    指定为 Loki Operator 定义警报和记录规则的命名空间。如果未定义,则只使用与 LokiStack 相同的命名空间中定义的规则。
    5
    添加可添加到要启用日志记录警报和指标的命名空间的自定义标签。

2.2. 授权 LokiStack 规则 RBAC 权限

管理员可以允许用户通过将集群角色绑定到 username 来创建和管理自己的警报和记录规则。集群角色定义为 ClusterRole 对象,其中包含用户所需的基于角色的访问控制(RBAC)权限。

LokiStack 有以下用于警报和记录规则的集群角色:

Expand
运行名称描述

alertingrules.loki.grafana.com-v1-admin

具有此角色的用户具有管理级别访问权限来管理警报规则。此集群角色授予在 loki.grafana.com/v1 API 组中创建、读取、更新、删除、列出和监视 AlertingRule 资源的权限。

alertingrules.loki.grafana.com-v1-crdview

具有此角色的用户可以查看与 loki.grafana.com/v1 API 组中的 AlertingRule 资源相关的自定义资源定义(CRD)的定义,但没有修改或管理这些资源的权限。

alertingrules.loki.grafana.com-v1-edit

具有此角色的用户有权创建、更新和删除 AlertingRule 资源。

alertingrules.loki.grafana.com-v1-view

具有此角色的用户可以读取 loki.grafana.com/v1 API 组中的 AlertingRule 资源。它们可以检查现有警报规则的配置、标签和注解,但不能对它们进行任何修改。

recordingrules.loki.grafana.com-v1-admin

具有此角色的用户具有管理记录规则的管理级别访问权限。此集群角色授予在 loki.grafana.com/v1 API 组中创建、读取、更新、删除、列出和监视 RecordingRule 资源的权限。

recordingrules.loki.grafana.com-v1-crdview

具有此角色的用户可以查看与 loki.grafana.com/v1 API 组中的 RecordingRule 资源相关的自定义资源定义(CRD)的定义,但没有修改或管理这些资源的权限。

recordingrules.loki.grafana.com-v1-edit

具有此角色的用户有权创建、更新和删除 RecordingRule 资源。

recordingrules.loki.grafana.com-v1-view

具有此角色的用户可以读取 loki.grafana.com/v1 API 组中的 RecordingRule 资源。它们可以检查现有警报规则的配置、标签和注解,但不能对它们进行任何修改。

2.2.1. 例子

要为用户应用集群角色,您必须将现有集群角色绑定到特定用户名。

集群角色可以是集群或命名空间范围,具体取决于您使用的角色绑定。使用 RoleBinding 对象时,如使用 oc adm policy add-role-to-user 命令时,集群角色仅适用于指定的命名空间。当使用 ClusterRoleBinding 对象时,如使用 oc adm policy add-cluster-role-to-user 命令时,集群角色会应用到集群中的所有命名空间。

以下示例命令为指定用户在集群中的特定命名空间中创建、读取、更新和删除(CRUD)权限:

特定命名空间中警报规则 CRUD 权限的集群角色绑定命令示例

$ oc adm policy add-role-to-user alertingrules.loki.grafana.com-v1-admin -n <namespace> <username>
Copy to Clipboard Toggle word wrap

以下命令为所有命名空间中的警报规则授予指定用户管理员权限:

管理员权限的集群角色绑定命令示例

$ oc adm policy add-cluster-role-to-user alertingrules.loki.grafana.com-v1-admin <username>
Copy to Clipboard Toggle word wrap

2.3. 使用 Loki 创建基于日志的警报规则

AlertingRule CR 包含一组规格和 webhook 验证定义,用于声明单个 LokiStack 实例的警报规则组。另外,webhook 验证定义支持规则验证条件:

  • 如果 AlertingRule CR 包含无效的 interval 周期,则它是一个无效的警报规则
  • 如果 AlertingRule CR 包含无效的 for 周期,则它是一个无效的警报规则
  • 如果 AlertingRule CR 包含无效的 LogQL expr,则它是一个无效的警报规则。
  • 如果 AlertingRule CR 包含两个同名的组,则它是一个无效的警报规则。
  • 如果以上都不适用,则警报规则被视为有效。
Expand
租户类型AlertingRule CR 的有效命名空间

audit

openshift-logging

infrastructure

OpenShiftDebug, kube channel, default

application

所有其他命名空间。

先决条件

  • Red Hat OpenShift Logging Operator 5.7 及更新的版本
  • OpenShift Container Platform 4.13 及更新的版本

流程

  1. 创建 AlertingRule 自定义资源 (CR):

    基础架构 AlertingRule CR 示例

      apiVersion: loki.grafana.com/v1
      kind: AlertingRule
      metadata:
        name: loki-operator-alerts
        namespace: openshift-operators-redhat 
    1
    
        labels: 
    2
    
          openshift.io/cluster-monitoring: "true"
      spec:
        tenantID: infrastructure 
    3
    
        groups:
          - name: LokiOperatorHighReconciliationError
            rules:
              - alert: HighPercentageError
                expr: | 
    4
    
                  sum(rate({kubernetes_namespace_name="openshift-operators-redhat", kubernetes_pod_name=~"loki-operator-controller-manager.*"} |= "error" [1m])) by (job)
                    /
                  sum(rate({kubernetes_namespace_name="openshift-operators-redhat", kubernetes_pod_name=~"loki-operator-controller-manager.*"}[1m])) by (job)
                    > 0.01
                for: 10s
                labels:
                  severity: critical 
    5
    
                annotations:
                  summary: High Loki Operator Reconciliation Errors 
    6
    
                  description: High Loki Operator Reconciliation Errors 
    7
    Copy to Clipboard Toggle word wrap

    1
    创建此 AlertingRule CR 的命名空间必须具有与 LokiStack spec.rules.namespaceSelector 定义匹配的标签。
    2
    labels 块必须与 LokiStack spec.rules.selector 定义匹配。
    3
    基础架构 租户的 AlertingRule CR 只在 openshift fluentd、kube channeldefault 命名空间中被支持。
    4
    kubernetes_namespace_name: 的值必须与 metadata.namespace 的值匹配。
    5
    此必需字段的值必须是 criticalwarninginfo
    6
    这个字段是必须的。
    7
    这个字段是必须的。

    应用程序 AlertingRule CR 示例

      apiVersion: loki.grafana.com/v1
      kind: AlertingRule
      metadata:
        name: app-user-workload
        namespace: app-ns 
    1
    
        labels: 
    2
    
          openshift.io/cluster-monitoring: "true"
      spec:
        tenantID: application
        groups:
          - name: AppUserWorkloadHighError
            rules:
              - alert:
                expr: | 
    3
    
                  sum(rate({kubernetes_namespace_name="app-ns", kubernetes_pod_name=~"podName.*"} |= "error" [1m])) by (job)
                for: 10s
                labels:
                  severity: critical 
    4
    
                annotations:
                  summary: This is an example summary. 
    5
    
                  description: This is an example description. 
    6
    Copy to Clipboard Toggle word wrap

    1
    创建此 AlertingRule CR 的命名空间必须具有与 LokiStack spec.rules.namespaceSelector 定义匹配的标签。
    2
    labels 块必须与 LokiStack spec.rules.selector 定义匹配。
    3
    kubernetes_namespace_name: 的值必须与 metadata.namespace 的值匹配。
    4
    此必需字段的值必须是 criticalwarninginfo
    5
    此必需字段的值是规则的摘要。
    6
    此必填字段的值是规则的详细描述。
  2. 应用 AlertingRule CR:

    $ oc apply -f <filename>.yaml
    Copy to Clipboard Toggle word wrap

法律通告

Copyright © 2025 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2025 Red Hat