티스토리 뷰

카테고리 없음

Grafana Dashboard

자바바라 2025. 9. 16. 21:45

Kubernetes (kube-state-metrics, node-exporter 등) 기반.

- 변수 설정:
  - `namespace`: 네임스페이스 목록을 쿼리하여 선택 (단일 선택).
  - `node`: 선택된 네임스페이스에 Pod가 배포된 Node 목록만 필터링하여 표시 (단일 선택). 이렇게 하면 네임스페이스 선택 시 관련 Node만 보여준다.

- 패널 구성:
  - Node CPU/Memory Usage: 시계열 그래프로 현재 사용량(usage) 표시.
  - CPU/Memory Limit (Capacity): Node의 전체 용량(allocatable/limit) 표시.
  - CPU/Memory Request: 선택된 네임스페이스의 Pod들이 해당 Node에 요청한 총 자원(request) 표시.
  - Pods Status: 선택된 네임스페이스와 Node의 Pod 목록을 테이블로 표시 (상태: Running, Pending 등 phase 기반, 색상으로 구분).

이 JSON을 Grafana에 import. (Grafana UI에서 Dashboard > Import > JSON 붙여넣기). 데이터 소스 UID는 "prometheus"로 설정되어 있으니, 실제 환경에 맞게 조정하세요. PromQL 쿼리는 표준 Kubernetes 메트릭스를 사용.

