本文介绍如何实现集群内ServiceMonitor和PodMonitor的同步。
前提条件
- 您的Prometheus Helm版本已升级至v1.1.5或以上。升级Helm版本的具体操作,请参见升级组件版本。
- (可选)如果您需要让通过集群命令创建的ServiceMonitor或PodMonitor能够被可观测监控 Prometheus 版发现到,那么您需要在创建的时候添加如下示例的annotation。
annotations: arms.prometheus.io/discovery: 'true' // 其中'true'被发现,false不会被发现
背景信息
阿里云可观测监控 Prometheus 版会默认发现集群内的ServiceMonitor以及PodMonitor并采集数据。如果您的集群通过命令行已创建了ServiceMonitor或PodMonitor,或者您的集群已安装了开源Prometheus自带的ServiceMonitor或PodMonitor,那么这些采集任务可能会和阿里云可观测监控 Prometheus 版默认的采集任务重复,导致不必要的资源消耗,同时会产生相应的费用。
为了避免产生不必要的成本以及资源的消耗,阿里云可观测监控 Prometheus 版提供了一键同步集群内ServiceMonitor和PodMonitor的开关。您可根据需求决定是否进行ServiceMonitor或PodMonitor同步。打开同步开关之后,您在集群创建的ServiceMonitor或PodMonitor将会被阿里云可观测监控 Prometheus 版发现;否则,阿里云可观测监控 Prometheus 版仅会发现通过可观测监控 Prometheus 版控制台创建的ServiceMonitor或PodMonitor。
操作步骤
同步集群内ServiceMonitor和PodMonitor的操作步骤类似,这里以同步集群内的ServiceMonitor为例为您介绍具体的操作。
- 登录Prometheus控制台。
- 在左侧导航栏单击监控列表,进入可观测监控 Prometheus 版的实例列表页面。
- 单击目标Prometheus实例名称。
- 在左侧导航栏,单击服务发现。
- 在服务发现页面单击配置页签,然后单击ServiceMonitor页签,打开自动同步集群内ServiceMonitor开关即可。说明
- 若您需要同步集群内的PodMonitor,此时只需在配置页面单击PodMonitor页签并打开自动同步集群内PodMonitor开关即可。
- 您在编辑ServiceMonitor或PodMonitor时,请勿删除annotations字段信息,否则会影响到您数据的采集。