49 lines
1.4 KiB
YAML
49 lines
1.4 KiB
YAML
{{- if .Values.monitoring.enabled }}
|
|
{{- /*
|
|
For every app that declares a container port named "metrics", create:
|
|
- a headless <name>-metrics Service exposing that port
|
|
- a ServiceMonitor (labeled for the Prometheus release) scraping it
|
|
Frontend/redis/nats have no metrics port, so they are skipped automatically.
|
|
*/ -}}
|
|
{{- range $name, $app := .Values.apps }}
|
|
{{- range $app.ports }}
|
|
{{- if eq .name "metrics" }}
|
|
apiVersion: v1
|
|
kind: Service
|
|
metadata:
|
|
name: {{ $name }}-metrics
|
|
namespace: {{ include "planpal.namespace" $ }}
|
|
labels:
|
|
app: {{ $name }}
|
|
planpal-metrics: "true"
|
|
spec:
|
|
clusterIP: None # headless; ServiceMonitor scrapes the pods behind it
|
|
selector: { app: {{ $name }} }
|
|
ports:
|
|
- name: metrics
|
|
port: {{ .containerPort }}
|
|
targetPort: {{ .containerPort }}
|
|
---
|
|
apiVersion: monitoring.coreos.com/v1
|
|
kind: ServiceMonitor
|
|
metadata:
|
|
name: {{ $name }}
|
|
namespace: {{ include "planpal.namespace" $ }}
|
|
labels:
|
|
# Prometheus (kube-prometheus-stack) only discovers ServiceMonitors with this label.
|
|
release: {{ $.Values.monitoring.prometheusRelease }}
|
|
spec:
|
|
namespaceSelector:
|
|
matchNames: [{{ include "planpal.namespace" $ }}]
|
|
selector:
|
|
matchLabels: { app: {{ $name }}, planpal-metrics: "true" }
|
|
endpoints:
|
|
- port: metrics
|
|
interval: {{ $.Values.monitoring.scrapeInterval }}
|
|
path: /metrics
|
|
---
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- end }}
|