This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.2.5. 设置指标集合
要使用服务公开的指标,您需要将 OpenShift Monitoring 配置为从 /metrics 端点中提取指标。您可以使用一个 ServiceMonitor 自定义资源定义(CRD)应该如何监控服务,或使用一个 PodMonitor CRD 指定应该如何监控 pod。前者需要 Service 对象,而后者则不需要,允许 Prometheus 直接从 Pod 公开的指标端点中提取指标。
此流程演示了如何为服务创建 ServiceMonitor 资源。
先决条件
-
以集群管理员或具有
monitor-crd-edit角色的用户身份登录。
流程
-
为
ServiceMonitor资源配置创建一个 YAML 文件。在本例中,该文件名为example-app-service-monitor.yaml。 使用用于创建
ServiceMonitor资源的配置填充该文件:Copy to Clipboard Copied! Toggle word wrap Toggle overflow 此配置可使 OpenShift Monitoring 提取在“部署示例服务”中部署的示例服务所公开的指标,该服务包括单个
version指标。将配置文件应用到集群:
oc apply -f example-app-service-monitor.yaml
$ oc apply -f example-app-service-monitor.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow 部署
ServiceMonitor资源需要一些时间。您可以检查
ServiceMonitor资源是否正在运行:oc -n ns1 get servicemonitor
$ oc -n ns1 get servicemonitorCopy to Clipboard Copied! Toggle word wrap Toggle overflow 输出示例
NAME AGE prometheus-example-monitor 81m
NAME AGE prometheus-example-monitor 81mCopy to Clipboard Copied! Toggle word wrap Toggle overflow
其他资源
有关 ServiceMonitor 和 PodMonitor 资源的更多信息,请参阅 Prometheus Operator API 文档。