/proc/net/netstat可读显示脚本

在查看centos机器的网络状态时,尝尝要看看计数器文件/proc/net/netstat,但是直接cat,如下显示

# cat /proc/net/netstat 
TcpExt: SyncookiesSent SyncookiesRecv SyncookiesFailed EmbryonicRsts PruneCalled RcvPruned OfoPruned OutOfWindowIcmps LockDroppedIcmps ArpFilter TW TWRecycled TWKilled PAWSPassive PAWSActive PAWSEstab DelayedACKs DelayedACKLocked DelayedACKLost ListenOverflows ListenDrops TCPPrequeued TCPDirectCopyFromBacklog TCPDirectCopyFromPrequeue TCPPrequeueDropped TCPHPHits TCPHPHitsToUser TCPPureAcks TCPHPAcks TCPRenoRecovery TCPSackRecovery TCPSACKReneging TCPFACKReorder TCPSACKReorder TCPRenoReorder TCPTSReorder TCPFullUndo TCPPartialUndo TCPDSACKUndo TCPLossUndo TCPLoss TCPLostRetransmit TCPRenoFailures TCPSackFailures TCPLossFailures TCPFastRetrans TCPForwardRetrans TCPSlowStartRetrans TCPLossProbes TCPLossProbeRecovery TCPTimeouts TCPRenoRecoveryFail TCPSackRecoveryFail TCPSchedulerFailed TCPRcvCollapsed TCPDSACKOldSent TCPDSACKOfoSent TCPDSACKRecv TCPDSACKOfoRecv TCPAbortOnData TCPAbortOnClose TCPAbortOnMemory TCPAbortOnTimeout TCPAbortOnLinger TCPAbortFailed TCPMemoryPressures TCPSACKDiscard TCPDSACKIgnoredOld TCPDSACKIgnoredNoUndo TCPSpuriousRTOs TCPMD5NotFound TCPMD5Unexpected TCPSackShifted TCPSackMerged TCPSackShiftFallback TCPBacklogDrop TCPMinTTLDrop TCPChallengeACK TCPSYNChallenge BusyPollRxPackets TCPFromZeroWindowAdv TCPToZeroWindowAdv TCPWantZeroWindowAdv
TcpExt: 35040990 0 59779326 3357 0 0 0 0 0 0 136419 18 38840650 31651 0 13 113169939 59662 104607836 423895 423895 177 40880 24 0 1990635022 16 754081894 1653441235 0 1022856 0 0 0 0 0 0 0 1061337 77658894 11069 13354 0 2243 5702 562930 502224 758547 76581738 39694045 232891774 0 138769 0 0 104607836 26 7355145 2287 1196925 559884 0 10981 0 177 0 0 0 285736 0 0 0 0 51088 3908984 4959708 0 563033 704255 0 0 0 6
IpExt: InNoRoutes InTruncatedPkts InMcastPkts OutMcastPkts InBcastPkts OutBcastPkts InOctets OutOctets InMcastOctets OutMcastOctets InBcastOctets OutBcastOctets
IpExt: 0 0 0 0 11214 0 673588464378 928920742927 0 0 4316942 0

上面这个太难看懂,有如下awk脚本,可以格式化

 cat /proc/net/netstat |  awk '(f==0) {name=$1; i=2; while ( i<=NF) {n[i] = $i; i++ }; f=1; next} (f==1){ i=2; while ( i<=NF){ printf "%s%s = %d\n", name, n[i], $i; i++}; f=0} ' 
