# helm_charts_prometheus-service-monitor.yaml
{{- if and .Values.metrics.enabled .Values.metrics.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ template "mongodb.fullname" . }}
  {{- if .Values.metrics.serviceMonitor.namespace }}
  namespace: {{ .Values.metrics.serviceMonitor.namespace }}
  {{- end }}
  labels:
    app: {{ template "mongodb.name" . }}
    chart: {{ template "mongodb.chart" . }}
    heritage: {{ .Release.Service }}
    release: {{ .Release.Name }}
    {{- if .Values.metrics.serviceMonitor.additionalLabels }}
{{ toYaml .Values.metrics.serviceMonitor.additionalLabels | indent 4 }}
    {{- end }}
spec:
  endpoints:
  - interval: 30s
    port: metrics
    {{- if .Values.metrics.serviceMonitor.relabellings }}
    metricRelabelings:
{{ toYaml .Values.metrics.serviceMonitor.relabellings | indent 4 }}
    {{- end }}
  jobLabel: {{ template "mongodb.fullname" . }}
  namespaceSelector:
    matchNames:
    - "{{ $.Release.Namespace }}"
  selector:
    matchLabels:
      app: {{ template "mongodb.name" . }}
      chart: {{ template "mongodb.chart" . }}
      release: "{{ .Release.Name }}"
      heritage: "{{ .Release.Service }}"
{{- end }}