Grafana dashboard: Container CPU Usage vs Throttling Percentage
Description: Detect/Diagnose CPU throttling for containers

This dashboard has two panes to view Container CPU and Container Percent Throttling on the same graph.  This allows you to see containers which could be subject to CFS throttling and could require their CPU limits increased.

{
  "__inputs": [],
  "__requires": [
    {
      "type": "grafana",
      "id": "grafana",
      "name": "Grafana",
      "version": "6.5.2"
    },
    {
      "type": "panel",
      "id": "graph",
      "name": "Graph",
      "version": ""
    },
    {
      "type": "datasource",
      "id": "prometheus",
      "name": "Prometheus",
      "version": "1.0.0"
    }
  ],
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": "-- Grafana --",
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      }
    ]
  },
  "editable": true,
  "gnetId": 11848,
  "graphTooltip": 0,
  "id": null,
  "iteration": 1583331206946,
  "links": [],
  "panels": [
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "datasource": "$cluster",
      "fill": 1,
      "fillGradient": 0,
      "gridPos": {
        "h": 8,
        "w": 24,
        "x": 0,
        "y": 0
      },
      "hiddenSeries": false,
      "id": 2,
      "legend": {
        "alignAsTable": true,
        "avg": true,
        "current": true,
        "max": true,
        "min": true,
        "rightSide": true,
        "show": true,
        "total": false,
        "values": true
      },
      "lines": true,
      "linewidth": 1,
      "nullPointMode": "null",
      "options": {
        "dataLinks": []
      },
      "percentage": false,
      "pointradius": 2,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [
        {
          "alias": "/Throttle/",
          "yaxis": 2
        }
      ],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "expr": "rate(container_cpu_usage_seconds_total{namespace=~\"$namespace\", pod_name=~\"$pod\", container_name=~\"$container\"}[1m])",
          "legendFormat": "CPU Cores Usage {{pod_name}} {{container_name}}",
          "refId": "B"
        },
        {
          "expr": "sum by (namespace,pod_name, container_name) ((container_cpu_cfs_throttled_periods_total{container_name=~\"$container\", pod_name=~\"$pod\", namespace=\"$namespace\"} / container_cpu_cfs_periods_total{container_name=~\"$container\", pod_name=~\"$pod\", namespace=\"$namespace\"}) * 100)",
          "legendFormat": "Throttle Percent {{pod_name}} {{container_name}}",
          "refId": "A"
        }
      ],
      "thresholds": [],
      "timeFrom": null,
      "timeRegions": [],
      "timeShift": null,
      "title": "CPU Usage vs Throttling Percent",
      "tooltip": {
        "shared": true,
        "sort": 0,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "buckets": null,
        "mode": "time",
        "name": null,
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "format": "short",
          "label": "cpu cores",
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        },
        {
          "format": "percent",
          "label": "throttling percent",
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        }
      ],
      "yaxis": {
        "align": false,
        "alignLevel": null
      }
    },
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "datasource": "$cluster",
      "fill": 1,
      "fillGradient": 0,
      "gridPos": {
        "h": 8,
        "w": 24,
        "x": 0,
        "y": 8
      },
      "hiddenSeries": false,
      "id": 3,
      "legend": {
        "alignAsTable": true,
        "avg": true,
        "current": true,
        "max": true,
        "min": true,
        "rightSide": true,
        "show": true,
        "total": false,
        "values": true
      },
      "lines": true,
      "linewidth": 1,
      "nullPointMode": "null",
      "options": {
        "dataLinks": []
      },
      "percentage": false,
      "pointradius": 2,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [
        {
          "alias": "/Throttle/",
          "yaxis": 2
        }
      ],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "expr": "rate(container_cpu_usage_seconds_total{namespace=~\"$namespace2\", pod_name=~\"$pod2\", container_name=~\"$container2\"}[1m])",
          "legendFormat": "CPU Cores Usage {{pod_name}} {{container_name}}",
          "refId": "B"
        },
        {
          "expr": "sum by (namespace,pod_name, container_name) ((container_cpu_cfs_throttled_periods_total{container_name=~\"$container2\",pod_name=~\"$pod2\", namespace=\"$namespace2\"} / container_cpu_cfs_periods_total{container_name=~\"$container2\",pod_name=~\"$pod2\", namespace=\"$namespace2\"}) * 100)",
          "legendFormat": "Throttle Percent {{pod_name}} {{container_name}}",
          "refId": "A"
        }
      ],
      "thresholds": [],
      "timeFrom": null,
      "timeRegions": [],
      "timeShift": null,
      "title": "CPU Usage vs Throttling Percent",
      "tooltip": {
        "shared": true,
        "sort": 0,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "buckets": null,
        "mode": "time",
        "name": null,
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "format": "short",
          "label": "cpu cores",
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        },
        {
          "format": "percent",
          "label": "throttling percent",
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        }
      ],
      "yaxis": {
        "align": false,
        "alignLevel": null
      }
    }
  ],
  "refresh": false,
  "schemaVersion": 21,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": [
      {
        "current": {
          "text": "cluster1.lab1",
          "value": "cluster1.lab1"
        },
        "hide": 0,
        "includeAll": false,
        "label": null,
        "multi": false,
        "name": "cluster",
        "options": [],
        "query": "prometheus",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "type": "datasource"
      },
      {
        "allValue": null,
        "current": {},
        "datasource": "$cluster",
        "definition": "label_values(container_cpu_usage_seconds_total, namespace)",
        "hide": 0,
        "includeAll": false,
        "label": null,
        "multi": false,
        "name": "namespace",
        "options": [],
        "query": "label_values(container_cpu_usage_seconds_total, namespace)",
        "refresh": 2,
        "regex": "",
        "skipUrlSync": false,
        "sort": 1,
        "tagValuesQuery": "",
        "tags": [],
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      },
      {
        "allValue": null,
        "current": {},
        "datasource": "$cluster",
        "definition": "label_values(container_cpu_usage_seconds_total{namespace=\"$namespace\"}, pod_name)",
        "hide": 0,
        "includeAll": true,
        "label": null,
        "multi": true,
        "name": "pod",
        "options": [],
        "query": "label_values(container_cpu_usage_seconds_total{namespace=\"$namespace\"}, pod_name)",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "tagValuesQuery": "",
        "tags": [],
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      },
      {
        "allValue": null,
        "current": {},
        "datasource": "$cluster",
        "definition": "label_values(container_cpu_usage_seconds_total{namespace=\"$namespace\", pod_name=~\"$pod\"}, container_name)",
        "hide": 0,
        "includeAll": true,
        "label": null,
        "multi": true,
        "name": "container",
        "options": [],
        "query": "label_values(container_cpu_usage_seconds_total{namespace=\"$namespace\", pod_name=~\"$pod\"}, container_name)",
        "refresh": 2,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "tagValuesQuery": "",
        "tags": [],
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      },
      {
        "allValue": null,
        "current": {},
        "datasource": "$cluster",
        "definition": "label_values(container_cpu_usage_seconds_total, namespace)",
        "hide": 0,
        "includeAll": false,
        "label": null,
        "multi": false,
        "name": "namespace2",
        "options": [],
        "query": "label_values(container_cpu_usage_seconds_total, namespace)",
        "refresh": 2,
        "regex": "",
        "skipUrlSync": false,
        "sort": 1,
        "tagValuesQuery": "",
        "tags": [],
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      },
      {
        "allValue": null,
        "current": {},
        "datasource": "$cluster",
        "definition": "label_values(container_cpu_usage_seconds_total{namespace=\"$namespace2\"}, pod_name)",
        "hide": 0,
        "includeAll": true,
        "label": null,
        "multi": true,
        "name": "pod2",
        "options": [],
        "query": "label_values(container_cpu_usage_seconds_total{namespace=\"$namespace2\"}, pod_name)",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "tagValuesQuery": "",
        "tags": [],
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      },
      {
        "allValue": null,
        "current": {},
        "datasource": "$cluster",
        "definition": "label_values(container_cpu_usage_seconds_total{namespace=\"$namespace2\", pod_name=~\"$pod2\"}, container_name)",
        "hide": 0,
        "includeAll": true,
        "label": null,
        "multi": true,
        "name": "container2",
        "options": [],
        "query": "label_values(container_cpu_usage_seconds_total{namespace=\"$namespace2\", pod_name=~\"$pod2\"}, container_name)",
        "refresh": 2,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "tagValuesQuery": "",
        "tags": [],
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      }
    ]
  },
  "time": {
    "from": "now-3h",
    "to": "now"
  },
  "timepicker": {
    "refresh_intervals": [
      "5s",
      "10s",
      "30s",
      "1m",
      "5m",
      "15m",
      "30m",
      "1h",
      "2h",
      "1d"
    ]
  },
  "timezone": "utc",
  "title": "Container CPU Usage vs Throttling Percentage",
  "uid": "kOjTBvyZk",
  "version": 18,
  "description": "Detect/Diagnose CPU throttling for containers"
}