TcpExt:SyncookiesSent = 35489955
TcpExt:SyncookiesRecv = 0
TcpExt:SyncookiesFailed = 60485560
TcpExt:EmbryonicRsts = 3358
TcpExt:PruneCalled = 0
TcpExt:RcvPruned = 0
TcpExt:OfoPruned = 0
TcpExt:OutOfWindowIcmps = 0
TcpExt:LockDroppedIcmps = 0
TcpExt:ArpFilter = 0
TcpExt:TW = 136714
TcpExt:TWRecycled = 18
TcpExt:TWKilled = 39264681
TcpExt:PAWSPassive = 33045
TcpExt:PAWSActive = 0
TcpExt:PAWSEstab = 13
TcpExt:DelayedACKs = 113527324
TcpExt:DelayedACKLocked = 59711
TcpExt:DelayedACKLost = 104743999
TcpExt:ListenOverflows = 427785
TcpExt:ListenDrops = 427785
TcpExt:TCPPrequeued = 177
TcpExt:TCPDirectCopyFromBacklog = 40880
TcpExt:TCPDirectCopyFromPrequeue = 24
TcpExt:TCPPrequeueDropped = 0
TcpExt:TCPHPHits = 1994510135
TcpExt:TCPHPHitsToUser = 16
TcpExt:TCPPureAcks = 761529606
TcpExt:TCPHPAcks = 1653441443
TcpExt:TCPRenoRecovery = 0
TcpExt:TCPSackRecovery = 1062162
TcpExt:TCPSACKReneging = 0
TcpExt:TCPFACKReorder = 0
TcpExt:TCPSACKReorder = 0
TcpExt:TCPRenoReorder = 0
TcpExt:TCPTSReorder = 0
TcpExt:TCPFullUndo = 0
TcpExt:TCPPartialUndo = 0
TcpExt:TCPDSACKUndo = 1061345
TcpExt:TCPLossUndo = 77901187
TcpExt:TCPLoss = 11262
TcpExt:TCPLostRetransmit = 13614
TcpExt:TCPRenoFailures = 0
TcpExt:TCPSackFailures = 2273
TcpExt:TCPLossFailures = 5784
TcpExt:TCPFastRetrans = 588602
TcpExt:TCPForwardRetrans = 516883
TcpExt:TCPSlowStartRetrans = 780842
TcpExt:TCPLossProbes = 76620127
TcpExt:TCPLossProbeRecovery = 39720645
TcpExt:TCPTimeouts = 233315959
TcpExt:TCPRenoRecoveryFail = 0
TcpExt:TCPSackRecoveryFail = 141679
TcpExt:TCPSchedulerFailed = 0
TcpExt:TCPRcvCollapsed = 0
TcpExt:TCPDSACKOldSent = 104743999
TcpExt:TCPDSACKOfoSent = 26
TcpExt:TCPDSACKRecv = 7357048
TcpExt:TCPDSACKOfoRecv = 2324
TcpExt:TCPAbortOnData = 1230601
TcpExt:TCPAbortOnClose = 594171
TcpExt:TCPAbortOnMemory = 0
TcpExt:TCPAbortOnTimeout = 10981
TcpExt:TCPAbortOnLinger = 0
TcpExt:TCPAbortFailed = 177
TcpExt:TCPMemoryPressures = 0
TcpExt:TCPSACKDiscard = 0
TcpExt:TCPDSACKIgnoredOld = 0
TcpExt:TCPDSACKIgnoredNoUndo = 285928
TcpExt:TCPSpuriousRTOs = 0
TcpExt:TCPMD5NotFound = 0
TcpExt:TCPMD5Unexpected = 0
TcpExt:TCPSackShifted = 0
TcpExt:TCPSackMerged = 51985
TcpExt:TCPSackShiftFallback = 3948946
TcpExt:TCPBacklogDrop = 4976826
TcpExt:TCPMinTTLDrop = 0
TcpExt:TCPChallengeACK = 568364
TcpExt:TCPSYNChallenge = 711190
TcpExt:BusyPollRxPackets = 0
TcpExt:TCPFromZeroWindowAdv = 0
TcpExt:TCPToZeroWindowAdv = 0
TcpExt:TCPWantZeroWindowAdv = 6
IpExt:InNoRoutes = 0
IpExt:InTruncatedPkts = 0
IpExt:InMcastPkts = 0
IpExt:OutMcastPkts = 0
IpExt:InBcastPkts = 11214
IpExt:OutBcastPkts = 0
IpExt:InOctets = 675937936252
IpExt:OutOctets = 932078274491
IpExt:InMcastOctets = 0
IpExt:OutMcastOctets = 0
IpExt:InBcastOctets = 4316942
IpExt:OutBcastOctets = 0

你可能感兴趣的:(工具类)