26Z28b3

QK·2026년 8월 28일
kubectl get pods -A -o json | jq -r '
  def parse_cpu:
    if . == null then 0
    elif type == "number" then . * 1000
    elif endswith("m") then (.[0:-1] | tonumber)
    elif endswith("u") then (.[0:-1] | tonumber / 1000)
    elif endswith("n") then (.[0:-1] | tonumber / 1000000)
    else ((. | tonumber) * 1000) end;

  def parse_mem:
    if . == null then 0
    elif type == "number" then (. / 1024 / 1024)
    elif endswith("Ki") then (.[0:-2] | tonumber / 1024)
    elif endswith("Mi") then (.[0:-2] | tonumber)
    elif endswith("Gi") then (.[0:-2] | tonumber * 1024)
    elif endswith("Ti") then (.[0:-2] | tonumber * 1024 * 1024)
    elif endswith("K") or endswith("k") then (.[0:-1] | tonumber * 1000 / 1048576)
    elif endswith("M") or endswith("m") then (.[0:-1] | tonumber * 1000000 / 1048576)
    elif endswith("G") or endswith("g") then (.[0:-1] | tonumber * 1000000000 / 1048576)
    else ((. | tonumber) / 1024 / 1024) end;

  ["NAMESPACE", "CPU_REQ(CORES)", "MEM_REQ(GIB)"],
  (
    [ .items[] | select(.status.phase=="Running") | {
        ns: .metadata.namespace,
        cpu: ([ (.spec.containers // [])[].resources.requests.cpu ] | map(parse_cpu) | add // 0),
        mem: ([ (.spec.containers // [])[].resources.requests.memory ] | map(parse_mem) | add // 0)
    } ]
    | group_by(.ns)
    | map({
        ns: .[0].ns,
        cpu_num: ((map(.cpu) | add) / 1000),
        mem_num: ((map(.mem) | add) / 1024)
      })
    | sort_by(.cpu_num) | reverse
    | .[] | [.ns, (.cpu_num * 100 | round / 100), (.mem_num * 100 | round / 100)]
  )
  | @tsv
' | column -t
profile
engineer

0개의 댓글