查看Linux Cpu软中断脚本

代码如下:

#!/bin/sh
# filename softirqs_status.sh

PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH

interrupts_=cat /proc/interrupts |grep -E "CPU0|em[0-9]{1,2}.*-[0-9]{1,3}$|eth[0-9]{1,2}.*-[0-9]{1,3}$|p[0-9]{1,2}p[0-9]{1,2}.*-[0-9]{1,3}$|nvme" |cat -s |column -t 
#interrupts_=cat /proc/interrupts |grep -E "CPU0|em[0-9]{1,2}.*-[0-9]{1,3}$|eth[0-9]{1,2}.*-[0-9]{1,3}$|p[0-9]{1,2}p[0-9]{1,2}.*-[0-9]{1,3}$" |cat -s |column -t 
#interrupts_=cat /proc/interrupts |grep -E "CPU0|em[0-9]{1,2}|eth[0-9]{1,2}|p[0-9]{1,2}p[0-9]{1,2}" |grep -i  "TxRx" |cat -s |column -t 
interrupts_=echo "${interrupts_}" |awk '{ if(NR == 1){one=$0;gsub(one, "- &", $0); print $0}else{print $0}}' |cat -s |column -t 
interrupts_=echo "${interrupts_}" |awk '{ for(i=2;i<=NF;i++){ if( $i ~ /^[[:digit:]]*$/ && $i >= 1000 && $i < 1000000 ){$i=int( $i / 1000 + 1)"K"}else if( $i ~ /^[[:digit:]]*$/ && $i >= 1000000 ){$i=int( $i / 1000000)"M"}}; print $0 }'
echo "${interrupts_}" |sed 's/CPU/U/g' |column -t

echo

cpu_c=expr $(cat /proc/cpuinfo |grep -i processor |wc -l) + 1 ;

softirqs_=cat /proc/softirqs |grep -E 'TX|RX|CPU' 
softirqs_=echo "${softirqs_}" |awk -v cpu_c=$cpu_c '{ if(NR == 1){one=$0;gsub(one, "- &", $0)}; for(i=1;i<=cpu_c;i++){print $i} }' 
softirqs_=echo "${softirqs_}" |xargs -n $cpu_c |column -t 
softirqs_=echo "${softirqs_}" |awk '{ for(i=2;i<=NF;i++){ if( $i ~ /^[[:digit:]]*$/ && $i >= 1000 && $i < 1000000 ){$i=int( $i / 1000 + 1)"K"}else if( $i ~ /^[[:digit:]]*$/ && $i >= 1000000 ){$i=int( $i / 1000000)"M"}}; print $0 }'
echo "${softirqs_}" |sed 's/CPU/U/g' |column -t

echo

显示结果如下

 bash /tmp/softirqs_status.sh
-    U0   U1  U2  U3  U4  U5  U6  U7  U8  U9  U10  U11  U12  U13  U14  U15  U16  U17  U18  U19  U20  U21  U22  U23  U24  U25  U26  U27  U28  U29  U30  U31
89:  102  0   0   0   0   0   0   0   0   0   0    0    0    0    0    0    0    0    0    0    0    0    0    4M   0    0    0    0    0    0    0    0    IR-PCI-MSI-edge  em49-fp-0
90:  4K   0   0   0   6M  0   0   0   0   0   0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    IR-PCI-MSI-edge  em49-fp-1
91:  50   5M  0   0   0   0   0   0   0   0   0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    IR-PCI-MSI-edge  em49-fp-2
92:  51   0   7M  0   0   0   0   0   0   0   0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    IR-PCI-MSI-edge  em49-fp-3
93:  64   0   0   6M  0   0   0   0   0   0   0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    IR-PCI-MSI-edge  em49-fp-4
94:  32   0   0   0   3K  0   0   0   0   0   0    0    0    0    0    0    0    5M   0    0    0    0    0    0    0    0    0    0    0    0    0    0    IR-PCI-MSI-edge  em49-fp-5
95:  41   0   0   0   0   6M  0   0   0   0   0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    IR-PCI-MSI-edge  em49-fp-6
96:  53   0   0   0   0   0   6M  0   0   0   0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    IR-PCI-MSI-edge  em49-fp-7

-        U0  U1  U2   U3   U4  U5   U6   U7   U8   U9   U10  U11  U12  U13  U14  U15  U16  U17  U18  U19  U20  U21  U22  U23  U24  U25  U26  U27  U28  U29  U30  U31
NET_TX:  35  26  667  114  93  160  106  1    0    0    0    0    0    0    0    0    1    2K   0    2    0    0    0    51   0    0    0    0    0    0    0    0
NET_RX:  5K  5M  7M   6M   6M  6M   6M   707  720  462  542  507  541  866  392  332  127  5M   289  199  251  244  194  4M   204  3K   396  446  217  165  164  128

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注