How to monitor kubevirt in Grafana

This guide describes How to monitor kubevirt in Grafana.

Monitoring KubeVirt VMIs with Grafana and Prometheus

This guide explains how to monitor KubeVirt Virtual Machine Instances (VMIs) using Grafana and Prometheus. By the end of this guide, you will have a Grafana dashboard displaying metrics related to KubeVirt VMIs.

Prerequisites

  • A running multi-node Kubernetes cluster with KubeVirt installed

    ⚠️ Note: Single-node clusters are not supported due to component scheduling and storage limitations.

  • A functional storage provider (e.g., Rook-Ceph or any other CSI-compatible solution) must be installed and available

    ⚠️ Required for deploying both Prometheus and Grafana, as they rely on PersistentVolumeClaims (PVCs)

  • Prometheus deployed in the cluster

  • Grafana installed and configured to connect to Prometheus

Step 1: Ensure Prometheus is Collecting KubeVirt Metrics

KubeVirt exposes various metrics that Prometheus can scrape. These metrics are documented here: KubeVirt Metrics.

To check if Prometheus is collecting KubeVirt metrics:

  1. Open the Prometheus Dashboard

  2. Search for KubeVirt-related metrics, e.g., kubevirt_vmi_memory_available_bytes.

  3. If no metrics appear, ensure the KubeVirt servicemonitor is added to Prometheus:

     kubectl get servicemonitor -A | grep kubevirt
    
  4. Check that KubeVirt has been installed correctly and that monitorNamespace and monitorAccount are correct. How to install KubeOps Virtualization (kubevirt)

  5. Reload Prometheus operator.

  6. Reload Kubevirt operator.

Step 2: Import the KubeVirt Grafana Dashboard

KubeVirt provides a ready-to-use Grafana dashboard JSON file: KubeVirt Grafana Dashboard.

To import it into Grafana:

  1. Open the Grafana Dashboard.
  2. Navigate to Dashboards > New > Import.
  3. Paste the JSON content from the KubeVirt dashboard file.
  4. Select Prometheus as the data source.
  5. Click Load.

Step 3: Customize the Dashboard (Optional)

To add specific VMI-related metrics to the dashboard:

  1. Click Edit on a panel.

  2. Use PromQL queries to fetch desired VMI metrics, e.g.,

    • CPU Usage: rate(kubevirt_vmi_cpu_usage_seconds_total[5m])
    • Memory Usage: kubevirt_vmi_memory_available_bytes
    • Network Traffic: rate(kubevirt_vmi_network_receive_bytes_total[5m])
  3. Save the dashboard.

Note: Query output can be viewed in the Prometheus Dashboard.

Conclusion

You have successfully set up Grafana to monitor KubeVirt VMIs using Prometheus. You can now track VMI performance and resource usage effectively.