温馨提示×

centos cpustat怎么输出到文件

小樊
44
2026-10-20 18:14:41
栏目: 智能运维

在 CentOS 里,cpustat 通常是 sysstat 工具包里的命令(也有同名其他工具,但最常见的是 sysstat 的 mpstat/sar 类工具;如果你指的是 cpustat 这个命令,一般用法类似)。
把输出写到文件,本质就是 重定向或让命令自己支持日志。

下面分几种常见情况:


一、直接重定向到文件(最常用)

cpustat > cpu.log

或追加:

cpustat >> cpu.log

如果 cpustat 需要参数(例如间隔和次数):

cpustat 1 10 > cpu.log

表示每 1 秒采样一次,共 10 次。


二、后台运行并输出到文件

cpustat 1 > cpu.log 2>&1 &
  • 2>&1:把错误输出也写进文件
  • &:后台运行

查看进程:

jobs
ps aux | grep cpustat

停止:

kill %1

三、结合 nohup(断开终端也运行)

nohup cpustat 1 > cpu.log 2>&1 &

四、如果是 sysstat 的 mpstat

很多人把 mpstat 当成 cpu 统计工具:

mpstat 1 10 > cpu.log

或记录到 sysstat 日志(自动):

sar -u 1 10 > cpu.log

五、定时持续采集(cron 示例)

* * * * * /usr/bin/cpustat 1 60 >> /var/log/cpu.log

每分钟采集 60 秒。


如果你说的 不是 sysstat 的 cpustat,而是某个特定工具(比如 github.com/uber-common/cpustat),告诉我一下,我可以给你精确命令。

0 踩