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

864 B
Raw Blame History

本文作者:丁辉

检测CPU负载

介绍

CPU利用率可以用以下公式计算

CPU利用率(%) = 1 - (闲置时间 / 总时间) x 100

解释

  • 闲置时间在指定的时间段内CPU处于闲置状态的时间总和。
  • 总时间这个时间段的总时长通常包括CPU的工作时间和闲置时间。

脚本检测

  • 使用 Sysstat 工具检测 CPU 负载

    1. 安装 Sysstat

      • Centos

        yum -y install sysstat
        
      • Ubuntu

        apt-get -y install sysstat
        
    2. 执行脚本

      curl -sfL https://gitee.com/offends/Linux/raw/main/File/Shell/check-cpu-sysstat.sh | bash
      
  • 根据 /proc/stat 数据计算 CPU 负载

    curl -sfL https://gitee.com/offends/Linux/raw/main/File/Shell/check-cpu.sh | bash