监控和日志记录


Red Hat Developer Hub 1.5

使用 Red Hat Developer Hub 中的监控和日志记录工具跟踪性能并捕获见解

Red Hat Customer Content Services

摘要

作为 Red Hat Developer Hub Operations 或 Project Manager,您可以使用 Red Hat Developer Hub 的监控和日志记录工具监控性能并收集见解。

第 1 章 在 OpenShift Container Platform 上为 Red Hat Developer Hub 启用可观察性

在 OpenShift Container Platform 中,指标通过 /metrics 规范名称下的 HTTP 服务端点公开。您可以创建一个 ServiceMonitor 自定义资源(CR),从用户定义的项目中的服务端点提取指标。

1.1. 在 OpenShift Container Platform 集群上安装 Red Hat Developer Hub Operator 中启用指标监控

您可以从 OpenShift Container Platform Web 控制台的 Developer 视角为 Operator 安装的 Red Hat Developer Hub 实例启用和查看指标。

先决条件

  • 您的 OpenShift Container Platform 集群启用了 用户定义的项目的监控
  • 已使用 Red Hat Developer Hub Operator 在 OpenShift Container Platform 上安装 Red Hat Developer Hub。
  • 已安装 OpenShift CLI(oc)。

流程

目前,Red Hat Developer Hub Operator 默认不支持创建 ServiceMonitor 自定义资源(CR)。您必须执行以下步骤来创建 ServiceMonitor CR,以从端点提取指标。

  1. ServiceMonitor CR 创建为 YAML 文件:

    apiVersion: monitoring.coreos.com/v1
    kind: ServiceMonitor
    metadata:
      name: <developer_hub_service_monitor_name> 
    1
    
      namespace: <rhdh_namespace_name> 
    2
    
      labels:
        app.kubernetes.io/instance: <rhdh_cr_name> 
    3
    
        app.kubernetes.io/name: Backstage
    spec:
      namespaceSelector:
        matchNames:
          - <rhdh_namespace_name> 
    4
    
      selector:
        matchLabels:
          app.kubernetes.io/instance: <deployment_name> 
    5
    
          app.kubernetes.io/name: <rhdh_cr_type> 
    6
    
      endpoints:
      - port: http-metrics
        path: '/metrics'
    Copy to Clipboard
    1
    ServiceMonitor 资源的名称,如 developer_hub_service_monitor
    2
    ServiceMonitor 将处于活动状态的命名空间,如 my-rhdh-project
    3
    标识 ServiceMonitor CR 实例的标签名称,如 my-rhdh-custom-resource
    4
    安装 RHDH 实例的命名空间,如 my-rhdh-project
    5
    您的 RHDH 部署的名称,如 developer-hub
    6
    RHDH 应用程序的名称,例如 backstage
    注意

    spec.selector.matchLabels 配置必须与 RHDH 安装的标签匹配。

  2. 运行以下命令来应用 ServiceMonitor CR:

    oc apply -f <filename>
    Copy to Clipboard

验证

  1. 从 OpenShift Container Platform web 控制台中的 Developer 视角,选择 Observe 视图。
  2. Metrics 选项卡查看 Red Hat Developer Hub pod 的指标。
  3. 从 OpenShift Container Platform Web 控制台中的 Developer 视角,点 Project > Services,再验证 backstage-developer-hub 的标签。

1.2. 在 OpenShift Container Platform 集群的 Helm Chart 安装中启用指标监控

您可以从 OpenShift Container Platform Web 控制台的 Developer 视角为 Red Hat Developer Hub Helm 部署启用和查看指标。

先决条件

  • 您的 OpenShift Container Platform 集群启用了 用户定义的项目的监控
  • 已使用 Helm Chart 在 OpenShift Container Platform 上安装 Red Hat Developer Hub。

流程

  1. 从 OpenShift Container Platform Web 控制台中的 Developer 视角,选择 Topology 视图。
  2. 点 Red Hat Developer Hub Helm Chart 的 overflow 菜单,然后选择 Upgrade

    Helm 升级
  3. Upgrade Helm Release 页面中,选择 Configure via 中的 YAML view 选项,然后在 YAML 中配置 metrics 部分,如下例所示:

    upstream:
    # ...
      metrics:
        serviceMonitor:
          enabled: true
          path: /metrics
          port: http-metrics
    # ...
    Copy to Clipboard
    升级 helm 指标
  4. 单击 Upgrade

验证

  1. 从 OpenShift Container Platform web 控制台中的 Developer 视角,选择 Observe 视图。
  2. Metrics 选项卡查看 Red Hat Developer Hub pod 的指标。

第 2 章 在 Red Hat Developer Hub 中监控和使用 Amazon Web Services (AWS)进行日志记录

在 Red Hat Developer Hub 中,通过 Amazon Web Services (AWS)集成促进监控和日志记录。使用 Amazon CloudWatch 进行实时监控和 Amazon Prometheus 的功能,您可以确保 AWS 基础架构上托管的 Developer Hub 应用程序的可靠性、可扩展性和合规性。

