4.5. 访问registry的指标数据(metrics)


OpenShift Container Registry 为 Prometheus metrics 提供了一个端点。Prometheus是一个独立的开源系统监视和警报工具包。指标在 registry 端点的 /extensions/v2/metrics 路径上公开。您可以通过运行包含集群角色的指标查询来访问指标。

流程

  1. 如果还没有一个访问指标的集群角色,创建一个集群角色:

    $ cat <<EOF | oc create -f -
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:
      name: prometheus-scraper
    rules:
    - apiGroups:
      - image.openshift.io
      resources:
      - registry/metrics
      verbs:
      - get
    EOF
    Copy to Clipboard Toggle word wrap
  2. 输入以下命令在用户帐户中添加集群角色:

    $ oc adm policy add-cluster-role-to-user prometheus-scraper <username>
    Copy to Clipboard Toggle word wrap
  3. 对于指标查询,获取用户令牌。

    openshift:
    $ oc whoami -t
    Copy to Clipboard Toggle word wrap
  4. 在节点或 pod 中运行指标查询。以下示例命令和输出演示了此任务。

    $ curl --insecure -s -u <user>:<secret> \ 
    1
    
        https://image-registry.openshift-image-registry.svc:5000/extensions/v2/metrics | grep imageregistry | head -n 20
    Copy to Clipboard Toggle word wrap
    • <user>:<secret &gt ; : <user > 对象可以是任意对象,但 <secret > 标签必须使用用户令牌。

      # HELP imageregistry_build_info A metric with a constant '1' value labeled by major, minor, git commit & git version from which the image registry was built.
      # TYPE imageregistry_build_info gauge
      imageregistry_build_info{gitCommit="9f72191",gitVersion="v3.11.0+9f72191-135-dirty",major="3",minor="11+"} 1
      # HELP imageregistry_digest_cache_requests_total Total number of requests without scope to the digest cache.
      # TYPE imageregistry_digest_cache_requests_total counter
      imageregistry_digest_cache_requests_total{type="Hit"} 5
      imageregistry_digest_cache_requests_total{type="Miss"} 24
      # HELP imageregistry_digest_cache_scoped_requests_total Total number of scoped requests to the digest cache.
      # TYPE imageregistry_digest_cache_scoped_requests_total counter
      imageregistry_digest_cache_scoped_requests_total{type="Hit"} 33
      imageregistry_digest_cache_scoped_requests_total{type="Miss"} 44
      # HELP imageregistry_http_in_flight_requests A gauge of requests currently being served by the registry.
      # TYPE imageregistry_http_in_flight_requests gauge
      imageregistry_http_in_flight_requests 1
      # HELP imageregistry_http_request_duration_seconds A histogram of latencies for requests to the registry.
      # TYPE imageregistry_http_request_duration_seconds summary
      imageregistry_http_request_duration_seconds{method="get",quantile="0.5"} 0.01296087
      imageregistry_http_request_duration_seconds{method="get",quantile="0.9"} 0.014847248
      imageregistry_http_request_duration_seconds{method="get",quantile="0.99"} 0.015981195
      imageregistry_http_request_duration_seconds_sum{method="get"} 12.260727916000022
      Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2025 Red Hat