From 628b57038d5692a524519c39b69ed341ab5ea272 Mon Sep 17 00:00:00 2001 From: Rory Z Date: Fri, 27 May 2022 09:19:18 +0800 Subject: [PATCH] feat(helm): add service monitor for prometheus --- deploy/charts/emqx/README.md | 2 ++ deploy/charts/emqx/service-monitor.yaml | 39 ++++++++++++++++++++++++ deploy/charts/emqx/templates/secret.yaml | 19 ++++++++++++ deploy/charts/emqx/values.yaml | 6 ++++ 4 files changed, 66 insertions(+) create mode 100644 deploy/charts/emqx/service-monitor.yaml create mode 100644 deploy/charts/emqx/templates/secret.yaml diff --git a/deploy/charts/emqx/README.md b/deploy/charts/emqx/README.md index 935624769..8461c4ef6 100644 --- a/deploy/charts/emqx/README.md +++ b/deploy/charts/emqx/README.md @@ -88,6 +88,8 @@ Parameter | Description | Default Value `ingress.wss.hosts` | Ingress hosts for EMQX WSS | `wss.emqx.local` `ingress.wss.tls` | Ingress tls for EMQX WSS | `[]` `ingress.wss.annotations` | Ingress annotations for EMQX WSS | `{}` +| `metrics.enable` | If set to true, [prometheus-operator](https://github.com/prometheus-operator/prometheus-operator) needs to be installed, and [emqx_prometheus](https://github.com/emqx/emqx/tree/main-v4.4/apps/emqx_prometheus) needs to enable | false | +| `metrics.type` | Now we only supported "prometheus" | "prometheus" | `extraEnv` | Aditional container env vars | `[]` `extraEnvFrom` | Aditional container env from vars (eg. [config map](https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/), [secrets](https://kubernetes.io/docs/concepts/configuration/secret/) | `[]` `extraArgs` | Additional container executable arguments | `[]` diff --git a/deploy/charts/emqx/service-monitor.yaml b/deploy/charts/emqx/service-monitor.yaml new file mode 100644 index 000000000..9988bcb1f --- /dev/null +++ b/deploy/charts/emqx/service-monitor.yaml @@ -0,0 +1,39 @@ +{{- if and (.Values.metrics.enabled) (eq .Values.metrics.type "prometheus") }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ include "emqx.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: + app.kubernetes.io/name: {{ include "emqx.name" . }} + helm.sh/chart: {{ include "emqx.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + {{- if .Values.service.annotations }} + annotations: + {{ toYaml .Values.service.annotations | indent 4 }} + {{- end }} +spec: + endpoints: + - interval: 10s + port: mgmt + scheme: http + path: /api/v4/emqx_prometheus + params: + type: + - prometheus + basicAuth: + password: + name: {{ include "emqx.fullname" . }}-basic-auth + key: password + username: + name: {{ include "emqx.fullname" . }}-basic-auth + key: username + jobLabel: {{ .Release.Name }}-scraping + namespaceSelector: + matchNames: + - {{ .Release.Namespace }} + selector: + matchLabels: + app.kubernetes.io/name: {{ include "emqx.name" . }} +{{- end }} \ No newline at end of file diff --git a/deploy/charts/emqx/templates/secret.yaml b/deploy/charts/emqx/templates/secret.yaml new file mode 100644 index 000000000..fcc1b2f3d --- /dev/null +++ b/deploy/charts/emqx/templates/secret.yaml @@ -0,0 +1,19 @@ +{{- if .Values.metrics.enabled }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "emqx.fullname" . }}-basic-auth + namespace: {{ .Release.Namespace }} +type: kubernetes.io/basic-auth +stringData: + {{- if not (empty .Values.emqxConfig.EMQX_MANAGEMENT__DEFAULT_APPLICATION__ID) }} + username: admin + {{- else }} + username: {{ .Values.emqxConfig.EMQX_MANAGEMENT__DEFAULT_APPLICATION__ID }} + {{- end }} + {{- if not (empty .Values.emqxConfig.EMQX_MANAGEMENT__DEFAULT_APPLICATION__SECRET) }} + password: public + {{- else }} + password: {{ .Values.emqxConfig.EMQX_MANAGEMENT__DEFAULT_APPLICATION__SECRET}} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/deploy/charts/emqx/values.yaml b/deploy/charts/emqx/values.yaml index 0f273671c..f2a51e3e4 100644 --- a/deploy/charts/emqx/values.yaml +++ b/deploy/charts/emqx/values.yaml @@ -70,6 +70,8 @@ initContainers: {} ## EMQX configuration item, see the documentation (https://hub.docker.com/r/emqx/emqx) emqxConfig: + EMQX_MANAGEMENT__DEFAULT_APPLICATION__ID: "admin" + EMQX_MANAGEMENT__DEFAULT_APPLICATION__SECRET: "public" EMQX_CLUSTER__K8S__APISERVER: "https://kubernetes.default.svc:443" ## The address type is used to extract host from k8s service. ## Value: ip | dns | hostname @@ -248,3 +250,7 @@ containerSecurityContext: enabled: true runAsNonRoot: true runAsUser: 1000 + +metrics: + enabled: false + type: prometheus \ No newline at end of file