此集成允许您在红帽生态系统中监督、诊断和重新定义您的应用程序,从而提高了开发和操作过程。

2.1. 使用 Amazon Prometheus 监控

Red Hat Developer Hub 提供与正在运行的应用程序相关的 Prometheus 指标。有关为 EKS 集群启用或部署 Prometheus 的更多信息,请参阅 Amazon 文档中的 Prometheus 指标

要使用 Amazon Prometheus 监控 Developer Hub,您需要为 Prometheus 工作区创建一个 Amazon 受管服务,并配置 Developer Hub Prometheus 指标的 ingestion。如需更多信息,请参阅 Amazon 文档中的创建工作区Ingest Prometheus metrics to the workspace 部分。

将 Prometheus 指标放入创建的工作区后,您可以将指标提取配置为根据特定 pod 注解从 pod 中提取数据。

2.1.1. 为监控配置注解

您可以在 Helm 部署和 Operator 支持的部署中配置用于监控的注解。

Helm 部署

要注解 backstage pod 进行监控,请按如下所示更新您的 values.yaml 文件:

upstream:
  backstage:
    # --- TRUNCATED ---
    podAnnotations:
      prometheus.io/scrape: 'true'
      prometheus.io/path: '/metrics'
      prometheus.io/port: '9464'
      prometheus.io/scheme: 'http'
Copy to Clipboard
Operator 支持的部署

流程

  1. 作为 Operator 的管理员,编辑默认配置以添加 Prometheus 注解,如下所示:

    # Update OPERATOR_NS accordingly
    OPERATOR_NS=rhdh-operator
    kubectl edit configmap backstage-default-config -n "${OPERATOR_NS}"
    Copy to Clipboard
  2. 在 ConfigMap 中找到 deployment.yaml 键,并将注解添加到 spec.template.metadata.annotations 字段中,如下所示:

    deployment.yaml: |-
      apiVersion: apps/v1
      kind: Deployment
      # --- truncated ---
      spec:
        template:
          # --- truncated ---
          metadata:
            labels:
             rhdh.redhat.com/app:  # placeholder for 'backstage-<cr-name>'
            # --- truncated ---
            annotations:
              prometheus.io/scrape: 'true'
              prometheus.io/path: '/metrics'
              prometheus.io/port: '9464'
              prometheus.io/scheme: 'http'
      # --- truncated ---
    Copy to Clipboard
  3. 保存您的更改。

验证

验证提取是否正常工作:

  1. 使用 kubectl 端口将 Prometheus 控制台转发到本地机器,如下所示:

    kubectl --namespace=prometheus port-forward deploy/prometheus-server 9090
    Copy to Clipboard
  2. 打开 Web 浏览器并导航到 http://localhost:9090 以访问 Prometheus 控制台。
  3. 监控相关指标,如 process_cpu_user_seconds_total

2.2. 使用 Amazon CloudWatch 日志进行日志记录

Red Hat Developer Hub 中的日志记录依赖于 winston 库。默认情况下,debug 级别的日志不会被记录。要激活调试日志,您必须在 Red Hat Developer Hub 实例中将环境变量 LOG_LEVEL 设置为 debug。

2.2.1. 配置应用程序日志级别

您可以在 Helm 部署和 Operator 支持的部署中配置应用程序日志级别。

Helm 部署

要更新日志记录级别,请将环境变量 LOG_LEVEL 添加到 Helm Chart 的 values.yaml 文件中:

upstream:
  backstage:
    # --- Truncated ---
    extraEnvVars:
      - name: LOG_LEVEL
        value: debug
Copy to Clipboard
Operator 支持的部署

您可以通过在自定义资源中包含环境变量 LOG_LEVEL 来修改日志记录级别,如下所示:

spec:
  # Other fields omitted
  application:
    extraEnvs:
      envs:
        - name: LOG_LEVEL
          value: debug
Copy to Clipboard

2.2.2. 从 Amazon CloudWatch 检索日志

CloudWatch Container Insights 用于捕获 Amazon EKS 的日志和指标。如需更多信息,请参阅 Amazon EKS 文档的日志记录。

要捕获日志和指标,请 在集群中安装 Amazon CloudWatch Observability EKS 附加组件。在 Container Insights 设置后,您可以使用 Logs Insights 或 Live Tail 视图访问容器日志。

Cloudwatch 命名所有容器日志的日志组,其方式如下:

/aws/containerinsights/<ClusterName>/application

以下是从 Developer Hub 实例检索日志的查询示例:

fields @timestamp, @message, kubernetes.container_name
| filter kubernetes.container_name in ["install-dynamic-plugins", "backstage-backend"]
Copy to Clipboard

第 3 章 在 Red Hat Developer Hub 中使用 Azure Kubernetes Services (AKS)监控和日志记录

