forked from cnamejj/cli-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chart-sar-net-dev-one
executable file
·130 lines (95 loc) · 1.85 KB
/
chart-sar-net-dev-one
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
#!/bin/bash
typeset -i days col low high
# ---
comm="chart-sar-generic"
# ---
if [ "$(which ${comm})" = "" ]
then
this_dir="$(dirname $(which $0) )"
if [ "${this_dir}" != "" ]
then
echo "Info: Adding '${this_dir}' to PATH to make '${comm}' script available."
export PATH="${PATH}:${this_dir}"
fi
fi
# ---
sar_opts="-n DEV"
chart_title="Network Device Stats"
title_pref=" ("
title_suff=")"
out_dir="/tmp/sar-$(whoami)/"
out_pref="${out_dir}$(hostname)-sar-net-dev-"
out_suff=".html"
# ---
if [ ! -d "${out_dir}" ]
then
mkdir "${out_dir}"
fi
# ---
days="$1"
if [ ${days} -lt 1 ]
then
days=3
fi
dev="$2"
if [ "${dev}" = "" ]
then
dev="$(sar ${sar_opts} 1 1 \
| gawk '
$1 == "Average:" && $2 != "IFACE" \
{
if( use == "" ) use = $2
else if( $2 != "lo" )
{
if( substr(use, 1, 3) == "tun" ) use = $2
}
}
END \
{
printf "%s", use
}'
)"
if [ "${dev}" = "" ]
then
echo "Error: Can't figure out what device to use."
exit 1
fi
echo "No device specified, will use '${dev}'"
fi
output="${out_pref}${dev}${out_suff}"
chart_title="${chart_title}${title_pref}${dev}${title_suff}"
# ---
crange=( $(sar ${sar_opts} 1 1 \
| gawk '
NF && $NF != "CPU)" \
{
headcheck = $NF
gsub("[0-9.-]", "", headcheck)
if( headcheck == "" )
{
low = high = NF
for( col = 3; col <= NF && low == NF; col++ )
{
gsub("[0-9.-]", "", $col)
if( $col == "" ) low = col
}
printf "%d %d\n", low, high
exit(0)
}
}' \
)
)
low=${crange[0]}
high=${crange[1]}
# ---
col=${low}
echo "Creating chart '${output}'"
cat /dev/null >"${output}"
while [ ${col} -le ${high} ]
do
echo "Run column ${col} of ${high}"
"${comm}" ${days} "${sar_opts}" ${col} "${chart_title}" "" " ${dev} " >>"${output}"
col=$(( ${col} + 1 ))
done
# ---
exit $?