본문 바로가기

Observability/Prometheus

[Prometheus]Add custom grafana template to Prometheus-stack

template location

  • kube-prometheus-stack/templates/grafana/dashboards-1.14/
  • 나의 경우 alertmanager-overview.yaml 파일을 복사해서 사용했다.
cp kube-prometheus-stack/templates/grafana/dashboards-1.14/alertmanager-overview.yaml kube-prometheus-stack/templates/grafana/dashboards-1.14/cloudwatch-exporter.yaml

Export grafana dashboard

Variables에 datasource 추가

Save JSON to file

cloudwatch-exporter.json
0.03MB

Create new template

  • 아래는 복사해온 template에서 dashboard이름을 “alertmanager-overview” → “cloudwatch-exporter” 으로 변경한 것이다.
  • data: 에 위에서 추출한 json 파일의 내용을 입력한다.
{{- /*
Generated from 'cloudwatch-exporter' from <https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/main/manifests/grafana-dashboardDefinitions.yaml>
Do not change in-place! In order to change this file first read following link:
<https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack/hack>
*/ -}}
{{- $kubeTargetVersion := default .Capabilities.KubeVersion.GitVersion .Values.kubeTargetVersionOverride }}
{{- if and (or .Values.grafana.enabled .Values.grafana.forceDeployDashboards) (semverCompare ">=1.14.0-0" $kubeTargetVersion) (semverCompare "<9.9.9-9" $kubeTargetVersion) .Values.grafana.defaultDashboardsEnabled }}
apiVersion: v1
kind: ConfigMap
metadata:
  namespace: {{ template "kube-prometheus-stack-grafana.namespace" . }}
  name: {{ printf "%s-%s" (include "kube-prometheus-stack.fullname" $) "cloudwatch-exporter" | trunc 63 | trimSuffix "-" }}
  annotations:
{{ toYaml .Values.grafana.sidecar.dashboards.annotations | indent 4 }}
  labels:
    {{- if $.Values.grafana.sidecar.dashboards.label }}
    {{ $.Values.grafana.sidecar.dashboards.label }}: {{ ternary $.Values.grafana.sidecar.dashboards.labelValue "1" (not (empty $.Values.grafana.sidecar.dashboards.labelValue)) | quote }}
    {{- end }}
    app: {{ template "kube-prometheus-stack.name" $ }}-grafana
{{ include "kube-prometheus-stack.labels" $ | indent 4 }}
data:
  cloudwatch-exporter.json: |-
    {
		## 중략
    }
{{- end }}

Deploy helm chart

Helm chart 배포 후 grafana에 접속해서 확인해보면 Dashboard Browse에 작성한 템플릿을 확인할 수 있다.