在 CentOS 上,cpustat 通常是 sysstat 工具包的一部分(或类似性能工具)。下面给你几种常见且实用的导出方式,从简单到规范。
先确认你用的是哪种 cpustat:
which cpustat
rpm -qf $(which cpustat)
常见情况:
mpstat 同级)pcp / collectl)下面以 最常用方式 为准。
cpustat > cpu_usage.txt
如果支持持续采样:
cpustat 1 10 > cpu_usage.txt
表示:每 1 秒采样一次,共 10 次
ts(更清晰)cpustat 1 | ts '[%Y-%m-%d %H:%M:%S]' > cpu_usage.log
需要安装:
yum install -y moreutils
awk 自己加时间cpustat 1 | awk '{ print strftime("[%Y-%m-%d %H:%M:%S]"), $0 }' >> cpu_usage.log
cpustat 1 60 | tee cpu.csv
或更规范一点:
cpustat -c 1 60 > cpu.csv
如果
cpustat输出列不固定,建议用mpstat(见下方)
mpstat(sysstat 自带)mpstat -P ALL 1 10 > cpu_usage.txt
导出 CSV:
mpstat -P ALL 1 10 -o CSV > cpu.csv
nohup mpstat -P ALL 1 > /var/log/cpu_usage.log 2>&1 &
停止:
pkill mpstat
systemctl enable sysstat
systemctl start sysstat
sar -u 1 10 > cpu_usage.txt
sar -u -f /var/log/sa/sa$(date +%d)
| 场景 | 推荐方式 |
|---|---|
| 快速导出 | cpustat > file.txt |
| 带时间 | `cpustat 1 |
| 表格/分析 | mpstat -P ALL -o CSV |
| 长期监控 | sar |
| 生产环境 | sysstat + sar ⭐ |
如果你愿意,可以告诉我:
cpustat 的具体版本我可以给你完全定制化的导出方案。