{{- if .Values.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ include "rabbitmq.fullname" . }}
  labels:
    {{- include "rabbitmq.labels" . | nindent 4 }}
    {{- with .Values.serviceMonitor.additionalLabels }}
    {{- toYaml . | nindent 4 }}
    {{- end }}
  {{- with .Values.serviceMonitor.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  endpoints:
    - port: "prometheus"
      path: "/metrics"
      {{- if .Values.serviceMonitor.interval }}
      interval: {{ .Values.serviceMonitor.interval }}
      {{- end }}
      {{- if .Values.serviceMonitor.scrapeTimeout }}
      scrapeTimeout: {{ .Values.serviceMonitor.scrapeTimeout }}
      {{- end }}
      {{- with .Values.serviceMonitor.extraEndpointParameters }}
      {{- toYaml . | nindent 6 }}
      {{- end }}
  {{- with .Values.serviceMonitor.extraParameters }}
  {{- toYaml . | nindent 2 }}
  {{- end }}
  selector:
    matchLabels:
      {{- include "rabbitmq.selectorLabels" . | nindent 6 }}
{{- end }}