监控和日志记录是在 Red Hat Developer Hub 中管理和维护 Azure Kubernetes Services (AKS)的完整方面。借助 Managed Prometheus Monitoring 和 Azure Monitor 集成等功能,管理员可以高效地监控资源利用率、诊断问题并确保其容器化工作负载的可靠性。

3.1. 启用 Azure Monitor 指标

要启用受管 Prometheus 监控,请在 az aks createaz aks update 命令中使用 -enable-azure-monitor-metrics 选项,具体取决于您要创建新集群还是更新现有集群,例如:

az aks create/update --resource-group <your-ResourceGroup> --name <your-Cluster> --enable-azure-monitor-metrics
Copy to Clipboard

上一命令安装指标附加组件,它会收集 Prometheus 指标。使用上一命令,您可以通过两个原生 Azure Monitor 指标启用对 Azure 资源的监控。您还可以在 Monitoring → Insights 下查看端口的结果。如需更多信息,请参阅使用 Azure Monitor 监控 Azure 资源

另外,Managed Prometheus 服务和 Azure Monitor 的指标可以通过 Azure Managed Grafana 服务访问。如需更多信息,请参阅链接 Grafana 工作区 部分。

默认情况下,Prometheus 使用最小 ingesting 配置集,它优化了 ingestion 卷,并为提取频率、目标和指标设置默认配置。默认设置可以通过自定义配置进行自定义。Azure 提供了各种方法,包括使用不同的 ConfigMap 来提供提取配置和其他指标附加组件设置。如需有关默认配置的更多信息,请参阅 Azure Monitor 中的默认 Prometheus metrics 配置,以及 Azure Monitor 托管服务中的自定义提取 Prometheus 指标 文档。

3.2. 为监控配置注解

您可以在 Helm 部署和 Operator 支持的部署中配置用于监控 Red Hat Developer Hub 特定指标的注解。

Helm 部署

要注解 backstage pod 进行监控,请按如下所示更新您的 values.yaml 文件:

upstream:
  backstage:
    # --- TRUNCATED ---
    podAnnotations:
      prometheus.io/scrape: 'true'
      prometheus.io/path: '/metrics'
      prometheus.io/port: '9464'
      prometheus.io/scheme: 'http'
Copy to Clipboard
Operator 支持的部署

流程

  1. 作为 Operator 的管理员,编辑默认配置以添加 Prometheus 注解,如下所示:

    # Update OPERATOR_NS accordingly
    OPERATOR_NS=rhdh-operator
    kubectl edit configmap backstage-default-config -n "${OPERATOR_NS}"
    Copy to Clipboard
  2. 在 ConfigMap 中找到 deployment.yaml 键,并将注解添加到 spec.template.metadata.annotations 字段中,如下所示:

    deployment.yaml: |-
      apiVersion: apps/v1
      kind: Deployment
      # --- truncated ---
      spec:
        template:
          # --- truncated ---
          metadata:
            labels:
             rhdh.redhat.com/app:  # placeholder for 'backstage-<cr-name>'
            # --- truncated ---
            annotations:
              prometheus.io/scrape: 'true'
              prometheus.io/path: '/metrics'
              prometheus.io/port: '9464'
              prometheus.io/scheme: 'http'
      # --- truncated ---
    Copy to Clipboard
  3. 保存您的更改。

验证

要验证提取是否正常工作,请导航到对应的 Azure Monitor Workspace,并在 Monitoring → Metrics 下查看指标。

3.3. 使用 Azure Kubernetes Services (AKS)查看日志

您可以访问 Kubernetes 对象生成的实时数据日志,并在 AKS 中收集容器 Insights 中的日志数据。

先决条件

  • 您已在 AKS 上部署了 Developer Hub。

如需更多信息,请参阅在 Microsoft Azure Kubernetes Service 上安装 Red Hat Developer Hub

流程

查看 Developer Hub 实例的实时日志
  1. 进入 Azure Portal。
  2. 搜索资源组 < your-ResourceGroup> 并找到您的 AKS 集群 < your-Cluster>
  3. 从菜单中选择 Kubernetes resources → Workloads
  4. 选择 & lt;your-rhdh-cr>-developer-hub (在 Helm Chart 安装中)或 <your-rhdh-cr>-backstage (在 Operator 支持的安装)部署。
  5. 单击左侧菜单中的 Live Logs
  6. 选择 pod。

    注意

    必须只有一个 pod。

收集并显示实时日志数据。

从容器引擎查看实时日志数据
  1. 进入 Azure Portal。
  2. 搜索资源组 < your-ResourceGroup> 并找到您的 AKS 集群 < your-Cluster>
  3. 从菜单中选择 MonitoringInsights
  4. 转至 容器 选项卡。
  5. 找到 backend-backstage 容器,并点击它查看由 Container Engine 生成的实时日志数据。

法律通告

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