节点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%。
相关推荐
数字护盾(和中)2 分钟前
攻击链识别:企业抵御快攻型勒索攻击的关键能力
网络·安全·web安全
志栋智能3 分钟前
超自动化运维:如何降低人为错误?
大数据·运维·网络·人工智能·自动化
达达爱吃肉16 分钟前
claude 接入deepseek 运行报错
java·服务器·前端
都市放羊26 分钟前
网络小白自学网工——因特网与网络互联技术
网络·笔记·自学
武器大师7227 分钟前
从零开始在 Linux 上编译运行 lvgljs 图形界面项目
linux·运维·服务器
剑神一笑29 分钟前
Linux free 命令深度解析:从内存监控到 OOM 排查的完整指南
linux·运维·服务器
叶半欲缺1 小时前
软考-中级信息安全工程师全战备资源包介绍和分享
网络·web安全
似水এ᭄往昔1 小时前
【Linux网络编程】--计算机网络基础
linux·网络·计算机网络
qq_312920111 小时前
服务器被攻击!完整安全加固清单汇总
运维·服务器·安全
xlq223221 小时前
61 cookie session传输层
网络