Visualizing metrics via Grafana

Big picture

Use Grafana dashboard to view Calico component metrics.

Value

Using Grafana can be beneficial by providing a means to visualize metrics through graphs that can help you quickly identify unusual activity. The following image shows some of the graphs and metrics that are available for you to leverage in order to achieve this goal.

Visualizing metrics via Grafana - 图1

Features

This how-to guide uses the following Calico features:

Felix and Typha components configured with Prometheus configuration parameters (for consumption by Prometheus) and Grafana (for graphs and visual dashboards).

Concepts

About Grafana

Grafana is an open source visualization and analytics tool that allows you to query, visualize, alert on, and explore metrics from a variety of data source, including Calico component metrics stored in Prometheus.

About Prometheus

Prometheus is an open source monitoring tool that scrapes metrics from instrumented components and stores them as time series data which can then be visualized using tools such as Grafana.

Before you begin…

In this tutorial we assume you have

  • a running Kubernetes cluster with Calico, calicoctl and kubectl installed
  • completed all steps in the monitor component metrics guide to set up Prometheus to gather Calico component metrics.

How to

This tutorial will go through the necessary steps to create Calico metrics dashboards with Grafana.

Preparing Prometheus

Here you will create a service to make your prometheus visible to Grafana.

  1. kubectl apply -f - <<EOF
  2. apiVersion: v1
  3. kind: Service
  4. metadata:
  5. name: prometheus-dashboard-svc
  6. namespace: calico-monitoring
  7. spec:
  8. selector:
  9. app: prometheus-pod
  10. role: monitoring
  11. ports:
  12. - port: 9090
  13. targetPort: 9090
  14. EOF

Preparing Grafana pod

1. Provisioning datasource

Grafana datasources are storage backends for your time series data. Each data source has a specific Query Editor that is customized for the features and capabilities that the particular data source exposes.

Visualizing metrics via Grafana - 图2note

Guide with greater detail about Grafana datasources can be found at this link.

In this section you will use Grafana provisioning capabilities to create a prometheus datasource.

Visualizing metrics via Grafana - 图3note

Guide with greater detail about provisioning can be found at this link.

Here You setup a datasource and pointing it to the prometheus service in your cluster.

  1. kubectl apply -f - <<EOF
  2. apiVersion: v1
  3. kind: ConfigMap
  4. metadata:
  5. name: grafana-config
  6. namespace: calico-monitoring
  7. data:
  8. prometheus.yaml: |-
  9. {
  10. "apiVersion": 1,
  11. "datasources": [
  12. {
  13. "access":"proxy",
  14. "editable": true,
  15. "name": "calico-demo-prometheus",
  16. "orgId": 1,
  17. "type": "prometheus",
  18. "url": "http://prometheus-dashboard-svc.calico-monitoring.svc:9090",
  19. "version": 1
  20. }
  21. ]
  22. }
  23. EOF

2. Provisioning Calico dashboards

Here you will create a configmap with Felix and Typha dashboards.

  1. kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.24.5/manifests/grafana-dashboards.yaml

3. Creating Grafana pod

In this step you are going to create your Grafana pod using the config file that was created earlier.

Visualizing metrics via Grafana - 图4note

Grafana uses port 3000 by default. A more detailed guide about how to modify this port can be found at this link.

  1. kubectl apply -f - <<EOF
  2. apiVersion: v1
  3. kind: Pod
  4. metadata:
  5. name: grafana-pod
  6. namespace: calico-monitoring
  7. labels:
  8. app: grafana-pod
  9. role: monitoring
  10. spec:
  11. containers:
  12. - name: grafana-pod
  13. image: grafana/grafana:latest
  14. resources:
  15. limits:
  16. memory: "128Mi"
  17. cpu: "500m"
  18. volumeMounts:
  19. - name: grafana-config-volume
  20. mountPath: /etc/grafana/provisioning/datasources
  21. - name: grafana-dashboards-volume
  22. mountPath: /etc/grafana/provisioning/dashboards
  23. - name: grafana-storage-volume
  24. mountPath: /var/lib/grafana
  25. ports:
  26. - containerPort: 3000
  27. volumes:
  28. - name: grafana-storage-volume
  29. emptyDir: {}
  30. - name: grafana-config-volume
  31. configMap:
  32. name: grafana-config
  33. - name: grafana-dashboards-volume
  34. configMap:
  35. name: grafana-dashboards-config
  36. EOF

4. Accessing Grafana Dashboard

At this step You have configured all the necessary components in order to view your Grafana dashboards. By using port-forward feature expose Grafana to your local machine.

  1. kubectl port-forward pod/grafana-pod 3000:3000 -n calico-monitoring

You can now access Grafana web-ui at http://localhost:3000, if you prefer to visit Felix dashboard directly click here.

Visualizing metrics via Grafana - 图5note

Both username and password are admin.

After login you will be prompted to change the default password, you can either change it here (Recommended) and click Save or click Skip and do it later from settings.

Congratulation you have arrived at your Felix dashboard.

In this tutorial we have also prepared a Typha dashboard for you, if you are not using Typha in your cluster you can delete it safely via Grafana web-ui.

Visualizing metrics via Grafana - 图6caution

A more detailed guide about Typha detection and setup can be found at this link.

Cleanup

By executing below command, you will delete all Calico monitoring resources, including the ones created by following this tutorial, and the monitor component metrics guide.

  1. kubectl delete namespace calico-monitoring