Integrate Grafana with Dragonfly operator
In this guide, we are going to see how we can setup Grafana dashboard to monitor Dragonfly pods in kubernetes cluster.
Prerequisites
- A kubernetes cluster with Dragonfly installed
- Prometheus setup in the cluster. See Prometheus integration guide
- You have Helm installed.
If you already have Grafana instance in your cluster, use grafana-dashboard.json to import the dashboard.
Install Grafana helm chart
We’ll be using grafana helm chart to setup Grafana. So make sure you have Helm installed.
helm repo add grafana https://grafana.github.io/helm-chartshelm install grafana-ui grafana/grafana
Once you run the command, grafana will create all the necessary resources to setup grafana. Run the below command to check if all resources are created successfully.
$ kubectl get allNAME READY STATUS RESTARTS AGEpod/dragonfly-sample-0 1/1 Running 1 (171m ago) 23hpod/dragonfly-sample-1 1/1 Running 1 (171m ago) 23hpod/grafana-ui-785f79fb65-rmk52 1/1 Running 1 (171m ago) 23hpod/prometheus-operator-744c6bb8f9-vnxw4 1/1 Running 10 (170m ago) 8dpod/prometheus-prometheus-0 2/2 Running 0 167mNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEservice/dragonfly-sample ClusterIP 10.96.2.149 <none> 6379/TCP 23hservice/grafana-ui ClusterIP 10.96.146.235 <none> 80/TCP 23hservice/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 33dservice/prometheus-operated ClusterIP None <none> 9090/TCP 167mservice/prometheus-operator ClusterIP None <none> 8080/TCP 8dNAME READY UP-TO-DATE AVAILABLE AGEdeployment.apps/grafana-ui 1/1 1 1 23hdeployment.apps/prometheus-operator 1/1 1 1 8dNAME DESIRED CURRENT READY AGEreplicaset.apps/grafana-ui-785f79fb65 1 1 1 23hreplicaset.apps/prometheus-operator-744c6bb8f9 1 1 1 8dNAME READY AGEstatefulset.apps/dragonfly-sample 2/2 23hstatefulset.apps/prometheus-prometheus 1/1 167m
Create Prometheus Service
Create a Prometheus Service to let Grafana access prometheus through it. If you already have a Prometheus Service object, move to the next step.
kubectl apply -f https://github.com/dragonflydb/dragonfly-operator/blob/main/monitoring/prometheus-service.yaml
Note that it is required to use prometheus: prometheus label as selector (if no label is given to the existing Prometheus object). The prometheus operator exposes a port named web, so you can use this port as targetPort in the service.
Create Grafana dashboard
The helm chart also creates a grafana-ui service which you can use to port-forward the grafana port.
kubectl port-forward services/grafana-ui 3000:80
Now go to localhost:3000. You will see a grafana dashboard running in the localhost. add a Prometheus data source. Use http://prometheus-svc:9090 as the datasource url. After that, import grafana-dashboard.json to the dashboard.