Files
Linux/Docs/检测CPU负载.md
offends cee91802b3
Some checks failed
continuous-integration/drone Build is failing
synchronization
2025-08-25 15:57:40 +08:00

44 lines
864 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

> 本文作者:丁辉
# 检测CPU负载
## 介绍
CPU利用率可以用以下公式计算
CPU利用率(%) = 1 - (闲置时间 / 总时间) x 100
**解释**
- **闲置时间**在指定的时间段内CPU处于闲置状态的时间总和。
- **总时间**这个时间段的总时长通常包括CPU的工作时间和闲置时间。
## 脚本检测
- 使用 Sysstat 工具检测 CPU 负载
1. 安装 Sysstat
- Centos
```bash
yum -y install sysstat
```
- Ubuntu
```bash
apt-get -y install sysstat
```
2. 执行脚本
```bash
curl -sfL https://gitee.com/offends/Linux/raw/main/File/Shell/check-cpu-sysstat.sh | bash
```
- 根据 `/proc/stat` 数据计算 CPU 负载
```bash
curl -sfL https://gitee.com/offends/Linux/raw/main/File/Shell/check-cpu.sh | bash
```