{
  "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"
      }
    ]
  },
  "description": "Kubernetes Node and Pod Dashboard",
  "editable": true,
  "fiscalYearStartMonth": 0,
  "graphTooltip": 0,
  "links": [],
  "liveNow": false,
  "panels": [
    {
      "datasource": {
        "type": "prometheus",
        "uid": "prometheus"
      },
      "fieldConfig": {
        "defaults": {},
        "overrides": []
      },
      "gridPos": {
        "h": 9,
        "w": 12,
        "x": 0,
        "y": 0
      },
      "id": 1,
      "options": {
        "colorMode": "value",
        "colorScheme": "green",
        "graphMode": "area",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto"
      },
      "pluginVersion": "9.0.0",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "prometheus"
          },
          "editorMode": "code",
          "expr": "sum(rate(node_cpu_seconds_total{instance=~\"$node\", job=\"node-exporter\"}[5m])) / count(node_cpu_seconds_total{instance=~\"$node\", job=\"node-exporter\", mode=\"idle\"}) * 100",
          "legendFormat": "CPU Usage %",
          "range": true,
          "refId": "A"
        }
      ],
      "title": "Node CPU Usage",
      "type": "timeseries"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "prometheus"
      },
      "fieldConfig": {
        "defaults": {},
        "overrides": []
      },
      "gridPos": {
        "h": 9,
        "w": 12,
        "x": 12,
        "y": 0
      },
      "id": 2,
      "options": {
        "colorMode": "value",
        "colorScheme": "green",
        "graphMode": "area",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto"
      },
      "pluginVersion": "9.0.0",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "prometheus"
          },
          "editorMode": "code",
          "expr": "(1 - (sum(node_memory_MemAvailable_bytes{instance=~\"$node\"}) / sum(node_memory_MemTotal_bytes{instance=~\"$node\"}))) * 100",
          "legendFormat": "Memory Usage %",
          "range": true,
          "refId": "A"
        }
      ],
      "title": "Node Memory Usage",
      "type": "timeseries"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "prometheus"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          },
          "unit": "short"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 4,
        "w": 6,
        "x": 0,
        "y": 9
      },
      "id": 3,
      "options": {
        "colorMode": "background",
        "graphMode": "none",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto"
      },
      "pluginVersion": "9.0.0",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "prometheus"
          },
          "editorMode": "code",
          "expr": "kube_node_status_capacity{resource=\"cpu\", node=\"$node\"}",
          "refId": "A"
        }
      ],
      "title": "CPU Limit (Capacity)",
      "type": "stat"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "prometheus"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          },
          "unit": "bytes"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 4,
        "w": 6,
        "x": 6,
        "y": 9
      },
      "id": 4,
      "options": {
        "colorMode": "background",
        "graphMode": "none",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto"
      },
      "pluginVersion": "9.0.0",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "prometheus"
          },
          "editorMode": "code",
          "expr": "kube_node_status_capacity{resource=\"memory\", node=\"$node\"}",
          "refId": "A"
        }
      ],
      "title": "Memory Limit (Capacity)",
      "type": "stat"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "prometheus"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "yellow",
                "value": 50
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          },
          "unit": "short"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 4,
        "w": 6,
        "x": 12,
        "y": 9
      },
      "id": 5,
      "options": {
        "colorMode": "background",
        "graphMode": "none",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto"
      },
      "pluginVersion": "9.0.0",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "prometheus"
          },
          "editorMode": "code",
          "expr": "sum(kube_pod_container_resource_requests{resource=\"cpu\", node=\"$node\", namespace=\"$namespace\"})",
          "refId": "A"
        }
      ],
      "title": "CPU Request (Sum)",
      "type": "stat"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "prometheus"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "yellow",
                "value": 50
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          },
          "unit": "bytes"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 4,
        "w": 6,
        "x": 18,
        "y": 9
      },
      "id": 6,
      "options": {
        "colorMode": "background",
        "graphMode": "none",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto"
      },
      "pluginVersion": "9.0.0",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "prometheus"
          },
          "editorMode": "code",
          "expr": "sum(kube_pod_container_resource_requests{resource=\"memory\", node=\"$node\", namespace=\"$namespace\"})",
          "refId": "A"
        }
      ],
      "title": "Memory Request (Sum)",
      "type": "stat"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "prometheus"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": "auto",
            "displayMode": "auto",
            "filterable": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byRegexp",
              "options": "phase"
            },
            "properties": [
              {
                "id": "custom.displayMode",
                "value": "color-background"
              },
              {
                "id": "color",
                "value": {
                  "fixedColor": "green",
                  "mode": "fixed"
                }
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 10,
        "w": 24,
        "x": 0,
        "y": 13
      },
      "id": 7,
      "options": {
        "showHeader": true,
        "sortBy": [
          {
            "desc": true,
            "displayName": "Pod"
          }
        ]
      },
      "pluginVersion": "9.0.0",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "prometheus"
          },
          "editorMode": "code",
          "expr": "kube_pod_info{namespace=\"$namespace\", node=\"$node\"}",
          "format": "table",
          "instant": true,
          "refId": "A"
        },
        {
          "datasource": {
            "type": "prometheus",
            "uid": "prometheus"
          },
          "editorMode": "code",
          "expr": "kube_pod_status_phase{namespace=\"$namespace\", node=\"$node\"}",
          "format": "table",
          "instant": true,
          "refId": "B"
        }
      ],
      "title": "Pods on Node (Status)",
      "transformations": [
        {
          "id": "organize",
          "options": {
            "excludeByRegexp": {
              "pod": "false"
            },
            "indexByName": {
              "node": 0,
              "namespace": 1,
              "pod": 2,
              "created_by_kind": 3,
              "created_by_name": 4,
              "host_ip": 5,
              "phase": 6,
              "uid": 7
            },
            "renameByName": {
              "Phase": "Status"
            }
          }
        }
      ],
      "type": "table"
    }
  ],
  "refresh": "30s",
  "schemaVersion": 30,
  "tags": [
    "kubernetes"
  ],
  "templating": {
    "list": [
      {
        "allValue": null,
        "current": {},
        "datasource": {
          "type": "prometheus",
          "uid": "prometheus"
        },
        "definition": "label_values(kube_pod_info, namespace)",
        "hide": 0,
        "includeAll": false,
        "label": "Namespace",
        "multi": false,
        "name": "namespace",
        "options": [],
        "query": {
          "query": "label_values(kube_pod_info, namespace)",
          "refId": "StandardVariableQuery"
        },
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 1,
        "type": "query"
      },
      {
        "allValue": null,
        "current": {},
        "datasource": {
          "type": "prometheus",
          "uid": "prometheus"
        },
        "definition": "label_values(kube_pod_info{namespace=\"$namespace\"}, node)",
        "hide": 0,
        "includeAll": false,
        "label": "Node",
        "multi": false,
        "name": "node",
        "options": [],
        "query": {
          "query": "label_values(kube_pod_info{namespace=\"$namespace\"}, node)",
          "refId": "StandardVariableQuery"
        },
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 1,
        "type": "query"
      }
    ]
  },
  "time": {
    "from": "now-6h",
    "to": "now"
  },
  "timepicker": {},
  "timezone": "",
  "title": "Kubernetes Node and Pod Dashboard",
  "uid": "k8s-node-pod-dashboard",
  "version": 1,
  "weekStart": ""
}

 추가 설명:
- 사용법: Grafana에서 네임스페이스를 선택하면 Node 드롭다운이 업데이트. Node를 선택하면 자원 현황과 Pod 테이블이 자동으로 필터링.
- PromQL 쿼리 세부:
  - CPU Usage: Node의 CPU 사용률 (%).
  - Memory Usage: Node의 메모리 사용률 (%).
  - Limit: `kube_node_status_capacity`로 Node 용량.
  - Request: `kube_pod_container_resource_requests`로 네임스페이스 내 Pod 요청 합계.
  - Pod Status: `kube_pod_info`와 `kube_pod_status_phase`로 Pod 이름, 상태(Phase) 표시. 테이블에서 Status 열로 phase를 매핑 (Running: 녹색 등 커스텀 가능).

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG more
«   2026/02   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
글 보관함