diff --git a/docs/admin/prometheus.md b/docs/admin/prometheus.md index 76f48e07c4909..e7477bf2ea63d 100644 --- a/docs/admin/prometheus.md +++ b/docs/admin/prometheus.md @@ -10,8 +10,6 @@ Coder server exports metrics via the HTTP endpoint, which can be enabled using e The Prometheus endpoint address is `http://localhost:2112/` by default. You can use either the environment variable `CODER_PROMETHEUS_ADDRESS` or the flag ` --prometheus-address :` to select a different listen address. -__Notice__: Prometheus endpoint is not supported by the official Coder Helm chart yet. - If `coder server --prometheus-enable` is started locally, you can preview the metrics endpoint in your browser or by using curl: http://localhost:2112/. ```shell @@ -22,6 +20,11 @@ coderd_api_active_users_duration_hour 0 ... ``` +### Kubernetes deployment + +The Prometheus endpoint can be enabled in the [Helm chart's](https://github.com/coder/coder/tree/main/helm) `values.yml` by setting the environment variable `CODER_PROMETHEUS_ADDRESS` to `0.0.0.0:2112`. +The environment variable `CODER_PROMETHEUS_ENABLE` will be enabled automatically. + ## Available metrics diff --git a/helm/README.md b/helm/README.md index 95b4ecffe3ed8..53a0d994f0086 100644 --- a/helm/README.md +++ b/helm/README.md @@ -50,6 +50,9 @@ coder: - name: CODER_AUTO_IMPORT_TEMPLATES value: "kubernetes" + # This env enables the Prometheus metrics endpoint. + - name: CODER_PROMETHEUS_ADDRESS + value: "0.0.0.0:2112" tls: secretNames: - my-tls-secret-name diff --git a/helm/templates/coder.yaml b/helm/templates/coder.yaml index 9e3b26e1ac85a..fa737e4ea2ef6 100644 --- a/helm/templates/coder.yaml +++ b/helm/templates/coder.yaml @@ -77,10 +77,23 @@ spec: {{- with .Values.coder.env -}} {{ toYaml . | nindent 12 }} {{- end }} + {{- range .Values.coder.env }} + {{- if eq .name "CODER_PROMETHEUS_ADDRESS" }} + - name: CODER_PROMETHEUS_ENABLE + value: "true" + {{- end }} + {{- end }} ports: - name: {{ include "coder.portName" . | quote }} containerPort: {{ include "coder.port" . }} protocol: TCP + {{- range .Values.coder.env }} + {{- if eq .name "CODER_PROMETHEUS_ADDRESS" }} + - name: "prometheus-http" + containerPort: {{ (splitList ":" .value) | last }} + protocol: TCP + {{- end }} + {{- end }} readinessProbe: httpGet: path: /api/v2/buildinfo diff --git a/helm/values.yaml b/helm/values.yaml index 9142b0a2f7d52..abbb98875be13 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -49,6 +49,7 @@ coder: # - CODER_TLS_ENABLE: set if tls.secretName is not empty. # - CODER_TLS_CERT_FILE: set if tls.secretName is not empty. # - CODER_TLS_KEY_FILE: set if tls.secretName is not empty. + # - CODER_PROMETHEUS_ENABLE: set if CODER_PROMETHEUS_ADDRESS is not empty. env: [] # coder.tls -- The TLS configuration for Coder.