Linux的IIO、記憶體、CPU狀態實時監控
阿新 • • 發佈:2022-03-04
pidstat命令監控一分鐘所有的狀態,排查問題足夠用.
使用ps命令監控當時的狀態.
指令碼如下
#!/bin/bash export MONTH=$(date +%m) export DAY=$(date +%d) export HOUR=$(date +%H) export MIN=$(date +%M) export SECOND=$(date +%S) # pidstat monitor mkdir -p /opt/scripts/ps_threads.log/pidstatlog/${MONTH}/${DAY}/${HOUR} pidstat -u -l 5 12 &> /opt/scripts/ps_threads.log/pidstatlog/${MONTH}/${DAY}/${HOUR}/cpu${MIN}_${SECOND}.log & # pid io pidstat -d -l 5 12 &> /opt/scripts/ps_threads.log/pidstatlog/${MONTH}/${DAY}/${HOUR}/io${MIN}_${SECOND}.log & # mpstat monitor mkdir -p /opt/scripts/ps_threads.log/mpstatlog/${MONTH}/${DAY}/${HOUR} mpstat -P ALL 5 12 &> /opt/scripts/ps_threads.log/mpstatlog/${MONTH}/${DAY}/${HOUR}/${MIN}_${SECOND}.log & for i in $(seq 2);do export MIN=$(date +%M) export SECOND=$(date +%S) mkdir -p /opt/scripts/ps_threads.log/pslog/${MONTH}/${DAY}/${HOUR} echo ${MONTH}-${DAY}-${HOUR}-${MIN}-${SECOND} > /opt/scripts/ps_threads.log/pslog/${MONTH}/${DAY}/${HOUR}/${MIN}_${SECOND}.log ps -efL >> /opt/scripts/ps_threads.log/pslog/${MONTH}/${DAY}/${HOUR}/${MIN}_${SECOND}.log # memory top 10 echo "memory top 10" >> /opt/scripts/ps_threads.log/pslog/${MONTH}/${DAY}/${HOUR}/${MIN}_${SECOND}.log ps -A --sort -rss -o comm,pmem,pcpu |uniq -c |head -10 >> /opt/scripts/ps_threads.log/pslog/${MONTH}/${DAY}/${HOUR}/${MIN}_${SECOND}.log # cpu top 10 echo "cpu top 10" >> /opt/scripts/ps_threads.log/pslog/${MONTH}/${DAY}/${HOUR}/${MIN}_${SECOND}.log ps -A --sort -%cpu -o comm,pmem,pcpu |uniq -c |head -10 >> /opt/scripts/ps_threads.log/pslog/${MONTH}/${DAY}/${HOUR}/${MIN}_${SECOND}.log sleep 20 done find /opt/scripts/ps_threads.log -name "*.log" -mtime +7 -exec rm -f {} \;