3.6.4.2. 监控 DevWorkspace Operator


您可以配置示例监控堆栈来处理 DevWorkspace Operator 公开的指标。

要使用 Prometheus 来收集、存储和查询 DevWorkspace Operator 的指标:

先决条件

  • devworkspace-controller-metrics 服务在端口 8443 中公开指标。
  • devworkspace-webhookserver 服务在端口 9443 上公开指标。默认情况下,服务在端口 9443 上公开指标。
  • Prometheus 2.26.0 或更高版本正在运行。Prometheus 控制台在端口 9090 上运行,带有对应的 服务和路由 。参阅 Prometheus 的第一个步骤

流程

  1. 创建一个 ClusterRoleBinding,将与 Prometheus 关联的 ServiceAccount 绑定到 devworkspace-controller-metrics-reader ClusterRole

    注意

    如果没有 ClusterRoleBinding,您无法访问 DevWorkspace 指标,因为访问受基于角色的访问控制(RBAC)保护。

    例 3.31. ClusterRole

    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:
      name: devworkspace-controller-metrics-reader
    rules:
    - nonResourceURLs:
      - /metrics
      verbs:
      - get
    Copy to Clipboard Toggle word wrap

    例 3.32. ClusterRoleBinding

    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    metadata:
      name: devworkspace-controller-metrics-binding
    subjects:
      - kind: ServiceAccount
        name: <ServiceAccount_name_associated_with_the_Prometheus_Pod>
        namespace: <Prometheus_namespace>
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: devworkspace-controller-metrics-reader
    Copy to Clipboard Toggle word wrap
  2. 将 Prometheus 配置为从 devworkspace-controller-metrics Service 公开的端口 8443 提取指标,并从 devworkspace-webhookserver 服务公开的端口 9443 中提取指标。

    例 3.33. Prometheus 配置

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: prometheus-config
    data:
      prometheus.yml: |-
          global:
            scrape_interval: 5s 
    1
    
            evaluation_interval: 5s 
    2
    
          scrape_configs: 
    3
    
            - job_name: 'DevWorkspace'
              scheme: https
              authorization:
                type: Bearer
                credentials_file: '/var/run/secrets/kubernetes.io/serviceaccount/token'
              tls_config:
                insecure_skip_verify: true
              static_configs:
                - targets: ['devworkspace-controller-metrics:8443'] 
    4
    
            - job_name: 'DevWorkspace webhooks'
              scheme: https
              authorization:
                type: Bearer
                credentials_file: '/var/run/secrets/kubernetes.io/serviceaccount/token'
              tls_config:
                insecure_skip_verify: true
              static_configs:
                - targets: ['devworkspace-webhookserver:9443'] 
    5
    Copy to Clipboard Toggle word wrap
    1
    提取目标的速度。
    2
    重新检查记录和警报规则的速率。
    3
    Prometheus 监控的资源。在默认配置中,两个作业: DevWorkspaceDevWorkspace Webhook,提取 devworkspace-controller-metricsdevworkspace-webhookserver 服务公开的时间序列数据。
    4
    从端口 8443 中提取指标。
    5
    从端口 9443 中提取指标。

验证步骤

  1. 使用 Prometheus 控制台查看和查询指标:

    • 查看 http:// <prometheus_url> /metrics 中的指标
    • http:// <prometheus_url>/graph 查询指标

      如需更多信息,请参阅 使用表达式浏览器

  2. 通过查看 http:// <prometheus-url> /targets 上的目标端点,验证所有目标是否已启动
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2025 Red Hat