系统cpu、内存、磁盘检查

本文介绍了一个简单的Bash脚本,用于实时监控Linux系统的CPU使用率、内存使用率和磁盘空间,以及报告CPU核心数和总磁盘容量。
摘要由CSDN通过智能技术生成

简单脚本统计

#!/bin/bash

# 获取磁盘使用率
disk_usage=$(df -h --total | tail -n 1 | awk '{print $5}')
#echo "磁盘使用率: ${disk_usage}"

cpuch=$(top -b -n 1 | awk '/^%Cpu/ {
    total_usage = $2 + $4
    print total_usage
}')
free_sum=`free -m|grep Mem:|awk '{print $3/$2 }'`
result=$(echo "$free_sum * 100" | bc)
#printf "内存使用率: %.2f%%\n" $result
memin=$(printf "%.2f%%\n" $result)
cpu_cores=$(nproc)
#echo "CPU核数: $cpu_cores"
total_disk=$(df -h --total | tail -n 1 | awk '{print $2}')
#echo "磁盘总量: $total_disk"
mem_count=$(free -m|grep Mem|awk '{print $2}')
echo "cpu使用率 磁盘使用率 内存使用率 cpu核数 内存总大小M 磁盘总大小
${cpuch}% ${disk_usage} ${memin} $cpu_cores ${mem_count}M ${total_disk}"
 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值