3.6.4.3.2. 使用 Prometheus 收集 OpenShift Dev Spaces 服务器指标

使用 Prometheus 为 OpenShift Dev Spaces 服务器收集、存储和查询 JVM 指标:

先决条件

流程

  1. 将 Prometheus 配置为从端口 8087 中提取指标。

    注意

    示例监控堆栈 已经使用空配置创建 prometheus-config ConfigMap。要提供 Prometheus 配置详情,请编辑 ConfigMap 的 data 字段。

    例 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: 'Che Server'
              static_configs:
                - targets: ['che-host.<OpenShift Dev Spaces_project>:8087']  4
    1
    提取目标的速度。
    2
    重新检查记录和警报规则的速率。
    3
    Prometheus 监控的资源。在默认配置中,一个作业 Che Server 提取由 OpenShift Dev Spaces 服务器公开的时间序列数据。
    4
    指标的修整目标(来自端口 8087 )。将 <OpenShift Dev Spaces_project& gt; 替换为 OpenShift Dev Spaces 项目。默认的 OpenShift Dev Spaces 项目为 openshift-devspaces
  2. 缩减 Prometheus Deployment,并最多从上一步中读取更新的 ConfigMap。

    $ oc scale --replicas=0 deployment/prometheus -n monitoring && oc scale --replicas=1 deployment/prometheus -n monitoring

验证

  1. 使用端口转发在本地访问 Prometheus 服务:

    $ oc port-forward svc/prometheus 9090:9090 -n monitoring
  2. 通过查看 localhost:9090/targets 上的 目标 端点,验证所有目标是否已启动。
  3. 使用 Prometheus 控制台查看和查询指标:

    • 查看 localhost:9090/metrics 中的指标。
    • localhost:9090/graph 查询指标。

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