美文网首页K8sk8s
统计k8s cpu mem disk脚本

统计k8s cpu mem disk脚本

作者: Joening | 来源:发表于2022-03-02 16:07 被阅读0次

    脚本内容

    #!/bin/bash
    NODE_LISTS=`kubectl get nodes | awk 'NR>1{print $1}'`
    NS_LISTS="jd-iam jd-tpaas kafka-system kube-node-lease   kube-public  kube-system  mysql  pgo  pgo-rds  redis  redis-operator-system  tpaas-es  tpaas-federation  tpaas-kafka  tpaas-mongodb  tpaas-rds  tpaas28-pg"
    showCpuMem(){
      for NS in ${NS_LISTS}
      do
        #echo "----------------$NS----------------------"
        for NODE in ${NODE_LISTS}
        do
          #echo "------------------$NODE-----------------------"
          kubectl describe node $NODE | grep "$NS" | awk '$1 == "'$NS'"{print $0}'
        done | awk 'BEGIN{C=0;M=0} {C+=$3~/m$/?$3/1000:$3;M+=$7~/M/?$7/1024:$7}END{print "'$NS':","cpu:"C"C","mem:"M"G"}'
      done
    }
    showDisk(){
      for NS in ${NS_LISTS}
      do
        kubectl get pv | grep "$NS/" | awk -v D=0 '{D+=$2}END{print "'$NS':"D"G"}'
      done
    }
    showCpuMem
    showDisk
    
    

    执行脚本结果

    [root@jdos-repo1 tmp]# sh check.sh 
    jd-iam: cpu:0C mem:0G
    jd-tpaas: cpu:1.3C mem:2.37891G
    kafka-system: cpu:3C mem:12G
    kube-node-lease: cpu:0C mem:0G
    kube-public: cpu:0C mem:0G
    kube-system: cpu:2.849C mem:0.694336G
    mysql: cpu:10.12C mem:14.1875G
    pgo: cpu:0C mem:0G
    pgo-rds: cpu:0.4C mem:0.5G
    redis: cpu:11.4C mem:7.5G
    redis-operator-system: cpu:6C mem:9G
    tpaas-es: cpu:17.3C mem:46G
    tpaas-federation: cpu:0.3C mem:0.1875G
    tpaas-kafka: cpu:12.5C mem:25G
    tpaas-mongodb: cpu:1C mem:1G
    tpaas-rds: cpu:0C mem:0G
    tpaas28-pg: cpu:0C mem:0G
    jd-iam:0G
    jd-tpaas:0G
    kafka-system:0G
    kube-node-lease:0G
    kube-public:0G
    kube-system:0G
    mysql:320G
    pgo:0G
    pgo-rds:0G
    redis:120G
    redis-operator-system:0G
    tpaas-es:120G
    tpaas-federation:0G
    tpaas-kafka:240G
    tpaas-mongodb:0G
    tpaas-rds:0G
    tpaas28-pg:0G
    

    相关文章

      网友评论

        本文标题:统计k8s cpu mem disk脚本

        本文链接:https://www.haomeiwen.com/subject/mnxerrtx.html