在Debian自动化运维中,cpustat可通过以下方式实践:
#!/bin/bash
interval=300 # 5分钟
output_file="/var/log/cpu_usage.log"
while true; do
cpustat -c -o $output_file >> $output_file
sleep $interval
done
# 编辑crontab
crontab -e
# 添加任务:每小时运行一次脚本
0 * * * * /path/to/cpu_monitor.sh
ssh user@remote_host "cpustat -c > /tmp/remote_cpu.log"