[英]How to scrape Jenkins metrics using Prometheus Operator
我正在使用 Kube-prometheus 和 Prometheus-Operator 來監控我的 K8s 集群。 我已經在我的集群上部署了 Jenkins,並想開始使用 ServiceMonitor 在這里獲取指標。
我已經安裝了 Prometheus 插件,它使用/prometheus
或/metrics/API_KEY/metrics
公開/metrics/API_KEY/metrics
,如果我創建一個新的靜態作業,這可以正常工作。 但是,如果我想使用 ServiceMonitor,它不起作用。
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
k8s-app: jenkins
name: jenkins
namespace: monitoring
spec:
endpoints:
- interval: 30s
port: http
path: /metrics/y1H6G16T-DhqpHdW9XwHWnP9FWAXMMfy4XnXVnyoIOEV3-gPJZKN284OFUcVkPxL/metrics
selector:
matchLabels:
jenkins: main
我不知道 ServiceMonitor,但我使用 Jenkins 服務上的注釋監控我的 Jenkins 實例沒有任何問題:
prometheus.io/scrape: "true"
prometheus.io/port: "8080"
prometheus.io/path: "/prometheus"
我正在使用 kube-prometheus-stack v12.8.0(以前稱為 prometheus-operator helm chart)。
要使 prometheus-operator 檢測外部 serviceMonitors(如 Jenkins 提供的那個),您必須配置兩件事:
將其配置為掃描其他命名空間:
serviceMonitorNamespaceSelector matchLabels: prometheus: please-scan-this-namespace-too
注意:或者,您可以將其保留為 {},以便掃描所有命名空間
將其配置為還選擇在這些其他命名空間中檢測到的 serviceMonitors:
serviceMonitorSelector: matchLabels: release: prometheus-operator
注意:盡管文檔指出如果您將 serviceMonitorSelector 保留為 {},它將選擇所有 serviceMonitor,但它似乎不起作用。
最后,您仍然需要將這些標簽添加到您希望普羅米修斯采用的 1) 命名空間和 2) serviceMonitor。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.