Grafana dashboard: kubernetes pod status
Description: k8s的重启和pod状态

k8s的重启和pod状态
```
(sum(kube_pod_container_status_waiting_reason{reason!="ContainerCreating",namespace=~"$namespace",pod=~"$pod"} ) by (reason,namespace,pod) >0) 
*on(pod) group_right(reason) sum(kube_pod_info) by (pod,node,host_ip,pod_ip,namespace) 
or
(sum(kube_pod_container_status_waiting_reason{reason="ContainerCreating",namespace=~"$namespace",pod=~"$pod"} ) by (reason,namespace,pod) >0) 
-on(pod) group_right(reason) sum(kube_pod_info) by (pod,node,host_ip,pod_ip,namespace) 
```
and 
```
(sum(kube_pod_container_status_restarts_total{namespace=~"$namespace",pod=~"$pod"}) by(namespace,pod) *on(pod) group_right() sum(kube_pod_info) by (pod,node,host_ip,pod_ip,namespace) 
-sum(kube_pod_container_status_restarts_total{namespace=~"$namespace",pod=~"$pod"} offset 5m) by(namespace,pod) *on(pod) group_right() sum(kube_pod_info) by (pod,node,host_ip,pod_ip,namespace))
```

{
  "__inputs": [
    {
      "name": "DS_VICTORIAMETRICS",
      "label": "victoriametrics",
      "description": "",
      "type": "datasource",
      "pluginId": "prometheus",
      "pluginName": "Prometheus"
    }
  ],
  "__elements": {},
  "__requires": [
    {
      "type": "grafana",
      "id": "grafana",
      "name": "Grafana",
      "version": "9.2.5"
    },
    {
      "type": "datasource",
      "id": "prometheus",
      "name": "Prometheus",
      "version": "1.0.0"
    },
    {
      "type": "panel",
      "id": "table",
      "name": "Table",
      "version": ""
    }
  ],
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": {
          "type": "grafana",
          "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": null,
  "links": [
    {
      "asDropdown": false,
      "icon": "external link",
      "includeVars": false,
      "keepTime": false,
      "tags": [],
      "targetBlank": false,
      "title": "blog",
      "tooltip": "",
      "type": "link",
      "url": "https://www.linuxea.com"
    }
  ],
  "liveNow": false,
  "panels": [
    {
      "collapsed": false,
      "gridPos": {
        "h": 1,
        "w": 24,
        "x": 0,
        "y": 0
      },
      "id": 8,
      "panels": [],
      "title": "重启次数/5m",
      "type": "row"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "${DS_VICTORIAMETRICS}"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": "auto",
            "displayMode": "auto",
            "inspect": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 9,
        "w": 24,
        "x": 0,
        "y": 1
      },
      "id": 4,
      "options": {
        "footer": {
          "fields": "",
          "reducer": [
            "sum"
          ],
          "show": false
        },
        "showHeader": true,
        "sortBy": [
          {
            "desc": true,
            "displayName": "Value"
          }
        ]
      },
      "pluginVersion": "9.2.5",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_VICTORIAMETRICS}"
          },
          "editorMode": "code",
          "exemplar": false,
          "expr": "(sum(kube_pod_container_status_restarts_total{namespace=~\"$namespace\",pod=~\"$pod\"}) by(namespace,pod) *on(pod) group_right() sum(kube_pod_info) by (pod,node,host_ip,pod_ip,namespace) \r\n-sum(kube_pod_container_status_restarts_total{namespace=~\"$namespace\",pod=~\"$pod\"} offset 5m) by(namespace,pod) *on(pod) group_right() sum(kube_pod_info) by (pod,node,host_ip,pod_ip,namespace)) > 0",
          "format": "table",
          "hide": true,
          "instant": true,
          "legendFormat": "重启次数/5m",
          "range": false,
          "refId": "A"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_VICTORIAMETRICS}"
          },
          "editorMode": "code",
          "exemplar": false,
          "expr": "(sum(kube_pod_container_status_restarts_total) by(namespace,pod) *on(pod) group_right() sum(kube_pod_info) by (pod,node,host_ip,pod_ip,namespace) \r\n-sum(kube_pod_container_status_restarts_total offset  5m) by(namespace,pod) *on(pod) group_right() sum(kube_pod_info) by (pod,node,host_ip,pod_ip,namespace))  > 0",
          "format": "table",
          "hide": false,
          "instant": true,
          "legendFormat": "重启次数/5m",
          "range": false,
          "refId": "B"
        }
      ],
      "title": "重启次数/15m",
      "type": "table"
    },
    {
      "collapsed": false,
      "gridPos": {
        "h": 1,
        "w": 24,
        "x": 0,
        "y": 10
      },
      "id": 6,
      "panels": [],
      "title": "Pod Status",
      "type": "row"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "${DS_VICTORIAMETRICS}"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": "auto",
            "displayMode": "auto",
            "inspect": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "namespace"
            },
            "properties": [
              {
                "id": "custom.align",
                "value": "auto"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "pod"
            },
            "properties": [
              {
                "id": "custom.align",
                "value": "auto"
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 15,
        "w": 24,
        "x": 0,
        "y": 11
      },
      "id": 2,
      "options": {
        "footer": {
          "fields": "",
          "reducer": [
            "sum"
          ],
          "show": false
        },
        "frameIndex": 0,
        "showHeader": true,
        "sortBy": [
          {
            "desc": false,
            "displayName": "namespace"
          }
        ]
      },
      "pluginVersion": "9.2.5",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "${DS_VICTORIAMETRICS}"
          },
          "editorMode": "code",
          "exemplar": false,
          "expr": "(sum(kube_pod_container_status_waiting_reason{reason!=\"ContainerCreating\",namespace=~\"$namespace\",pod=~\"$pod\"} ) by (reason,namespace,pod) >0) \r\n*on(pod) group_right(reason) sum(kube_pod_info) by (pod,node,host_ip,pod_ip,namespace) \r\nor\r\n(sum(kube_pod_container_status_waiting_reason{reason=\"ContainerCreating\",namespace=~\"$namespace\",pod=~\"$pod\"} ) by (reason,namespace,pod) >0) \r\n-on(pod) group_right(reason) sum(kube_pod_info) by (pod,node,host_ip,pod_ip,namespace) ",
          "format": "table",
          "hide": false,
          "instant": true,
          "legendFormat": "名称空间",
          "range": false,
          "refId": "B"
        }
      ],
      "title": "Pod Status ",
      "type": "table"
    }
  ],
  "schemaVersion": 37,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": [
      {
        "current": {},
        "datasource": {
          "type": "prometheus",
          "uid": "${DS_VICTORIAMETRICS}"
        },
        "definition": "label_values(origin_prometheus)",
        "hide": 0,
        "includeAll": false,
        "label": "K8S",
        "multi": false,
        "name": "origin_prometheus",
        "options": [],
        "query": {
          "query": "label_values(origin_prometheus)",
          "refId": "StandardVariableQuery"
        },
        "refresh": 2,
        "regex": "",
        "skipUrlSync": false,
        "sort": 5,
        "type": "query"
      },
      {
        "current": {},
        "datasource": {
          "type": "prometheus",
          "uid": "${DS_VICTORIAMETRICS}"
        },
        "definition": "label_values(kube_pod_container_info{origin_prometheus=~\"$origin_prometheus\"},namespace)",
        "hide": 0,
        "includeAll": true,
        "label": "namespace",
        "multi": false,
        "name": "namespace",
        "options": [],
        "query": {
          "query": "label_values(kube_pod_container_info{origin_prometheus=~\"$origin_prometheus\"},namespace)",
          "refId": "StandardVariableQuery"
        },
        "refresh": 2,
        "regex": "",
        "skipUrlSync": false,
        "sort": 5,
        "type": "query"
      },
      {
        "current": {},
        "datasource": {
          "type": "prometheus",
          "uid": "${DS_VICTORIAMETRICS}"
        },
        "definition": "label_values(kube_pod_container_info{origin_prometheus=~\"$origin_prometheus\",namespace=~\"$namespace\"},pod)",
        "hide": 0,
        "includeAll": true,
        "label": "pod",
        "multi": false,
        "name": "pod",
        "options": [],
        "query": {
          "query": "label_values(kube_pod_container_info{origin_prometheus=~\"$origin_prometheus\",namespace=~\"$namespace\"},pod)",
          "refId": "StandardVariableQuery"
        },
        "refresh": 2,
        "regex": "",
        "skipUrlSync": false,
        "sort": 5,
        "type": "query"
      }
    ]
  },
  "time": {
    "from": "now-5m",
    "to": "now"
  },
  "timepicker": {},
  "timezone": "",
  "title": "kubernetes pod status",
  "uid": "l-q5_7YVz",
  "version": 11,
  "weekStart": "",
  "gnetId": 18425,
  "description": "k8s的重启和pod状态"
}