From caff5bf5e4b0d5b4659f0453fbea8f69b9f07702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beatrice=20Dellac=C3=A0?= Date: Sun, 30 Mar 2025 19:48:23 +0200 Subject: [PATCH] fix prom --- deploy/prometheus/deploy.jsonnet | 42 ++++++++++++++++++- .../manifests/prometheus-prometheus.yaml | 1 - .../manifests/prometheus-self-monitor.yaml | 18 ++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 deploy/prometheus/manifests/prometheus-self-monitor.yaml diff --git a/deploy/prometheus/deploy.jsonnet b/deploy/prometheus/deploy.jsonnet index bb0bf39..4dbce38 100644 --- a/deploy/prometheus/deploy.jsonnet +++ b/deploy/prometheus/deploy.jsonnet @@ -24,7 +24,6 @@ local kp = (import 'kube-prometheus/main.libsonnet') + { }, }, }, - selfScrape: true, }, }, }, @@ -129,3 +128,44 @@ local kp = (import 'kube-prometheus/main.libsonnet') + { { ['prometheus-' + name]: kp.prometheus[name] for name in std.objectFields(kp.prometheus) } + { ['prometheus-adapter-' + name]: kp.prometheusAdapter[name] for name in std.objectFields(kp.prometheusAdapter) } + { [name + '-ingress']: kp.ingress[name] for name in std.objectFields(kp.ingress) } + +/* + Add a ServiceMonitor for Prometheus self-scrape. + The relabeling below forces the job label to be "prometheus", so that querying with: + up{job="prometheus"} + will return Prometheus's own metrics. + + NOTE: Adjust the matchLabels selector if your Prometheus service has different labels. +*/ + +{ 'prometheus-self-monitor': { + apiVersion: 'monitoring.coreos.com/v1', + kind: 'ServiceMonitor', + metadata: { + name: 'prometheus-self-monitor', + namespace: kp.values.common.namespace, + labels: { + release: 'prometheus', + }, + }, + spec: { + selector: { + matchLabels: { + // This selector should match labels on the Prometheus service. + // Here we assume the Prometheus service is labeled with: + // prometheus: "prometheus-k8s" + prometheus: 'prometheus-k8s', + }, + }, + endpoints: [{ + port: 'web', // Must match the name of the port exposed by the Prometheus service + path: '/metrics', + scheme: 'http', // Change to "https" if your Prometheus endpoint requires it + relabelings: [{ + targetLabel: 'job', + replacement: 'prometheus', + }], + }], + }, + }, +} \ No newline at end of file diff --git a/deploy/prometheus/manifests/prometheus-prometheus.yaml b/deploy/prometheus/manifests/prometheus-prometheus.yaml index f07f6ca..e5108c1 100644 --- a/deploy/prometheus/manifests/prometheus-prometheus.yaml +++ b/deploy/prometheus/manifests/prometheus-prometheus.yaml @@ -46,7 +46,6 @@ spec: fsGroup: 2000 runAsNonRoot: true runAsUser: 1000 - selfScrape: true serviceAccountName: prometheus-k8s serviceMonitorNamespaceSelector: {} serviceMonitorSelector: {} diff --git a/deploy/prometheus/manifests/prometheus-self-monitor.yaml b/deploy/prometheus/manifests/prometheus-self-monitor.yaml new file mode 100644 index 0000000..8968917 --- /dev/null +++ b/deploy/prometheus/manifests/prometheus-self-monitor.yaml @@ -0,0 +1,18 @@ +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + labels: + release: prometheus + name: prometheus-self-monitor + namespace: monitoring +spec: + endpoints: + - path: /metrics + port: web + relabelings: + - replacement: prometheus + targetLabel: job + scheme: http + selector: + matchLabels: + prometheus: prometheus-k8s