跳至主要内容

ServiceMonitor 和 PodMonitor 配置

ServiceMonitors 和 PodMonitors 都是偽 CRD,它們對應到 Prometheus 自訂資源的抓取配置。

這些配置物件以宣告方式指定 Prometheus 將從中抓取指標的端點。

ServiceMonitors 比 PodMonitors 更常用,我們建議在大多數使用情況下使用它們。

備註

本章節假設您熟悉監控元件如何協同工作。如需有關 Alertmanager 的更多資訊,請參閱此章節。

ServiceMonitors​

此偽 CRD 對應到 Prometheus 自訂資源配置的一個部分。它以宣告方式指定應如何監控 Kubernetes 服務群組。

建立 ServiceMonitor 時,Prometheus Operator 會更新 Prometheus 抓取配置以包含 ServiceMonitor 配置。然後 Prometheus 開始從 ServiceMonitor 中定義的端點抓取指標。

您叢集中與 ServiceMonitor selector 欄位中的標籤匹配的任何 Services 將根據 ServiceMonitor 上指定的 endpoints 進行監控。如需有關可以指定哪些欄位的更多資訊,請查看 Prometheus Operator 提供的 spec。

如需有關 ServiceMonitors 如何運作的更多資訊,請參閱 Prometheus Operator 文件。

PodMonitors​

此偽 CRD 對應到 Prometheus 自訂資源配置的一個部分。它以宣告方式指定應如何監控 pods 群組。

建立 PodMonitor 時,Prometheus Operator 會更新 Prometheus 抓取配置以包含 PodMonitor 配置。然後 Prometheus 開始從 PodMonitor 中定義的端點抓取指標。

您叢集中與 PodMonitor selector 欄位中的標籤匹配的任何 Pods 將根據 PodMonitor 上指定的 podMetricsEndpoints 進行監控。如需有關可以指定哪些欄位的更多資訊,請查看 Prometheus Operator 提供的 spec。