可以的,不过要先澄清一下你说的 cpustat 是指哪一种:
cpustat(Go 写的性能工具,来自 tools 项目)仓库通常是:
github.com/uber-archive/cpustat
它本身 没有内置定时功能,但可以用 Linux 定时机制 来跑。
# 每 5 分钟采集一次
*/5 * * * * /usr/local/bin/cpustat -s 1 > /var/log/cpustat.log 2>&1
while true; do
cpustat -s 1 >> /var/log/cpustat.log
sleep 60
done
例如 mpstat:
# 每 10 秒一次,共 6 次
mpstat 10 6
或定时保存:
*/1 * * * * mpstat 1 1 >> /var/log/mpstat.log
# /etc/systemd/system/cpustat.timer
[Unit]
Description=Run cpustat every 5 min
[Timer]
OnCalendar=*:0/5
Persistent=true
[Install]
WantedBy=timers.target
# /etc/systemd/system/cpustat.service
[Service]
ExecStart=/usr/local/bin/cpustat -s 1
启用:
systemctl enable --now cpustat.timer
也可以直接用:
top / htopsar -u 1 10vmstat 1| 工具 | 是否支持定时 | 解决方式 |
|---|---|---|
| cpustat | ❌ 不支持 | cron / systemd / sleep |
| mpstat | ❌ | cron |
| sar | ✅(sa 自动采集) | 配 sysstat |
如果你能贴一下你用的是 哪个 cpustat 命令或安装方式,我可以给你更精确的定时方案。