diff --git a/deploy/helm/grafana-operator/README.md b/deploy/helm/grafana-operator/README.md index 144a19385..95e3e19e8 100644 --- a/deploy/helm/grafana-operator/README.md +++ b/deploy/helm/grafana-operator/README.md @@ -59,5 +59,14 @@ It's easier to just manage this configuration outside of the operator. | serviceAccount.annotations | object | `{}` | Annotations to add to the service account | | serviceAccount.create | bool | `true` | Specifies whether a service account should be created | | serviceAccount.name | string | `""` | The name of the service account to use. If not set and create is true, a name is generated using the fullname template | +| serviceMonitor | object | `{"additionalLabels":{},"enabled":false,"interval":"1m","metricRelabelings":[],"relabelings":[],"scrapeTimeout":"10s","targetLabels":[],"telemetryPath":"/metrics"}` | Enable this to use with Prometheus Operator | +| serviceMonitor.additionalLabels | object | `{}` | Set of labels to transfer from the Kubernetes Service onto the target | +| serviceMonitor.enabled | bool | `false` | When set true then use a ServiceMonitor to configure scraping | +| serviceMonitor.interval | string | `"1m"` | Set how frequently Prometheus should scrape | +| serviceMonitor.metricRelabelings | list | `[]` | MetricRelabelConfigs to apply to samples before ingestion | +| serviceMonitor.relabelings | list | `[]` | Set relabel_configs as per https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config | +| serviceMonitor.scrapeTimeout | string | `"10s"` | Set timeout for scrape | +| serviceMonitor.targetLabels | list | `[]` | Set of labels to transfer from the Kubernetes Service onto the target | +| serviceMonitor.telemetryPath | string | `"/metrics"` | Set path to metrics path | | tolerations | list | `[]` | pod tolerations | | watchNamespaces | string | `""` | Sets the WATCH_NAMESPACE environment variable, it defines which namespaces the operator should be listening for. By default it's all namespaces, if you only want to listen for the same namespace as the operator is deployed to look at namespaceScope. | diff --git a/deploy/helm/grafana-operator/templates/servicemonitor.yaml b/deploy/helm/grafana-operator/templates/servicemonitor.yaml new file mode 100644 index 000000000..e423f89ca --- /dev/null +++ b/deploy/helm/grafana-operator/templates/servicemonitor.yaml @@ -0,0 +1,46 @@ +{{- if.Values.serviceMonitor.enabled -}} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ include "grafana-operator.fullname" . }} + namespace: {{ include "grafana-operator.namespace" . }} + labels: + {{- include "grafana-operator.labels" . | nindent 4 }} + {{- with .Values.additionalLabels }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.serviceMonitor.additionalLabels }} + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + jobLabel: {{ .Release.Name }} + namespaceSelector: + matchNames: + - {{ .Release.Namespace }} + selector: + matchLabels: + {{- include "grafana-operator.selectorLabels" . | nindent 6 }} + endpoints: + - port: metrics + path: {{ .Values.serviceMonitor.telemetryPath }} + {{- with .Values.serviceMonitor.interval }} + interval: {{ . }} + {{- end }} + {{- with .Values.serviceMonitor.scrapeTimeout }} + scrapeTimeout: {{ . }} + {{- end }} + {{- if .Values.serviceMonitor.metricRelabelings }} + metricRelabelings: + {{ toYaml .Values.serviceMonitor.metricRelabelings | indent 4 }} + {{- end }} + {{- if .Values.serviceMonitor.relabelings }} + relabelings: + {{ toYaml .Values.serviceMonitor.relabelings | nindent 4 }} + {{- end }} + {{- if .Values.serviceMonitor.targetLabels }} + targetLabels: + {{- range .Values.serviceMonitor.targetLabels }} + - {{ . }} + {{- end }} + {{- end }} +{{- end }} diff --git a/deploy/helm/grafana-operator/values.yaml b/deploy/helm/grafana-operator/values.yaml index d4ff678fc..6bdd428b5 100644 --- a/deploy/helm/grafana-operator/values.yaml +++ b/deploy/helm/grafana-operator/values.yaml @@ -87,3 +87,22 @@ tolerations: [] # -- pod affinity affinity: {} + +# -- Enable this to use with Prometheus Operator +serviceMonitor: + # -- When set true then use a ServiceMonitor to configure scraping + enabled: false + # -- Set of labels to transfer from the Kubernetes Service onto the target + additionalLabels: {} + # -- Set how frequently Prometheus should scrape + interval: 1m + # -- Set timeout for scrape + scrapeTimeout: 10s + # -- Set path to metrics path + telemetryPath: /metrics + # -- Set of labels to transfer from the Kubernetes Service onto the target + targetLabels: [] + # -- MetricRelabelConfigs to apply to samples before ingestion + metricRelabelings: [] + # -- Set relabel_configs as per https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config + relabelings: []