Grafana dashboard: VPA Recommendations
Description: A dashboard to visualize metrics about the Vertical Pod Autoscalar (https://github.com/kubernetes/autoscaler/tree/master/vertical-pod-autoscaler) using the generated Prometheus metrics of the Kube-State-Metrics (https://github.com/kubernetes/kube-state-metrics/blob/master/docs/verticalpodautoscaler-metrics.md)

# What's it all about?
A dashboard to visualize metrics about the Vertical Pod Autoscalar (https://github.com/kubernetes/autoscaler/tree/master/vertical-pod-autoscaler) using the generated Prometheus metrics of the Kube-State-Metrics (https://github.com/kubernetes/kube-state-metrics/blob/master/docs/verticalpodautoscaler-metrics.md)

# What do I need as a perquisite?
- Prometheus installed => ultimately using the kube-prometheus stack (https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack)
- The kube-state-metrics must be configured to enable Vertical Pod Autoscalar metrics. Example for the Helm Chart above:
```yaml
kube-state-metrics:
  namespaceOverride: ""
  rbac:
    create: true
  ...
  collectors:
    verticalpodautoscalers: true
```
- VPA Installed and at least one `VerticalPodAutoscalar` CRD is configured against a certain target (check the documentation of the VPA for more info)
- Optionally: VPA is using Prometheus as a historical query backend to monitor changes over time. 

# My installation & configurations for the VPA
I am using the Helm chart at https://github.com/FairwindsOps/charts/tree/master/stable/vpa for the installing the VPA. There are other ways to do so. Just thought of sharing my `values.yml` for customizing this chart as the Prometheus part wasn't that trivial. You can check my GitHub Gist here [https://gist.github.com/sherifkayad/1b4e4df408e1be357168a38e1980b9a5](https://gist.github.com/sherifkayad/1b4e4df408e1be357168a38e1980b9a5)

# What's New
- Revision 3 => added support for dynamic datasource and for multi-cluster setups (cluster label)

{
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": {
          "type": "datasource",
          "uid": "grafana"
        },
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "target": {
          "limit": 100,
          "matchAny": false,
          "tags": [],
          "type": "dashboard"
        },
        "type": "dashboard"
      }
    ]
  },
  "editable": true,
  "fiscalYearStartMonth": 0,
  "graphTooltip": 0,
  "id": 2173,
  "links": [],
  "liveNow": false,
  "panels": [
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "datasource": {
        "uid": "${DS_PROMETHEUS}"
      },
      "description": "Shows the recommendations that the VPA gives as target usage. The graph also shows the actual usage of each container.",
      "fill": 0,
      "fillGradient": 0,
      "gridPos": {
        "h": 10,
        "w": 12,
        "x": 0,
        "y": 0
      },
      "hiddenSeries": false,
      "id": 3,
      "legend": {
        "avg": false,
        "current": false,
        "max": false,
        "min": false,
        "show": true,
        "total": false,
        "values": false
      },
      "lines": true,
      "linewidth": 1,
      "links": [],
      "nullPointMode": "null",
      "options": {
        "alertThreshold": true
      },
      "percentage": false,
      "pluginVersion": "9.5.1",
      "pointradius": 2,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "datasource": {
            "uid": "${DS_PROMETHEUS}"
          },
          "exemplar": true,
          "expr": "sum(container_memory_working_set_bytes{cluster=\"$cluster\", namespace=\"$namespace\", pod=~\"$targetName(.+)\", container!=\"\", container!=\"POD\"}) by (container,pod)",
          "format": "time_series",
          "interval": "",
          "intervalFactor": 1,
          "legendFormat": "{{pod}}-{{container}} actual usage",
          "refId": "D"
        },
        {
          "datasource": {
            "uid": "${DS_PROMETHEUS}"
          },
          "exemplar": true,
          "expr": "sum(kube_verticalpodautoscaler_status_recommendation_containerrecommendations_$recommendation{resource=\"memory\", cluster=\"$cluster\", namespace=\"$namespace\", target_name=\"$targetName\"}) by (container)",
          "format": "time_series",
          "interval": "",
          "intervalFactor": 1,
          "legendFormat": "{{container}} recommendation",
          "refId": "C"
        }
      ],
      "thresholds": [],
      "timeRegions": [],
      "title": "Memory $recommendation vs Memory Usage",
      "tooltip": {
        "shared": true,
        "sort": 0,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "mode": "time",
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "$$hashKey": "object:420",
          "format": "bytes",
          "label": "Bytes",
          "logBase": 1,
          "show": true
        },
        {
          "$$hashKey": "object:421",
          "format": "short",
          "logBase": 1,
          "show": true
        }
      ],
      "yaxis": {
        "align": false
      }
    },
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "datasource": {
        "uid": "${DS_PROMETHEUS}"
      },
      "description": "Shows the recommendation of the VPA and compares it to the requests and limits of all containers in a pod. \n\n**Requests and/or limits may not reflect useful values if they are not defined for each container in a pod.",
      "fill": 0,
      "fillGradient": 0,
      "gridPos": {
        "h": 10,
        "w": 12,
        "x": 12,
        "y": 0
      },
      "hiddenSeries": false,
      "id": 6,
      "legend": {
        "avg": false,
        "current": false,
        "max": false,
        "min": false,
        "show": true,
        "total": false,
        "values": false
      },
      "lines": true,
      "linewidth": 1,
      "links": [],
      "nullPointMode": "null",
      "options": {
        "alertThreshold": true
      },
      "percentage": false,
      "pluginVersion": "9.5.1",
      "pointradius": 2,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "datasource": {
            "uid": "${DS_PROMETHEUS}"
          },
          "exemplar": true,
          "expr": "sum(kube_verticalpodautoscaler_status_recommendation_containerrecommendations_$recommendation{cluster=\"$cluster\", namespace=\"$namespace\", target_name=\"$targetName\", resource=\"memory\"}) by (container)",
          "format": "time_series",
          "interval": "",
          "intervalFactor": 1,
          "legendFormat": "{{container}} recommendation",
          "refId": "A"
        },
        {
          "datasource": {
            "uid": "${DS_PROMETHEUS}"
          },
          "exemplar": true,
          "expr": "sum(kube_pod_container_resource_requests{resource=\"memory\", cluster=\"$cluster\", namespace=\"$namespace\", pod=~\"$targetName(.+)\"}) by (container,pod)",
          "format": "time_series",
          "instant": false,
          "interval": "",
          "intervalFactor": 1,
          "legendFormat": "{{pod}}-{{container}} requests",
          "refId": "B"
        },
        {
          "datasource": {
            "uid": "${DS_PROMETHEUS}"
          },
          "exemplar": true,
          "expr": "sum(kube_pod_container_resource_limits{resource=\"memory\", cluster=\"$cluster\", namespace=\"$namespace\", pod=~\"$targetName(.+)\"}) by (container,pod)",
          "format": "time_series",
          "interval": "",
          "intervalFactor": 1,
          "legendFormat": "{{pod}}-{{container}} limits",
          "refId": "C"
        }
      ],
      "thresholds": [],
      "timeRegions": [],
      "title": "VPA Memory Recommendations vs Requests and Limits",
      "tooltip": {
        "shared": true,
        "sort": 0,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "mode": "time",
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "$$hashKey": "object:272",
          "format": "bytes",
          "label": "Bytes",
          "logBase": 1,
          "show": true
        },
        {
          "$$hashKey": "object:273",
          "format": "short",
          "logBase": 1,
          "show": true
        }
      ],
      "yaxis": {
        "align": false
      }
    },
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "datasource": {
        "uid": "${DS_PROMETHEUS}"
      },
      "description": "Shows the recommendations that the VPA gives as target usage. The graph also shows the actual usage of each container.",
      "fill": 0,
      "fillGradient": 0,
      "gridPos": {
        "h": 10,
        "w": 12,
        "x": 0,
        "y": 10
      },
      "hiddenSeries": false,
      "id": 2,
      "legend": {
        "avg": false,
        "current": false,
        "max": false,
        "min": false,
        "show": true,
        "total": false,
        "values": false
      },
      "lines": true,
      "linewidth": 1,
      "links": [],
      "nullPointMode": "null",
      "options": {
        "alertThreshold": true
      },
      "percentage": false,
      "pluginVersion": "9.5.1",
      "pointradius": 2,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "datasource": {
            "uid": "${DS_PROMETHEUS}"
          },
          "exemplar": true,
          "expr": "sum(rate(container_cpu_usage_seconds_total{cluster=\"$cluster\", namespace=\"$namespace\", pod=~\"$targetName-(.+)\", container!=\"\", container!=\"POD\"}[$__rate_interval])) by (container,pod) * 1000",
          "format": "time_series",
          "interval": "",
          "intervalFactor": 1,
          "legendFormat": "{{pod}}-{{container}} actual usage",
          "refId": "D"
        },
        {
          "datasource": {
            "uid": "${DS_PROMETHEUS}"
          },
          "exemplar": true,
          "expr": "sum(kube_verticalpodautoscaler_status_recommendation_containerrecommendations_$recommendation{resource=\"cpu\", cluster=\"$cluster\", namespace=\"$namespace\", target_name=\"$targetName\"}) by (container) * 1000",
          "format": "time_series",
          "interval": "",
          "intervalFactor": 1,
          "legendFormat": "{{container}} recommendation",
          "refId": "C"
        }
      ],
      "thresholds": [],
      "timeRegions": [],
      "title": "CPU $recommendation vs CPU Usage",
      "tooltip": {
        "shared": true,
        "sort": 0,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "mode": "time",
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "$$hashKey": "object:207",
          "format": "short",
          "label": "Millicores",
          "logBase": 1,
          "show": true
        },
        {
          "$$hashKey": "object:208",
          "format": "short",
          "logBase": 1,
          "show": true
        }
      ],
      "yaxis": {
        "align": false
      }
    },
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "datasource": {
        "uid": "${DS_PROMETHEUS}"
      },
      "description": "Shows the recommendation of the VPA and compares it to the requests and limits of all containers in a pod. \n\n**Requests and/or limits may not reflect useful values if they are not defined for each container in a pod.",
      "fill": 0,
      "fillGradient": 0,
      "gridPos": {
        "h": 10,
        "w": 12,
        "x": 12,
        "y": 10
      },
      "hiddenSeries": false,
      "id": 5,
      "legend": {
        "avg": false,
        "current": false,
        "max": false,
        "min": false,
        "show": true,
        "total": false,
        "values": false
      },
      "lines": true,
      "linewidth": 1,
      "links": [],
      "nullPointMode": "null",
      "options": {
        "alertThreshold": true
      },
      "percentage": false,
      "pluginVersion": "9.5.1",
      "pointradius": 2,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "datasource": {
            "uid": "${DS_PROMETHEUS}"
          },
          "exemplar": true,
          "expr": "sum(kube_verticalpodautoscaler_status_recommendation_containerrecommendations_$recommendation{cluster=\"$cluster\", namespace=\"$namespace\", target_name=\"$targetName\", resource=\"cpu\"}) by (container) * 1000",
          "format": "time_series",
          "interval": "",
          "intervalFactor": 1,
          "legendFormat": "{{container}} recommendation",
          "refId": "A"
        },
        {
          "datasource": {
            "uid": "${DS_PROMETHEUS}"
          },
          "exemplar": true,
          "expr": "sum(kube_pod_container_resource_requests{resource=\"cpu\", cluster=\"$cluster\", namespace=\"$namespace\", pod=~\"$targetName(.+)\"}) by (container,pod) * 1000",
          "format": "time_series",
          "interval": "",
          "intervalFactor": 1,
          "legendFormat": "{{pod}}-{{container}} requests",
          "refId": "B"
        },
        {
          "datasource": {
            "uid": "${DS_PROMETHEUS}"
          },
          "exemplar": true,
          "expr": "sum(kube_pod_container_resource_limits{resource=\"cpu\", cluster=\"$cluster\", namespace=\"$namespace\", pod=~\"$targetName(.+)\"}) by (container,pod) * 1000",
          "format": "time_series",
          "interval": "",
          "intervalFactor": 1,
          "legendFormat": "{{pod}}-{{container}} limits",
          "refId": "C"
        }
      ],
      "thresholds": [],
      "timeRegions": [],
      "title": "VPA CPU Recommendations vs Requests and Limits",
      "tooltip": {
        "shared": true,
        "sort": 0,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "mode": "time",
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "$$hashKey": "object:568",
          "format": "short",
          "label": "Millicores",
          "logBase": 1,
          "show": true
        },
        {
          "$$hashKey": "object:569",
          "format": "short",
          "logBase": 1,
          "show": true
        }
      ],
      "yaxis": {
        "align": false
      }
    }
  ],
  "refresh": "10s",
  "schemaVersion": 38,
  "style": "dark",
  "tags": [
    "Autoscaling",
    "VPA"
  ],
  "templating": {
    "list": [
      {
        "current": {},
        "hide": 0,
        "includeAll": false,
        "label": "datasource",
        "multi": false,
        "name": "DS_PROMETHEUS",
        "options": [],
        "query": "prometheus",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "type": "datasource"
      },
      {
        "current": {},
        "datasource": {
          "uid": "${DS_PROMETHEUS}"
        },
        "definition": "label_values(kube_verticalpodautoscaler_labels, cluster)",
        "hide": 0,
        "includeAll": false,
        "multi": false,
        "name": "cluster",
        "options": [],
        "query": {
          "query": "label_values(kube_verticalpodautoscaler_labels, cluster)",
          "refId": "StandardVariableQuery"
        },
        "refresh": 2,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "type": "query"
      },
      {
        "current": {
          "selected": false,
          "text": "target",
          "value": "target"
        },
        "hide": 0,
        "includeAll": false,
        "label": "Recommendation",
        "multi": false,
        "name": "recommendation",
        "options": [
          {
            "selected": true,
            "text": "target",
            "value": "target"
          },
          {
            "selected": false,
            "text": "uncappedtarget",
            "value": "uncappedtarget"
          },
          {
            "selected": false,
            "text": "lowerbound",
            "value": "lowerbound"
          },
          {
            "selected": false,
            "text": "upperbound",
            "value": "upperbound"
          }
        ],
        "query": "target,uncappedtarget,lowerbound,upperbound",
        "queryValue": "",
        "skipUrlSync": false,
        "type": "custom"
      },
      {
        "current": {},
        "datasource": {
          "uid": "${DS_PROMETHEUS}"
        },
        "definition": "label_values(kube_verticalpodautoscaler_labels{cluster=\"$cluster\"}, namespace)",
        "hide": 0,
        "includeAll": false,
        "label": "Namespace",
        "multi": false,
        "name": "namespace",
        "options": [],
        "query": {
          "query": "label_values(kube_verticalpodautoscaler_labels{cluster=\"$cluster\"}, namespace)",
          "refId": "StandardVariableQuery"
        },
        "refresh": 2,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "tagValuesQuery": "",
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      },
      {
        "current": {},
        "datasource": {
          "uid": "${DS_PROMETHEUS}"
        },
        "definition": "label_values(kube_verticalpodautoscaler_labels{cluster=\"$cluster\", namespace=\"$namespace\"}, target_name)",
        "hide": 0,
        "includeAll": false,
        "label": "Target",
        "multi": false,
        "name": "targetName",
        "options": [],
        "query": {
          "query": "label_values(kube_verticalpodautoscaler_labels{cluster=\"$cluster\", namespace=\"$namespace\"}, target_name)",
          "refId": "StandardVariableQuery"
        },
        "refresh": 2,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "tagValuesQuery": "",
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      }
    ]
  },
  "time": {
    "from": "now-1h",
    "to": "now"
  },
  "timepicker": {
    "refresh_intervals": [
      "5s",
      "10s",
      "30s",
      "1m",
      "5m",
      "15m",
      "30m",
      "1h"
    ],
    "time_options": [
      "5m",
      "15m",
      "1h",
      "3h",
      "6h",
      "12h",
      "24h",
      "2d",
      "7d",
      "14d"
    ]
  },
  "timezone": "browser",
  "title": "VPA Recommendations",
  "uid": "_BFbbSg7k",
  "version": 3,
  "weekStart": "",
  "gnetId": 14588,
  "description": "A dashboard to visualize metrics about the Vertical Pod Autoscalar (https://github.com/kubernetes/autoscaler/tree/master/vertical-pod-autoscaler) using the generated Prometheus metrics of the Kube-State-Metrics (https://github.com/kubernetes/kube-state-metrics/blob/master/docs/verticalpodautoscaler-metrics.md)"
}