访问指标
Harbor 公开了一些关键指标,运维人员和管理员可以使用这些指标来监控 Harbor 实例的实时运行状况。可观测性是在生产环境中运行服务的关键特性,使用这些数据,您可以识别异常状态,并在发生错误时做出明智的决策来修复问题。Harbor 使用 Prometheus 数据模型 公开指标,因此您可以轻松地开始使用 Prometheus 抓取 Harbor 实例的指标。
在 Harbor v2.2 及更高版本中,您可以在 Harbor 配置文件 中启用指标。Harbor 指标可通过 <harbor_instance>:<metrics_port>/<metrics_path>
访问,具体取决于您配置的值。
Harbor 指标显示与以下内容相关的数据
- 来自 GO 库 的运行时信息
- 关于 core 中所有 API 请求的性能指标
- core 中正在处理的请求数
- 由 Distribution/Distribution 本身提供的指标
- Harbor 数据库中已存在的一些与业务逻辑相关的数据
指标由多个 Harbor 组件公开:exporter
、core
、jobservice
和 registry
。除了运行时和性能数据外,这些组件还公开 Harbor 特定的指标。以下部分列出了可用的 Harbor 指标。
Harbor Exporter 指标
exporter
组件指标与您的 Harbor 实例配置相关,并从 Harbor 数据库收集一些数据。指标可通过 <harbor_instance>:<metrics_port>/<metrics_path>
访问。
名称 | 描述 | 标签 (值) | 指标类型 |
---|---|---|---|
harbor_project_total |
公有和私有项目的总数 | public (true ,false ) |
gauge |
harbor_project_repo_total |
项目中仓库的总数 | public (true ,false ), project_name |
gauge |
harbor_project_member_total |
项目中成员的总数 | project_name | gauge |
harbor_project_quota_usage_byte |
项目已使用的资源总量 | project_name | gauge |
harbor_project_quota_byte |
项目中设置的配额 | project_name | gauge |
harbor_artifact_pulled |
项目中拉取的镜像数量 | project_name | gauge |
harbor_project_artifact_total |
项目中制品类型的总数 | artifact_type , project_name, public (true ,false ) |
gauge |
harbor_health |
Harbor 的当前状态 | gauge | |
harbor_system_info |
关于您的 Harbor 实例的信息 | auth_mode (db_auth , ldap_auth , uaa_auth , http_auth , oidc_auth ), harbor_version, self_registration(true ,false ) |
gauge |
harbor_up |
Harbor 组件的运行状态 | component (chartmuseum , core , database , jobservice , portal , redis , registry , registryctl , trivy ) |
gauge |
harbor_task_queue_size |
队列中每种类型的任务总数 | instance, job, type | gauge |
harbor_task_queue_latency |
队列中每种类型待处理的下一个 Job 的入队时间 | instance, job, type | gauge |
harbor_task_scheduled_total |
计划任务数 | instance, job | gauge |
harbor_task_concurrency |
池中每种类型的并发任务总数 | instance, job, pool, type | gauge |
Harbor Core 指标
以下是从 Harbor core Pod 中拉取的指标,可通过 <harbor_instance>:<metrics_port>/<metrics_path>?comp=core
访问。
名称 | 描述 | 标签 (值) | 指标类型 |
---|---|---|---|
harbor_core_http_inflight_requests |
请求总数 | operation (值来自 Harbor API 中的 operationId 。一些旧端点没有 operationId ,因此标签值为 unknown ) |
gauge |
harbor_core_http_request_duration_seconds |
请求的持续时间 | method (GET , POST , HEAD , PATCH , PUT ), operation (值来自 Harbor API 中的 operationId 。一些旧端点没有 operationId ,因此标签值为 unknown ), quantile |
summary |
harbor_core_http_request_total |
请求总数 | method (GET , POST , HEAD , PATCH , PUT ), operation (值来自 Harbor API 中的 operationId 。一些旧端点没有 operationId ,因此标签值为 unknown ) |
counter |
Registry 指标
以下是从 Distribution/Distribution 中拉取的指标,可通过 <harbor_instance>:<metrics_port>/<metrics_path>?comp=registry
访问。
名称 | 描述 | 标签 (值) | 指标类型 |
---|---|---|---|
registry_http_in_flight_requests |
正在处理的 HTTP 请求 | handler | gauge |
registry_http_request_duration_seconds_bucket registry_http_request_duration_seconds_sum registry_http_request_duration_seconds_count |
HTTP 请求延迟,以秒为单位 | handler, method (GET , POST , HEAD , PATCH , PUT ), le |
histogram |
registry_http_request_size_bytes_bucket registry_http_request_size_bytes_sum registry_http_request_size_bytes_count |
HTTP 请求大小,以字节为单位 | handler, le | histogram |
registry_http_requests_total |
发出的 HTTP 请求总数 | code,handler,method,le | counter |
registry_http_response_size_bytes_bucket registry_http_response_size_bytes_sum registry_http_response_size_bytes_count |
HTTP 响应大小,以字节为单位 | handler,le | histogram |
registry_storage_action_seconds_bucket registry_storage_action_seconds_sum registry_storage_action_seconds_count |
存储操作所花费的秒数 | action,driver,le | histogram |
registry_storage_cache_total |
收到的缓存请求数 | type | gauge |
Harbor Jobservice 指标
以下是从 Harbor Jobservice 中拉取的指标,可通过 <harbor_instance>:<metrics_port>/<metrics_path>?comp=jobservice
访问。
名称 | 描述 | 标签 (值) | 指标类型 |
---|---|---|---|
harbor_jobservice_info |
Jobservice 的信息 | instance, job, node, pool, workers | gauge |
harbor_jobservice_task_total |
每种 Job 类型处理的任务数 | instance, job, status, type | counter |
harbor_jobservice_task_process_time_seconds |
任务处理时间的持续时间 | instance, job, quantile, status, type | summary |
使用 Prometheus 抓取指标
要开始使用 Prometheus 访问 Harbor 实例的指标,请执行以下操作:
-
在
harbor.yml
配置文件 中启用指标公开,并设置要公开指标的端口和路径。另请参阅有关 重新配置 Harbor 实例 的更多信息。 -
设置 Prometheus 服务器,有关安装的更多信息,请参阅 Prometheus 文档。
-
配置 Prometheus 配置文件以抓取在您配置的端口和路径上公开的 Harbor 指标。以下是一个抓取配置示例,有关所有可用的 抓取配置选项,请参阅 Prometheus 文档。
scrape_configs: - job_name: 'harbor-exporter' scrape_interval: 20s static_configs: # Scrape metrics from the Harbor exporter component - targets: ['<harbor_instance>:<metrics_port>'] - job_name: 'harbor-core' scrape_interval: 20s params: # Scrape metrics from the Harbor core component comp: ['core'] static_configs: - targets: ['<harbor_instance>:<metrics_port>'] - job_name: 'harbor-registry' scrape_interval: 20s params: # Scrape metrics from the Harbor registry component comp: ['registry'] static_configs: - targets: ['<harbor_instance>:<metrics_port>'] - job_name: 'harbor-jobservice' scrape_interval: 20s params: # Scrape metrics from the Harbor jobservice component comp: ['jobservice'] static_configs: - targets: ['<harbor_instance>:<metrics_port>']
-
配置 Prometheus 服务器以收集 Harbor 指标后,您可以使用 Grafana 可视化您的数据。Harbor repo 中提供了一个 Grafana 仪表板示例,以帮助您开始可视化 Harbor 指标。
从 Kubernetes 集群
您还可以使用 Prometheus 从部署在 Kubernetes 集群中的 Harbor 实例收集指标。您应该已经 安装了 Prometheus 并设置为从您的集群中拉取指标。
-
在 Prometheus 中为 Harbor 创建 ServiceMonitor。
apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: name: harbor labels: app: harbor spec: selector: matchLabels: app: harbor endpoints: - port: metrics
-
通过更新 harbor-helm
values.yaml
文件并将metrics.enabled
设置为true
,启用 Harbor 以公开指标。您还可以通过更新可用的 harbor-helm chart 指标配置选项 来编辑公开指标的端口和路径。
Prometheus 现在应该显示您的 Harbor 实例的指标。
在本页
贡献