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

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.

  1. helm repo add grafana https://grafana.github.io/helm-charts
  2. helm 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.

  1. $ kubectl get all
  2. NAME READY STATUS RESTARTS AGE
  3. pod/dragonfly-sample-0 1/1 Running 1 (171m ago) 23h
  4. pod/dragonfly-sample-1 1/1 Running 1 (171m ago) 23h
  5. pod/grafana-ui-785f79fb65-rmk52 1/1 Running 1 (171m ago) 23h
  6. pod/prometheus-operator-744c6bb8f9-vnxw4 1/1 Running 10 (170m ago) 8d
  7. pod/prometheus-prometheus-0 2/2 Running 0 167m
  8. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
  9. service/dragonfly-sample ClusterIP 10.96.2.149 <none> 6379/TCP 23h
  10. service/grafana-ui ClusterIP 10.96.146.235 <none> 80/TCP 23h
  11. service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 33d
  12. service/prometheus-operated ClusterIP None <none> 9090/TCP 167m
  13. service/prometheus-operator ClusterIP None <none> 8080/TCP 8d
  14. NAME READY UP-TO-DATE AVAILABLE AGE
  15. deployment.apps/grafana-ui 1/1 1 1 23h
  16. deployment.apps/prometheus-operator 1/1 1 1 8d
  17. NAME DESIRED CURRENT READY AGE
  18. replicaset.apps/grafana-ui-785f79fb65 1 1 1 23h
  19. replicaset.apps/prometheus-operator-744c6bb8f9 1 1 1 8d
  20. NAME READY AGE
  21. statefulset.apps/dragonfly-sample 2/2 23h
  22. statefulset.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.

  1. kubectl apply -f https://raw.githubusercontent.com/dragonflydb/dragonfly-operator/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.

  1. 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.