节点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%。
相关推荐
Configure-Handler5 分钟前
buildroot System configuration
java·服务器·数据库
津津有味道21 分钟前
易语言TCP服务端接收刷卡数据并向客户端读卡器发送指令
服务器·网络协议·tcp·易语言
Fᴏʀ ʏ꯭ᴏ꯭ᴜ꯭.1 小时前
Keepalived VIP迁移邮件告警配置指南
运维·服务器·笔记
酣大智1 小时前
接口模式参数
运维·网络·网络协议·tcp/ip
Genie cloud1 小时前
1Panel SSL证书申请完整教程
服务器·网络协议·云计算·ssl
一只自律的鸡2 小时前
【Linux驱动】bug处理 ens33找不到IP
linux·运维·bug
17(无规则自律)2 小时前
【CSAPP 读书笔记】第二章:信息的表示和处理
linux·嵌入式硬件·考研·高考
!chen2 小时前
linux服务器静默安装Oracle26ai
linux·运维·服务器
莫大3302 小时前
2核2G云服务器PHP8.5+MySQL9.0+Nginx(LNMP)安装WordPress网站详细教程
运维·服务器·nginx
24zhgjx-lxq2 小时前
华为ensp:MSTP
网络·安全·华为·hcip·ensp