Grafana dashboard: Namespace Resources Usage (vs Quotas)
Description: For companies that control resource utilization ($$$) in Kubernetes namespaces through resource quotas, this dashboard helps you and your end users to quickly spot how close they are to hitting their quota limits.

Comes with variables for datasource, AWS account, cluster, and namespace. Tune the labels/queries to your particular environment.

{
  "__inputs": [
    {
      "name": "DS_PROMETHEUS",
      "label": "Prometheus",
      "description": "",
      "type": "datasource",
      "pluginId": "prometheus",
      "pluginName": "Prometheus"
    }
  ],
  "__elements": [],
  "__requires": [
    {
      "type": "panel",
      "id": "gauge",
      "name": "Gauge",
      "version": ""
    },
    {
      "type": "grafana",
      "id": "grafana",
      "name": "Grafana",
      "version": "8.4.2"
    },
    {
      "type": "datasource",
      "id": "prometheus",
      "name": "Prometheus",
      "version": "1.0.0"
    },
    {
      "type": "panel",
      "id": "text",
      "name": "Text",
      "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",
        "target": {
          "limit": 100,
          "matchAny": false,
          "tags": [],
          "type": "dashboard"
        },
        "type": "dashboard"
      }
    ]
  },
  "description": "For companies that control resource utilization ($$$) in Kubernetes namespaces through resource quotas, this dashboard helps you and your end users to quickly spot how close they are to hitting their quota limits.",
  "editable": true,
  "fiscalYearStartMonth": 0,
  "gnetId": 17044,
  "graphTooltip": 0,
  "id": null,
  "iteration": 1663953135253,
  "links": [],
  "liveNow": false,
  "panels": [
    {
      "gridPos": {
        "h": 1,
        "w": 24,
        "x": 0,
        "y": 0
      },
      "id": 113,
      "title": "At a Glance",
      "type": "row"
    },
    {
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "max": 1,
          "min": 0,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "yellow",
                "value": 0.7
              },
              {
                "color": "red",
                "value": 0.9
              }
            ]
          },
          "unit": "percentunit"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 9,
        "w": 12,
        "x": 0,
        "y": 1
      },
      "id": 104,
      "links": [],
      "options": {
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "showThresholdLabels": false,
        "showThresholdMarkers": true
      },
      "pluginVersion": "8.4.2",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "exemplar": true,
          "expr": "sum by (cluster) (kube_resourcequota{namespace=\"$namespace\",cluster=~\"$cluster\", type=\"used\", resource=\"requests.cpu\"})/sum by (cluster) (kube_resourcequota{namespace=\"$namespace\",cluster=~\"$cluster\", type=\"hard\", resource=\"requests.cpu\"})",
          "hide": false,
          "interval": "",
          "legendFormat": "CPU Quota Used ({{ cluster }})",
          "refId": "A"
        }
      ],
      "title": "CPU Quota - % Allocated",
      "type": "gauge"
    },
    {
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "max": 1,
          "min": 0,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "#EAB839",
                "value": 0.7
              },
              {
                "color": "red",
                "value": 0.9
              }
            ]
          },
          "unit": "percentunit"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 9,
        "w": 12,
        "x": 12,
        "y": 1
      },
      "id": 105,
      "links": [],
      "options": {
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "showThresholdLabels": false,
        "showThresholdMarkers": true
      },
      "pluginVersion": "8.4.2",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "exemplar": true,
          "expr": "sum by (cluster)(kube_resourcequota{namespace=\"$namespace\",cluster=~\"$cluster\", type=\"used\", resource=\"requests.memory\"}) / sum by (cluster)(kube_resourcequota{namespace=\"$namespace\",cluster=~\"$cluster\", type=\"hard\", resource=\"requests.memory\"})",
          "hide": false,
          "interval": "",
          "legendFormat": "Memory limit ({{ cluster }})",
          "refId": "A"
        }
      ],
      "title": "Memory Quota - % Allocated",
      "type": "gauge"
    },
    {
      "gridPos": {
        "h": 1,
        "w": 24,
        "x": 0,
        "y": 10
      },
      "id": 107,
      "title": "Resource Quota",
      "type": "row"
    },
    {
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "axisLabel": "CPU Usage (Percent)",
            "axisPlacement": "auto",
            "barAlignment": 0,
            "drawStyle": "line",
            "fillOpacity": 0,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "lineInterpolation": "linear",
            "lineStyle": {
              "fill": "solid"
            },
            "lineWidth": 1,
            "pointSize": 5,
            "scaleDistribution": {
              "type": "linear"
            },
            "showPoints": "never",
            "spanNulls": true,
            "stacking": {
              "group": "A",
              "mode": "none"
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "mappings": [],
          "min": 0,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              }
            ]
          },
          "unit": "none"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 9,
        "w": 12,
        "x": 0,
        "y": 11
      },
      "id": 114,
      "links": [],
      "options": {
        "legend": {
          "calcs": [
            "lastNotNull"
          ],
          "displayMode": "table",
          "placement": "bottom"
        },
        "tooltip": {
          "mode": "single",
          "sort": "none"
        }
      },
      "pluginVersion": "8.4.2",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "exemplar": true,
          "expr": "kube_resourcequota{namespace=\"$namespace\",cluster=~\"$cluster\", type=\"hard\", resource=\"requests.cpu\"}",
          "hide": false,
          "interval": "",
          "legendFormat": "CPU limit ({{ cluster }})",
          "refId": "A"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "exemplar": true,
          "expr": "kube_resourcequota{namespace=\"$namespace\",cluster=~\"$cluster\", type=\"used\", resource=\"requests.cpu\"}",
          "hide": false,
          "interval": "",
          "legendFormat": "CPU allocated ({{ cluster }})",
          "refId": "B"
        }
      ],
      "title": "CPU Quota - Allocated vs Limit",
      "type": "timeseries"
    },
    {
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "axisLabel": "CPU Usage (Percent)",
            "axisPlacement": "auto",
            "barAlignment": 0,
            "drawStyle": "line",
            "fillOpacity": 0,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "lineInterpolation": "linear",
            "lineStyle": {
              "fill": "solid"
            },
            "lineWidth": 1,
            "pointSize": 5,
            "scaleDistribution": {
              "type": "linear"
            },
            "showPoints": "never",
            "spanNulls": true,
            "stacking": {
              "group": "A",
              "mode": "none"
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "mappings": [],
          "min": 0,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              }
            ]
          },
          "unit": "bytes"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 9,
        "w": 12,
        "x": 12,
        "y": 11
      },
      "id": 115,
      "links": [],
      "options": {
        "legend": {
          "calcs": [
            "lastNotNull"
          ],
          "displayMode": "table",
          "placement": "bottom"
        },
        "tooltip": {
          "mode": "single",
          "sort": "none"
        }
      },
      "pluginVersion": "8.4.2",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "exemplar": true,
          "expr": "kube_resourcequota{namespace=\"$namespace\",cluster=~\"$cluster\", type=\"hard\", resource=\"requests.memory\"}",
          "hide": false,
          "interval": "",
          "legendFormat": "Memory limit ({{ cluster }})",
          "refId": "A"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "exemplar": true,
          "expr": "kube_resourcequota{namespace=\"$namespace\",cluster=~\"$cluster\", type=\"used\", resource=\"requests.memory\"}",
          "hide": false,
          "interval": "",
          "legendFormat": "Memory allocated ({{ cluster }})",
          "refId": "B"
        }
      ],
      "title": "Memory Quota - Allocated vs Limit",
      "type": "timeseries"
    },
    {
      "collapsed": false,
      "gridPos": {
        "h": 1,
        "w": 24,
        "x": 0,
        "y": 20
      },
      "id": 109,
      "panels": [],
      "title": "Pod resource Requests, Limits and actual Usage",
      "type": "row"
    },
    {
      "gridPos": {
        "h": 2,
        "w": 24,
        "x": 0,
        "y": 21
      },
      "id": 111,
      "options": {
        "content": "If your Limits exceed your Requests, then it means you missed setting some limits! ",
        "mode": "markdown"
      },
      "pluginVersion": "8.4.2",
      "title": "Info",
      "type": "text"
    },
    {
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "axisLabel": "CPU Usage (Percent)",
            "axisPlacement": "auto",
            "barAlignment": 0,
            "drawStyle": "line",
            "fillOpacity": 0,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "lineInterpolation": "linear",
            "lineStyle": {
              "fill": "solid"
            },
            "lineWidth": 1,
            "pointSize": 5,
            "scaleDistribution": {
              "type": "linear"
            },
            "showPoints": "never",
            "spanNulls": true,
            "stacking": {
              "group": "A",
              "mode": "none"
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "mappings": [],
          "min": 0,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              }
            ]
          },
          "unit": "none"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 9,
        "w": 12,
        "x": 0,
        "y": 23
      },
      "id": 100,
      "links": [],
      "options": {
        "legend": {
          "calcs": [
            "lastNotNull"
          ],
          "displayMode": "table",
          "placement": "bottom"
        },
        "tooltip": {
          "mode": "single",
          "sort": "none"
        }
      },
      "pluginVersion": "8.0.3",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "exemplar": true,
          "expr": "(sum by (cluster,namespace) (rate(container_cpu_usage_seconds_total{namespace=\"$namespace\",account=~\"$awsaccount\",cluster=~\"$cluster\"}[$__rate_interval])))",
          "hide": false,
          "interval": "",
          "legendFormat": "CPU usage for all PODs - container {{ container }} ({{ cluster }})",
          "refId": "C"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "exemplar": true,
          "expr": "100*avg(kube_pod_container_resource_requests{resource=\"cpu\",namespace=\"$namespace\",account=~\"$awsaccount\",cluster=~\"$cluster\"}) by (cluster,namespace)",
          "hide": false,
          "interval": "",
          "legendFormat": "CPU request for {{ namespace }} ({{ cluster }})",
          "refId": "A"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "exemplar": true,
          "expr": "100*avg(kube_pod_container_resource_limits{resource=\"cpu\",namespace=\"$namespace\",account=~\"$awsaccount\",cluster=~\"$cluster\"}) by (cluster,namespace)",
          "hide": false,
          "interval": "",
          "legendFormat": "CPU limit  {{ namespace }} ({{ cluster }})",
          "refId": "D"
        }
      ],
      "title": "CPU Usage (Avg of all replicas)",
      "type": "timeseries"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "${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": "never",
            "spanNulls": true,
            "stacking": {
              "group": "A",
              "mode": "none"
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "mappings": [],
          "min": 0,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              }
            ]
          },
          "unit": "bytes"
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "Memory Request"
            },
            "properties": [
              {
                "id": "custom.spanNulls",
                "value": true
              },
              {
                "id": "color",
                "value": {
                  "fixedColor": "yellow",
                  "mode": "fixed"
                }
              },
              {
                "id": "custom.hideFrom",
                "value": {
                  "legend": false,
                  "tooltip": true,
                  "viz": false
                }
              },
              {
                "id": "custom.fillOpacity",
                "value": 0
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Memory Limit"
            },
            "properties": [
              {
                "id": "custom.fillOpacity",
                "value": 0
              },
              {
                "id": "custom.spanNulls",
                "value": true
              },
              {
                "id": "custom.hideFrom",
                "value": {
                  "legend": false,
                  "tooltip": true,
                  "viz": false
                }
              },
              {
                "id": "color",
                "value": {
                  "fixedColor": "red",
                  "mode": "fixed"
                }
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 9,
        "w": 12,
        "x": 12,
        "y": 23
      },
      "id": 103,
      "links": [],
      "options": {
        "legend": {
          "calcs": [
            "lastNotNull"
          ],
          "displayMode": "table",
          "placement": "bottom"
        },
        "tooltip": {
          "mode": "single",
          "sort": "none"
        }
      },
      "pluginVersion": "8.0.3",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "exemplar": true,
          "expr": "sum by (cluster,namespace) (container_memory_working_set_bytes{namespace=\"$namespace\",account=~\"$awsaccount\",cluster=~\"$cluster\"})",
          "format": "time_series",
          "hide": false,
          "interval": "",
          "intervalFactor": 1,
          "legendFormat": "Max memory usage of {{ namespace }} ({{ cluster }})",
          "refId": "B"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "exemplar": true,
          "expr": "sum by (cluster,namespace) (kube_pod_container_resource_requests{namespace=\"$namespace\", account=~\"$awsaccount\",cluster=~\"$cluster\"})",
          "hide": false,
          "interval": "",
          "legendFormat": "Memory Request for {{ container }} ({{ cluster }})",
          "refId": "A"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_PROMETHEUS}"
          },
          "exemplar": true,
          "expr": "sum by (cluster,namespace) (kube_pod_container_resource_limits{namespace=\"$namespace\",account=~\"$awsaccount\",cluster=~\"$cluster\"})",
          "hide": false,
          "interval": "",
          "legendFormat": "Memory Limit for {{ container }} ({{ cluster }})",
          "refId": "C"
        }
      ],
      "title": "Memory Usage (Max of all replicas)",
      "type": "timeseries"
    }
  ],
  "refresh": "",
  "schemaVersion": 35,
  "style": "dark",
  "tags": [
    "start here"
  ],
  "templating": {
    "list": [
      {
        "current": {
          "selected": false,
          "text": "Prometheus",
          "value": "Prometheus"
        },
        "hide": 0,
        "includeAll": false,
        "label": "datasource",
        "multi": false,
        "name": "DS_PROMETHEUS",
        "options": [],
        "query": "prometheus",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "type": "datasource"
      },
      {
        "current": {},
        "datasource": {
          "type": "prometheus",
          "uid": "${DS_PROMETHEUS}"
        },
        "definition": "query_result(avg(kube_deployment_labels) by (account))",
        "hide": 0,
        "includeAll": false,
        "label": "AWS Account",
        "multi": true,
        "name": "awsaccount",
        "options": [],
        "query": {
          "query": "query_result(avg(kube_deployment_labels) by (account))",
          "refId": "StandardVariableQuery"
        },
        "refresh": 1,
        "regex": "/.*(?:account)=\"([^\"]*).*/",
        "skipUrlSync": false,
        "sort": 5,
        "type": "query"
      },
      {
        "current": {},
        "datasource": {
          "type": "prometheus",
          "uid": "${DS_PROMETHEUS}"
        },
        "definition": "query_result(avg(kube_deployment_labels{account=~\"$awsaccount\"}) by (cluster))",
        "hide": 0,
        "includeAll": false,
        "label": "Cluster",
        "multi": true,
        "name": "cluster",
        "options": [],
        "query": {
          "query": "query_result(avg(kube_deployment_labels{account=~\"$awsaccount\"}) by (cluster))",
          "refId": "StandardVariableQuery"
        },
        "refresh": 1,
        "regex": "/.*(?:cluster)=\"([^\"]*).*/",
        "skipUrlSync": false,
        "sort": 5,
        "type": "query"
      },
      {
        "current": {},
        "datasource": {
          "type": "prometheus",
          "uid": "${DS_PROMETHEUS}"
        },
        "definition": "label_values(kube_namespace_labels{cluster=~\"$cluster\"},namespace)",
        "hide": 0,
        "includeAll": false,
        "label": "Namespace",
        "multi": false,
        "name": "namespace",
        "options": [],
        "query": {
          "query": "label_values(kube_namespace_labels{cluster=~\"$cluster\"},namespace)",
          "refId": "StandardVariableQuery"
        },
        "refresh": 1,
        "regex": "(.*)",
        "skipUrlSync": false,
        "sort": 5,
        "type": "query"
      }
    ]
  },
  "time": {
    "from": "now-6h",
    "to": "now"
  },
  "timepicker": {},
  "timezone": "",
  "title": "Namespace Resources Usage (vs Quotas)",
  "uid": "M_-46zKnzasdf",
  "version": 26,
  "weekStart": ""
}