Grafana dashboard: Container resources
Description: Overview of requests, limits and usage of containers. Similar to what "kube-eagle" offers, but this dashboard relies on kube-state-metrics and kubelet/cadvisor.

This dashboard leverages the data collected by prometheus from [kube-state-metrics](https://github.com/kubernetes/kube-state-metrics) and [kubelet/cadvisor](https://kubernetes.io/docs/concepts/cluster-administration/system-metrics/) to provide a similar experience to [kube-eagle](https://github.com/cloudworkz/kube-eagle). While kube-eagle itself is a great tool, when you are already scraping kube-state-metrics and cadvisor, it is also a bit redundant.

{
  "__inputs": [
    {
      "name": "DS_PROMETHEUS",
      "label": "Prometheus",
      "description": "Name of your Prometheus datasource",
      "type": "datasource",
      "pluginId": "prometheus",
      "pluginName": "Prometheus"
    }
  ],
  "__requires": [
    {
      "type": "grafana",
      "id": "grafana",
      "name": "Grafana",
      "version": "8.0.3"
    },
    {
      "type": "datasource",
      "id": "prometheus",
      "name": "Prometheus",
      "version": "1.0.0"
    },
    {
      "type": "panel",
      "id": "table",
      "name": "Table",
      "version": ""
    },
    {
      "type": "panel",
      "id": "timeseries",
      "name": "Time series",
      "version": ""
    }
  ],
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": "-- Grafana --",
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      }
    ]
  },
  "description": "Overview of requests, limits and usage of containers. Similar to what \"kube-eagle\" offers, but this dashboard relies on kube-state-metrics and kubelet/cadvisor.",
  "editable": true,
  "gnetId": 14678,
  "graphTooltip": 0,
  "id": null,
  "iteration": 1625422644671,
  "links": [],
  "panels": [
    {
      "datasource": "${DS_PROMETHEUS}",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "axisLabel": "",
            "axisPlacement": "auto",
            "barAlignment": 0,
            "drawStyle": "line",
            "fillOpacity": 0,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "lineInterpolation": "linear",
            "lineWidth": 1,
            "pointSize": 5,
            "scaleDistribution": {
              "type": "linear"
            },
            "showPoints": "auto",
            "spanNulls": false,
            "stacking": {
              "group": "A",
              "mode": "none"
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 9,
        "w": 12,
        "x": 0,
        "y": 0
      },
      "id": 5,
      "options": {
        "legend": {
          "calcs": [],
          "displayMode": "list",
          "placement": "bottom"
        },
        "tooltip": {
          "mode": "multi"
        }
      },
      "targets": [
        {
          "exemplar": true,
          "expr": "max (kube_pod_container_resource_requests{resource=\"cpu\", namespace=\"$namespace\", pod=\"$pod\", container=\"$container\"})",
          "interval": "",
          "legendFormat": "requests",
          "queryType": "randomWalk",
          "refId": "A"
        },
        {
          "exemplar": true,
          "expr": "max (kube_pod_container_resource_limits{resource=\"cpu\", namespace=\"$namespace\", pod=\"$pod\", container=\"$container\"})",
          "hide": false,
          "interval": "",
          "legendFormat": "limits",
          "queryType": "randomWalk",
          "refId": "B"
        },
        {
          "exemplar": true,
          "expr": "max (irate(container_cpu_usage_seconds_total{image!=\"\", image!~\"^k8s.gcr.io/pause:.*$\", namespace=\"$namespace\", pod=\"$pod\", container=\"$container\"}[5m]))",
          "hide": false,
          "interval": "",
          "legendFormat": "usage",
          "queryType": "randomWalk",
          "refId": "C"
        }
      ],
      "title": "CPU",
      "type": "timeseries"
    },
    {
      "datasource": "${DS_PROMETHEUS}",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "axisLabel": "",
            "axisPlacement": "auto",
            "barAlignment": 0,
            "drawStyle": "line",
            "fillOpacity": 0,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "lineInterpolation": "linear",
            "lineWidth": 1,
            "pointSize": 5,
            "scaleDistribution": {
              "type": "linear"
            },
            "showPoints": "auto",
            "spanNulls": false,
            "stacking": {
              "group": "A",
              "mode": "none"
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          },
          "unit": "bytes"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 9,
        "w": 12,
        "x": 12,
        "y": 0
      },
      "id": 6,
      "options": {
        "legend": {
          "calcs": [],
          "displayMode": "list",
          "placement": "bottom"
        },
        "tooltip": {
          "mode": "multi"
        }
      },
      "targets": [
        {
          "exemplar": true,
          "expr": "max (kube_pod_container_resource_requests{resource=\"memory\", namespace=\"$namespace\", pod=\"$pod\", container=\"$container\"})",
          "interval": "",
          "legendFormat": "requests",
          "queryType": "randomWalk",
          "refId": "A"
        },
        {
          "exemplar": true,
          "expr": "max (kube_pod_container_resource_limits{resource=\"memory\", namespace=\"$namespace\", pod=\"$pod\", container=\"$container\"})",
          "hide": false,
          "interval": "",
          "legendFormat": "limits",
          "queryType": "randomWalk",
          "refId": "B"
        },
        {
          "exemplar": true,
          "expr": "max (container_memory_working_set_bytes{namespace=\"$namespace\", pod=\"$pod\", container=\"$container\"})",
          "hide": false,
          "interval": "",
          "legendFormat": "usage",
          "queryType": "randomWalk",
          "refId": "C"
        }
      ],
      "title": "Memory",
      "type": "timeseries"
    },
    {
      "datasource": "${DS_PROMETHEUS}",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "fixed"
          },
          "custom": {
            "align": "auto",
            "displayMode": "auto",
            "filterable": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byRegexp",
              "options": "^Usage/.*$"
            },
            "properties": [
              {
                "id": "unit",
                "value": "percentunit"
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 14,
        "w": 24,
        "x": 0,
        "y": 9
      },
      "id": 2,
      "options": {
        "showHeader": true,
        "sortBy": [
          {
            "desc": false,
            "displayName": "Usage/Request"
          }
        ]
      },
      "pluginVersion": "8.0.3",
      "targets": [
        {
          "exemplar": true,
          "expr": "sum (kube_pod_container_resource_requests{resource=\"cpu\"}) by (namespace, pod, container)",
          "format": "table",
          "instant": true,
          "interval": "",
          "legendFormat": "",
          "queryType": "randomWalk",
          "refId": "A"
        },
        {
          "exemplar": true,
          "expr": "sum (kube_pod_container_resource_limits{resource=\"cpu\"}) by (namespace, pod, container)",
          "format": "table",
          "hide": false,
          "instant": true,
          "interval": "",
          "legendFormat": "",
          "queryType": "randomWalk",
          "refId": "B"
        },
        {
          "exemplar": true,
          "expr": "sum (irate(container_cpu_usage_seconds_total{image!=\"\", image!~\"^k8s.gcr.io/pause:.*$\"}[5m])) by (namespace, pod, container)",
          "format": "table",
          "hide": false,
          "instant": true,
          "interval": "",
          "legendFormat": "",
          "queryType": "randomWalk",
          "refId": "C"
        },
        {
          "exemplar": true,
          "expr": "sum( irate(container_cpu_usage_seconds_total{image!=\"\", image!~\"^k8s.gcr.io/pause:.*$\"}[5m]) / ignoring(cpu, endpoint, id, image, instance, job, node_name, metrics_path, name, resource, service, unit) kube_pod_container_resource_requests{resource=\"cpu\"} ) by (namespace, pod, container)",
          "format": "table",
          "hide": false,
          "instant": true,
          "interval": "",
          "legendFormat": "",
          "queryType": "randomWalk",
          "refId": "D"
        },
        {
          "exemplar": true,
          "expr": "sum( irate(container_cpu_usage_seconds_total{image!=\"\", image!~\"^k8s.gcr.io/pause:.*$\"}[5m]) / ignoring(cpu, endpoint, id, image, instance, job, node_name, metrics_path, name, resource, service, unit) kube_pod_container_resource_limits{resource=\"cpu\"} ) by (namespace, pod, container)",
          "format": "table",
          "hide": false,
          "instant": true,
          "interval": "",
          "legendFormat": "",
          "queryType": "randomWalk",
          "refId": "E"
        }
      ],
      "title": "CPU",
      "transformations": [
        {
          "id": "merge",
          "options": {}
        },
        {
          "id": "organize",
          "options": {
            "excludeByName": {
              "Time": true
            },
            "indexByName": {
              "Time": 0,
              "Value #A": 4,
              "Value #B": 5,
              "Value #C": 6,
              "container": 3,
              "namespace": 1,
              "pod": 2
            },
            "renameByName": {
              "Value #A": "Requests",
              "Value #B": "Limits",
              "Value #C": "Usage",
              "Value #D": "Usage/Request",
              "Value #E": "Usage/Limit"
            }
          }
        }
      ],
      "type": "table"
    },
    {
      "datasource": "${DS_PROMETHEUS}",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "fixed"
          },
          "custom": {
            "align": "auto",
            "displayMode": "auto",
            "filterable": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          },
          "unit": "bytes"
        },
        "overrides": [
          {
            "matcher": {
              "id": "byRegexp",
              "options": "^Usage/.*$"
            },
            "properties": [
              {
                "id": "unit",
                "value": "percentunit"
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 14,
        "w": 24,
        "x": 0,
        "y": 23
      },
      "id": 3,
      "options": {
        "showHeader": true,
        "sortBy": [
          {
            "desc": true,
            "displayName": "Usage/Request"
          }
        ]
      },
      "pluginVersion": "8.0.3",
      "targets": [
        {
          "exemplar": true,
          "expr": "sum (kube_pod_container_resource_requests{resource=\"memory\"}) by (namespace, pod, container)",
          "format": "table",
          "instant": true,
          "interval": "",
          "legendFormat": "",
          "queryType": "randomWalk",
          "refId": "A"
        },
        {
          "exemplar": true,
          "expr": "sum (kube_pod_container_resource_limits{resource=\"memory\"}) by (namespace, pod, container)",
          "format": "table",
          "hide": false,
          "instant": true,
          "interval": "",
          "legendFormat": "",
          "queryType": "randomWalk",
          "refId": "B"
        },
        {
          "exemplar": true,
          "expr": "sum (container_memory_working_set_bytes{image!=\"\", image!~\"^k8s.gcr.io/pause:.*$\"}) by (namespace, pod, container)",
          "format": "table",
          "hide": false,
          "instant": true,
          "interval": "",
          "legendFormat": "",
          "queryType": "randomWalk",
          "refId": "C"
        },
        {
          "exemplar": true,
          "expr": "sum( container_memory_working_set_bytes{image!=\"\", image!~\"^k8s.gcr.io/pause:.*$\"} / ignoring(endpoint, id, image, instance, job, metrics_path, name, node_name, resource, service, unit) kube_pod_container_resource_requests{resource=\"memory\"} ) by (namespace, pod, container)",
          "format": "table",
          "hide": false,
          "instant": true,
          "interval": "",
          "legendFormat": "",
          "queryType": "randomWalk",
          "refId": "D"
        },
        {
          "exemplar": true,
          "expr": "sum( container_memory_working_set_bytes{image!=\"\", image!~\"^k8s.gcr.io/pause:.*$\"} / ignoring(endpoint, id, image, instance, job, metrics_path, name, node_name, resource, service, unit) kube_pod_container_resource_limits{resource=\"memory\"} ) by (namespace, pod, container)",
          "format": "table",
          "hide": false,
          "instant": true,
          "interval": "",
          "legendFormat": "",
          "queryType": "randomWalk",
          "refId": "E"
        }
      ],
      "title": "Memory",
      "transformations": [
        {
          "id": "merge",
          "options": {}
        },
        {
          "id": "organize",
          "options": {
            "excludeByName": {
              "Time": true
            },
            "indexByName": {
              "Time": 0,
              "Value #A": 4,
              "Value #B": 5,
              "Value #C": 6,
              "container": 3,
              "namespace": 1,
              "pod": 2
            },
            "renameByName": {
              "Value #A": "Requests",
              "Value #B": "Limits",
              "Value #C": "Usage",
              "Value #D": "Usage/Request",
              "Value #E": "Usage/Limit"
            }
          }
        }
      ],
      "type": "table"
    }
  ],
  "schemaVersion": 30,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": [
      {
        "allValue": null,
        "current": {},
        "datasource": "${DS_PROMETHEUS}",
        "definition": "label_values(kube_pod_container_info, namespace)",
        "description": null,
        "error": null,
        "hide": 0,
        "includeAll": false,
        "label": null,
        "multi": false,
        "name": "namespace",
        "options": [],
        "query": {
          "query": "label_values(kube_pod_container_info, namespace)",
          "refId": "StandardVariableQuery"
        },
        "refresh": 2,
        "regex": "",
        "skipUrlSync": false,
        "sort": 1,
        "type": "query"
      },
      {
        "allValue": null,
        "current": {},
        "datasource": "${DS_PROMETHEUS}",
        "definition": "label_values(kube_pod_container_info{namespace=\"$namespace\"}, pod)",
        "description": null,
        "error": null,
        "hide": 0,
        "includeAll": false,
        "label": null,
        "multi": false,
        "name": "pod",
        "options": [],
        "query": {
          "query": "label_values(kube_pod_container_info{namespace=\"$namespace\"}, pod)",
          "refId": "StandardVariableQuery"
        },
        "refresh": 2,
        "regex": "",
        "skipUrlSync": false,
        "sort": 1,
        "type": "query"
      },
      {
        "allValue": null,
        "current": {},
        "datasource": "${DS_PROMETHEUS}",
        "definition": "label_values(kube_pod_container_info{namespace=\"$namespace\", pod=\"$pod\"}, container)",
        "description": null,
        "error": null,
        "hide": 0,
        "includeAll": false,
        "label": null,
        "multi": false,
        "name": "container",
        "options": [],
        "query": {
          "query": "label_values(kube_pod_container_info{namespace=\"$namespace\", pod=\"$pod\"}, container)",
          "refId": "StandardVariableQuery"
        },
        "refresh": 2,
        "regex": "",
        "skipUrlSync": false,
        "sort": 1,
        "type": "query"
      }
    ]
  },
  "time": {
    "from": "now-3h",
    "to": "now"
  },
  "timepicker": {},
  "timezone": "",
  "title": "Container resources",
  "uid": "px1WKJznk",
  "version": 5
}