-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchecknet
More file actions
executable file
·127 lines (122 loc) · 5.72 KB
/
checknet
File metadata and controls
executable file
·127 lines (122 loc) · 5.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
# checknet-0.0.1 Written by Kyle Walker kwalker@redhat.com
# Uses sosreports to grab relevant active NIC information for a system.
if [ $# == 0 ]; then
for i in `grep 'Link.*yes' sos_commands/networking/ethtool_e* sos_commands/networking/ethtool_p* -l 2>/dev/null | cut -d "_" -f 3-5`
do
if [ -f sos_commands/networking/ethtool_-S_$i ]; then
echo $i - `grep driver sos_commands/networking/ethtool_-i_$i `
cat sos_commands/networking/ethtool_-S_$i | awk '/error|drop|discard|collision|out of|crc/ {if($NF != 0 && $0!~/address.*drop|address_/) print $0}'
else
echo -e "$i\nNo stats available in sosreport"
fi
done
fi
case "$1" in
-v)
for i in `grep 'Link.*yes' sos_commands/networking/ethtool_e* sos_commands/networking/ethtool_p* -l 2>/dev/null | cut -d "_" -f 3-5`
do
echo $i
cat sos_commands/networking/ethtool_-S_$i | awk '/error|drop|discard|collision|crc|out of/ {if($NF == 0) print $0}'
done
;;
-a)
for i in `grep 'Link.*yes' sos_commands/networking/ethtool_e* sos_commands/networking/ethtool_p* -l 2>/dev/null | cut -d "_" -f 3-5`
do
echo $i; cat sos_commands/networking/ethtool_-S_$i | awk '{print $0}'
done
;;
-history)
shift
if [[ $1 == '--max' ]]; then
shift
for i in `ls var/log/sa/sar* sar*`
do
echo $i
awk '/rxerr/,/^$/' $i | awk 'BEGIN {first=1; counter=0; max='"$1"'; if(max>1) max--} /IFACE/ {if(first==1) print $0; first++} !/IFACE|^ *$|bond/ {if($3+$4+$5+$6+$7+$8+$9+$10+$11 > 0){if(counter <= max) {print $0; counter++}}}'
done
else
for i in `ls var/log/sa/sar* sar*`
do
echo $i
awk 'BEGIN {header=0} /rxerr/ {if(header==0){print;header++}} /rxerr/,/^$/ {if($0~/^$/) print; if($0!~/rxerr|bond/){for(x=3;x<=11;x++) {if($x > 0) y++; if(x==11&&y>0) {print $0; y=0}}}}' $i
done
fi
;;
-history-count) for i in `ls var/log/sa/sar* sar*`
do
echo -en "$i\t\t"
awk '/rxerr/,/^$/' $i | awk 'BEGIN {count=0} !/IFACE|^ *$|bond/ {if($3+$4+$5+$6+$7+$8+$9+$10+$11 > 0)count++} END {print "Total number of issues: "count}'
done | column -t
;;
-d) for i in `cat ifconfig | awk '$0~/^em|^p|^eth/ {print $1}'`; do echo $i; for b in `grep bus-info sos_commands/networking/ethtool_-i_$i | cut -d ' ' -f 2 | cut -d ':' -f 2-3`; do grep $b lspci -m 1; done; done
;;
-cluster) for i in `ls -d */`
do
if [ -d $i/sos_commands/networking/ ]
then
echo $i;
for b in `grep 'Link.*yes' $i\sos_commands/networking/ethtool_[ep]* -l | cut -d "_" -f 3 2>/dev/null`
do
echo -e " "$b - `grep driver $i/sos_commands/networking/ethtool_-i_$b 2>/dev/null`
cat $i/sos_commands/networking/ethtool_-S_$b | awk '/[rx|tx]_error|drop|discard|collision|crc|out of/ {if($NF != 0 && $0!~/address.*drop|address_/) print $0}'
done
echo "";
fi
done
;;
-tcpstat) output="Sosreport:\tDropped-recv-pkts\tTotal-recv-pkts\tPercentage-drop\n"
if [ ! -f ifconfig ];
then
for i in `ls -d */`
do
if [ -f $i/ifconfig ]
then
output=$output" "$i" "
let x=`awk 'BEGIN {sum=0} /collapsed in receive/ {sum+=$1} END {print sum}' $i/sos_commands/networking/netstat_-s`
let y=`awk 'BEGIN {pkts=0} /total packets received/ {pkts=$1} END {print pkts}' $i/sos_commands/networking/netstat_-s`
output=$output$x" "$y" "
if [ $y -ne 0 ]
then
output=$output$(echo "scale=3;($x/$y)*100" | bc)
else
output=$output"0"
fi
fi
output=$output"\n"
done
echo -e $output | column -t
else
output=$output" "${PWD##*/}" "
let x=`awk 'BEGIN {sum=0} /collapsed in receive/ {sum+=$1} END {print sum}' sos_commands/networking/netstat_-s`
let y=`awk 'BEGIN {pkts=0} /total packets received/ {pkts=$1} END {print pkts}' sos_commands/networking/netstat_-s`
output=$output$x" "$y" "
if [ $y -ne 0 ]
then
output=$output$(echo "scale=3;($x/$y)*100" | bc)
else
output=$output"0"
fi
echo -e $output | column -t
fi
;;
-ifup) awk 'BEGIN {printer=0; buffer=""} /^eth|^bond|^em|^p[0-9]/,/^$/ {buffer=buffer"\n"$0; if($0~/^[ \t]*UP/) printer=1; if($0~/^$/ && printer>0) {print buffer; buffer=""; printer=0} else if($0~/^$/) {buffer="";printer=0}}' ifconfig
;;
-h) echo "checknet: Should be run from the root directory of a sosreport; except -tcpstat and -cluster"
echo "Usage: checknet [option]"
echo -e "\tOptions:"
echo -e "\t\tNo options - Outputs a number of NIC-level errors and active driver in use"
echo -e "\t\t-h\t\tThis message"
echo -e "\t\t-a\t\tReturns all entries in active NIC interfaces"
echo -e "\t\t-v\t\tReturns the entries above that do have 0 values"
echo -e "\t\t-d\t\tReturns the hardware as reported by lspci output"
echo -e "\t\t-cluster\tRun from a directory that has multiple sosreports. Output is the same type of no options output but for multiple sosreports at once"
echo -e "\t\t-tcpstat\tRun from a directory that has multiple sosreports. Checks the number of buffer [over,under]run drops against total packet transmission"
echo -e "\t\t-history\tParses the existing sar data files for any instances of network issues"
echo -e "\t\t--max\tReturns the first N instances in the -history output above"
echo -e "\t\t-history-count\tSame process as -history, but outputs only counts of issues"
echo -e "\t\t-ifup\tReturns output from ifconfig for interfaces that are UP"
;;
esac
#Included the entry below if having the customer generate new output:
#for i in `ifconfig | grep -Eve '^ .*$' -e '^ *$' -e lo | cut -d ':' -f 1`; do if [ `ethtool $i 2>/dev/null| grep Link | awk '{print $NF}'` == "yes" ]; then echo $i - `ethtool -i $i | grep driver`; ethtool -S $i | awk '/error|drop|discard|collision/ {if($NF != 0) print $0}'; fi ; done