This commit is contained in:
21
File/Shell/check-cpu-sysstat.sh
Normal file
21
File/Shell/check-cpu-sysstat.sh
Normal file
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
|
||||
#############################################################################################
|
||||
# 用途: 使用 Sysstat 工具检测 CPU 负载
|
||||
# 作者: 丁辉
|
||||
# 更新时间: 2024-05-10
|
||||
#############################################################################################
|
||||
|
||||
# 获取 CPU 使用情况
|
||||
cpu_usage=$(mpstat 1 1 | awk '/Average:/ {print 100 - $12}')
|
||||
|
||||
# 输出 CPU 使用率
|
||||
echo "当前 CPU 使用率为: $cpu_usage%"
|
||||
|
||||
# 根据需要设置 CPU 使用率的阈值
|
||||
threshold=80
|
||||
|
||||
# 检查 CPU 使用率是否超过阈值
|
||||
if (( $(echo "$cpu_usage > $threshold" | bc -l) )); then
|
||||
echo "警告: CPU 使用率超过 ${threshold}%!"
|
||||
fi
|
Reference in New Issue
Block a user