节点request资源统计脚本

powershell 复制代码
#!/bin/bash

for node in `kubectl get node | grep node | awk '{print $1}'` 
do
    total_cpu=`kubectl describe node $node | grep cpu | awk '{print $2}' | sed -n '1p'`
    used_cpuM=`kubectl describe node $node | grep "cpu " | awk '{print $2}'| cut -d 'm' -f 1`
    used_cpu=`expr $used_cpuM / 1024`
    used_cpu_ratio=`kubectl describe node $node | grep "cpu " | awk '{print $3}'`

    total_memK=`kubectl describe node $node | grep " memory:" | awk '{print $2}' | sed -n '1p' | cut -d 'K' -f 1`
    total_mem=`expr $total_memK / 1024 / 1024`
    used_memMm=`kubectl describe node $node | grep " memory  " | awk '{print $2}'`

    Mm=`echo $used_memMm | grep M | wc -l`
    if [ $Mm == 0 ];then
        if [ `echo $used_memMm | grep m | wc -l` == 0 ];then
            used_mem=`expr $used_memMm / 1024 / 1024 / 1024`
        else
            used_mem_Mm=`echo $used_memMm | cut -d 'm' -f 1`
            used_mem=`expr $used_mem_Mm / 1024 / 1024 / 1024 / 1024`
        fi
    else
        used_mem_Mm=`echo $used_memMm | cut -d 'M' -f 1`
        used_mem=`expr $used_mem_Mm / 1024`
    fi
    used_mem_ratio=`kubectl describe node $node | grep " memory  " | awk '{print $3}'`

    echo "--------"
    echo "$node"
    echo "cpu:  [ total:$total_cpu ] [ used:$used_cpu $used_cpu_ratio ]"
    echo "mem:  [ total:$total_mem ] [ used:$used_mem $used_mem_ratio ]"
done
powershell 复制代码
包含两个节点(node01和node02)的集群的资源使用情况
- node01:
  - CPU:总共有4个CPU核心,目前使用0个(使用率为2%)。
  - 内存:总共有2GB的内存,目前使用0GB(使用率为2%)。

- node02:
  - CPU:总共有16个CPU核心,目前使用0个(使用率为0%)。
  - 内存:总共有5GB的内存,目前使用0GB(使用率为0%)。

这些信息显示了每个节点上CPU和内存资源的总量以及当前使用量。
根据给出的信息,节点01有4个CPU核心和2GB的内存,而节点02有16个CPU核心和5GB的内存。
目前,两个节点的资源使用率都非常低,都是0% 或2%。
相关推荐
是小胡嘛1 天前
C++之Any类的模拟实现
linux·开发语言·c++
口袋物联1 天前
设计模式之工厂模式在 C 语言中的应用(含 Linux 内核实例)
linux·c语言·设计模式·简单工厂模式
qq_479875431 天前
X-Macros(1)
linux·服务器·windows
笨笨聊运维1 天前
CentOS官方不维护版本,配置python升级方法,无损版
linux·python·centos
jun_bai1 天前
python写的文件备份网盘程序
运维·服务器·网络
爱吃牛肉的大老虎1 天前
网络传输架构之gRPC讲解
网络·架构
Warren981 天前
Python自动化测试全栈面试
服务器·网络·数据库·mysql·ubuntu·面试·职场和发展
HIT_Weston1 天前
39、【Ubuntu】【远程开发】拉出内网 Web 服务:构建静态网页(二)
linux·前端·ubuntu
欢喜躲在眉梢里1 天前
CANN 异构计算架构实操指南:从环境部署到 AI 任务加速全流程
运维·服务器·人工智能·ai·架构·计算
云飞云共享云桌面1 天前
无需配置传统电脑——智能装备工厂10个SolidWorks共享一台工作站
运维·服务器·前端·网络·算法·电脑