This commit is contained in:
2025-03-30 19:48:23 +02:00
parent 5663e93c2d
commit caff5bf5e4
3 changed files with 59 additions and 2 deletions

View File

@@ -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',
}],
}],
},
},
}