forked from roboception/rc_genicam_api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
net_perf_check.sh
executable file
·273 lines (221 loc) · 8.83 KB
/
net_perf_check.sh
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#!/bin/bash
#
# Simple test of network settings for receiving lots of UDP packets (e.g. for GigE Vision)
# Copyright 2017 Felix Ruess <felix.ruess@roboception.de>
#
# SOFTIRQ check based on xsos <http://github.com/ryran/xsos>
# Copyright 2012-2016 Ryan Sawhill Aroha <rsaw@redhat.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License <gnu.org/licenses/gpl.html> for more details.
#-------------------------------------------------------------------------------
export LC_ALL=en_US.UTF-8
# Colors and colors and colors oh my (but only for bash v4)
if [[ $BASH_VERSINFO -ge 4 ]]; then
declare -A c
c[reset]='\033[0;0m' c[BOLD]='\033[0;0m\033[1;1m'
c[dgrey]='\033[0;30m' c[DGREY]='\033[1;30m' c[bg_DGREY]='\033[40m'
c[red]='\033[0;31m' c[RED]='\033[1;31m' c[bg_RED]='\033[41m'
c[green]='\033[0;32m' c[GREEN]='\033[1;32m' c[bg_GREEN]='\033[42m'
c[orange]='\033[0;33m' c[ORANGE]='\033[1;33m' c[bg_ORANGE]='\033[43m'
c[blue]='\033[0;34m' c[BLUE]='\033[1;34m' c[bg_BLUE]='\033[44m'
c[purple]='\033[0;35m' c[PURPLE]='\033[1;35m' c[bg_PURPLE]='\033[45m'
c[cyan]='\033[0;36m' c[CYAN]='\033[1;36m' c[bg_CYAN]='\033[46m'
c[lgrey]='\033[0;37m' c[LGREY]='\033[1;37m' c[bg_LGREY]='\033[47m'
fi
# ==============================================================================
# ENVIRONMENT VARIABLES -- Modify these by setting them in your shell
# environment, e.g. ~/.bash_profile or /etc/profile.d/xsos.sh
# COLORS
# The following configure defaults for various colors to enhance output
# XSOS_COLORS (bool: y/n)
# Controls whether color is enabled or disabled by default
# Can also be controlled by cmdline arg
: ${XSOS_COLORS:="y"}
# XSOS_COLOR_RESET -- color to reset terminal to after using other colors
: ${XSOS_COLOR_RESET:="reset"}
# XSOS_COLOR_H1 -- color for content modules' primary header
: ${XSOS_COLOR_H1:="RED"}
# XSOS_COLOR_H2 -- color for content modules' secondary header
: ${XSOS_COLOR_H2:="PURPLE"}
# XSOS_COLOR_H3 -- color for content modules' tertiary header
: ${XSOS_COLOR_H3:="BLUE"}
# XSOS_COLOR_H4 -- color used only for SYSCTL() module
: ${XSOS_COLOR_H4:="reset"}
# XSOS_COLOR_IMPORTANT -- color for drawing attention to important data
: ${XSOS_COLOR_IMPORTANT:="BOLD"}
# XSOS_COLOR_WARN1 -- color for level-1 warnings
: ${XSOS_COLOR_WARN1:="orange"}
# XSOS_COLOR_WARN2 -- color for level-2 warnings
: ${XSOS_COLOR_WARN2:="ORANGE"}
# INDENTATION
# The following variables are not used universally and that might not change
# XSOS_INDENT_H1 -- 1st level of indentation
: ${XSOS_INDENT_H1:=" "}
# XSOS_INDENT_H2 -- 2nd level of indentation
: ${XSOS_INDENT_H2:=" "}
# XSOS_INDENT_H3 -- 3rd level of indentation
: ${XSOS_INDENT_H3:=" "}
# XSOS_HEADING_SEPARATOR (str)
# Acts as a separator between content modules
# Should include at least 1 trailing new-line
: ${XSOS_HEADING_SEPARATOR:="\n"}
# XSOS_OUTPUT_HANDLER (str: application name)
# Sets name of application to handle output
: ${XSOS_OUTPUT_HANDLER:="cat"}
HELP_USAGE() {
echo "Usage: net_perf_check.sh [-xy] [-i interface]
or: net_perf_check.sh [-?|-h|--help]"
}
HELP_OPTS() {
echo "
Options:"
echo "
-i, --iface❚select interface for MTU check
-x, --nocolor❚disable output colorization
-y, --less❚send output to \`less -SR\`" | column -ts❚
}
HELP() {
HELP_USAGE
HELP_OPTS
exit
}
# Help? Version?
case $1 in
-\?|-h) HELP ;;
--help|help) HELP ;;
esac
# GNU getopt short and long options:
sopts='xyi:'
lopts='nocolor,less,iface'
# Check for bad switches
getopt -Q --name=xsos -o $sopts -l $lopts -- "$@" || { HELP_USAGE; exit 64; }
# Parse command-line arguments
PARSE() {
until [[ $1 == -- ]]; do
case $1 in
-x|--nocolor) XSOS_COLORS=n ;;
-y|--less) XSOS_OUTPUT_HANDLER='less -SR' ;;
-i|--iface) IFACE=$2; shift ;;
esac
shift
done
shift #(to get rid of the '--')
}
# Call the parser
PARSE $(getopt -u --name=xsos -o $sopts -l $lopts -- "$@")
# If color should be enabled, taste the rainbow
if [[ $XSOS_COLORS == y && $BASH_VERSINFO -ge 4 ]]; then
c[0]=${c[$XSOS_COLOR_RESET]}
c[H1]=${c[$XSOS_COLOR_H1]}
c[H2]=${c[$XSOS_COLOR_H2]}
c[H3]=${c[$XSOS_COLOR_H3]}
c[H4]=${c[$XSOS_COLOR_H4]}
c[Imp]=${c[$XSOS_COLOR_IMPORTANT]}
c[Warn1]=${c[$XSOS_COLOR_WARN1]}
c[Warn2]=${c[$XSOS_COLOR_WARN2]}
else
unset c
fi
MTU() {
local mtu= iface=
if [[ $# == 1 ]]; then
iface=$1
else
#echo -e "Detecting default interface..."
iface=$(route | grep '^default' | head -n1 | grep -o '[^ ]*$')
#echo -e "Using default interface $iface"
fi
if [[ ! -e /sys/class/net/$iface ]]; then
echo -e "${c[Warn2]}Warning:${c[Warn1]} Interface $iface does not exist; skipping MTU check${c[0]}" >&2
echo -en $XSOS_HEADING_SEPARATOR >&2
return
fi
mtu=$(cat /sys/class/net/$iface/mtu)
echo -e "${c[H1]}MTU${c[0]}"
if [[ $mtu -lt 8000 ]]; then
echo -e "${XSOS_INDENT_H1}${c[Warn1]}Current MTU of $iface is only $mtu, consider setting an MTU up to 9000.${c[0]}"
else
echo -e "${XSOS_INDENT_H1}MTU of $iface is sufficient${c[0]} (Current value: $mtu)"
fi
echo -en $XSOS_HEADING_SEPARATOR
}
RMEM_MAX () {
local rcvbuf_errors= rmem_max=
if [[ ! -r /proc/net/snmp ]]; then
echo -e "${c[Warn2]}Warning:${c[Warn1]} '/proc/net/snmp' unreadable; skipping receive buffer check${c[0]}" >&2
echo -en $XSOS_HEADING_SEPARATOR >&2
return
fi
rcvbuf_errors=$(cat /proc/net/snmp | grep -E "Udp\:[[:space:]][0-9]+" | awk '{print $6}')
rmem_max=$(cat /proc/sys/net/core/rmem_max 2>/dev/null) \
&& rmem_max=" (Current value: net.core.rmem_max = $rmem_max)" \
|| rmem_max=" (However, proc/sys/net/core/rmem_max is missing)"
echo -e "${c[H1]}RMEM_MAX${c[0]}"
if [[ $rcvbuf_errors -gt 0 ]]; then
echo -e "${XSOS_INDENT_H1}${c[Warn1]}There were $rcvbuf_errors RcvbufErrors, consider reviewing rmem_max tunable.${c[0]}$rmem_max"
echo -e "${XSOS_INDENT_H1}This is only a problem if RcvbufErrors value increases while receiving data."
else
echo -e "${XSOS_INDENT_H1}Max receive buffer seems to be sufficient${c[0]}$rmem_max"
fi
echo -en $XSOS_HEADING_SEPARATOR
}
SOFTIRQ() {
# Local vars:
local softirq_input_file suffix= backlog= budget=
softirq_input_file=/proc/net/softnet_stat
if [[ ! -r $softirq_input_file ]]; then
echo -e "${c[Warn2]}Warning:${c[Warn1]} '/proc/net/softnet_stat' unreadable; skipping softirq check${c[0]}" >&2
echo -en $XSOS_HEADING_SEPARATOR >&2
return
fi
backlog=$(cat /proc/sys/net/core/netdev_max_backlog 2>/dev/null) \
&& backlog=" (Current value: net.core.netdev_max_backlog = $backlog)" \
|| backlog=" (However, proc/sys/net/core/netdev_max_backlog is missing)"
budget=$(cat /proc/sys/net/core/netdev_budget 2>/dev/null) \
&& budget=" (Current value: net.core.netdev_budget = $budget)" \
|| budget=" (However, proc/sys/net/core/netdev_budget is missing)"
echo -e "${c[H1]}SOFTIRQ${c[0]}"
gawk '{if (strtonum("0x" $2) > 0) exit 177}' "$softirq_input_file"
if [[ $? -eq 177 ]]; then
echo -e "${XSOS_INDENT_H1}${c[Warn1]}Backlog max has been reached, consider reviewing backlog tunable.${c[0]}$backlog"
else
echo -e "${XSOS_INDENT_H1}Backlog max is sufficient${c[0]}$backlog"
fi
gawk '{if (strtonum("0x" $3) > 0) exit 177}' "$softirq_input_file"
if [[ $? -eq 177 ]]; then
echo -e "${XSOS_INDENT_H1}${c[Warn1]}Budget is not sufficient, consider reviewing budget tunable.${c[0]}$budget"
else
echo -e "${XSOS_INDENT_H1}Budget is sufficient${c[0]}$budget"
fi
echo -en $XSOS_HEADING_SEPARATOR
}
# Create sub tempdir in /dev/shm (tons of bash constructs use TMPDIR)
[[ -d /dev/shm && -w /dev/shm ]] && parent=/dev/shm || parent=/tmp
export TMPDIR=$(mktemp -d -p $parent)
# Create tmp file for capturing stderr
stderr_file=$TMPDIR/stderr
# Remove temp dir when we're done
trap "rm -rf $TMPDIR 2>/dev/null" EXIT
{
# Redirect stderr to temp file
exec 7>&2 2>$stderr_file
[[ -n $IFACE ]] && MTU $IFACE || MTU
RMEM_MAX
SOFTIRQ
# If sending output to less or more, let's just append stderr to stdout
# If just outputting to term (cat), redirect fd2 to tty
case $XSOS_OUTPUT_HANDLER in
less*|more) cat $stderr_file ;;
cat) exec 2>&7
esac
} | $XSOS_OUTPUT_HANDLER
# If output going to term (cat), print stderr tmp file contents to stderr
[[ $XSOS_OUTPUT_HANDLER == cat ]] && cat $stderr_file >&2 || :