-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyslog-all.sh
executable file
·198 lines (150 loc) · 5.44 KB
/
syslog-all.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
#!/bin/sh
# Copyright (C) 2017 Embecosm Limited <www.embecosm.com>
# Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
# General script to handle syslog data
# 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 for
# more details.
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
# Usage:
# updown-graph.sh
# Prerequisites:
# sudo dnf install fuse-sshfs
# SNOBOL4 installation (see http://www.snobol4.org/csnobol4/curr/)
# SSH public key on loglady
###############################################################################
#
# Mount the remote directory
#
###############################################################################
remdir=/tmp/syslog-all-dir-$$
#remdir=testing
remhost=loglady
# Unmount first if already mounted
fusermount -q -u ${remdir} || true
rm -rf ${remdir}
mkdir ${remdir}
if ! sshfs embadmin@${remhost}:/var/log ${remdir}
then
echo "ERROR: Could not mount remote file system"
exit 1
fi
###############################################################################
#
# Strip out irrelevant content from all the syslogs and make one unified file.
#
###############################################################################
tmpf1=/tmp/syslog-all-tmp-1-$$
tmpf2=/tmp/syslog-all-tmp-2-$$
updowndat=/tmp/syslog-all-tmp-3-$$
speeddat=/tmp/syslog-all-tmp-4-$$
#tmpf1=tmpf1
#tmpf2=tmpf2
#updowndat=updown.dat
#speeddat=speed.dat
rm -f ${tmpf1}
rm -f ${tmpf2}
# We are not interested in messages at the TCP/UDP level
echo "Gathering data from current logs"
for f in ${remdir}/syslog ${remdir}/syslog.1
do
grep -v 'TCP\|UDP\|ICMP\|DNS' ${f} | tac >> ${tmpf1}
done
echo "Gathering data from historic logs"
for f in ${remdir}/syslog.?.gz ${remdir}/syslog.??.gz
do
zcat ${f} | grep -v 'TCP\|UDP\|ICMP\|DNS' | tac >> ${tmpf1}
done
tac < ${tmpf1} | sed -e 's/DrayTek2/DrayTek/' > ${tmpf2}
###############################################################################
#
# Now process the data
#
###############################################################################
# Use SNOBOL4 to do the processing.
# Processing the data
snobol4 syslog-all.sno ${tmpf2} ${updowndat} ${speeddat}
firstday=$(head -n 1 ${updowndat} | cut -f 1 -d /)
lastday=$(tail -n 1 ${updowndat} | cut -f 1 -d /)
###############################################################################
#
# Plot the results
#
###############################################################################
echo "Plotting a graph"
cat > ${tmpf2} <<EOF
set xlabel "date"
set xdata time
set timefmt "%Y-%b-%d/%H:%M:%S"
set format x "%d-%b"
set border 3
set xrange ["firstday/00:00:00" : "lastday/23:59:59"]
set xtics out nomirror
set style line 1 lc rgb '#0000ff' lt 1 lw .2 pt 7 ps 1.5 # --- blue
set style line 2 lc rgb '#00ff00' lt 1 lw .2 pt 7 ps 1.5 # --- green
set style line 3 lc rgb '#ff0000' lt 1 lw .2 pt 7 ps 1.5 # --- red
set style line 4 lc rgb '#ffff00' lt 1 lw .2 pt 7 ps 1.5 # --- yellow
set margins 12, 2, 4, 2
set ylabel "status"
set yrange ["0" : "12"]
set ytics out nomirror ("DSL down" 1, "DSL up" 4, "PPP down" 6, "PPP up" 9)
plot 'updowndat' using 1:2 linestyle 1 with lines title "DSL status", \
'updowndat' using 1:3 linestyle 2 with lines title "PPP status"
set terminal x11 1
set ylabel "speed"
set yrange ["0" : "100000000"]
unset ytics
set ytics out nomirror
plot 'speeddat' using 1:2 linestyle 1 with lines title "Speed up", \
'speeddat' using 1:3 linestyle 2 with lines title "Speed sown"
set terminal x11 2
set ylabel "noise"
set yrange ["-10" : "25"]
unset ytics
set ytics out nomirror
plot 'speeddat' using 1:4 linestyle 1 with lines title "SNR", \
'speeddat' using 1:5 linestyle 2 with lines title "Attenuation"
set terminal pdf
set output "status.pdf"
set ylabel "status"
set yrange ["0" : "12"]
set ytics out nomirror ("DSL down" 1, "DSL up" 4, "PPP down" 6, "PPP up" 9)
plot 'updowndat' using 1:2 linestyle 1 with lines title "DSL status", \
'updowndat' using 1:3 linestyle 2 with lines title "PPP status"
set output "speed.pdf"
set ylabel "speed"
set yrange ["0" : "100000000"]
unset ytics
set ytics out nomirror
plot 'speeddat' using 1:2 linestyle 1 with lines title "Speed up", \
'speeddat' using 1:3 linestyle 2 with lines title "Speed sown"
set output "noise.pdf"
set ylabel "noise"
set yrange ["-10" : "25"]
unset ytics
set ytics out nomirror
plot 'speeddat' using 1:4 linestyle 1 with lines title "SNR", \
'speeddat' using 1:5 linestyle 2 with lines title "Attenuation"
EOF
sed -i ${tmpf2} -e "s|firstday|${firstday}|" -e "s|lastday|${lastday}|" \
-e "s|updowndat|${updowndat}|g" -e "s|speeddat|${speeddat}|g"
gnuplot -persist ${tmpf2}
###############################################################################
#
# Tidy up
#
###############################################################################
# Remove temporary files
rm -f ${tmpf1}
rm -f ${tmpf2}
rm -f ${updowndat}
rm -f ${speeddat}
# Lazy unmount to allow previous commands to catch up
fusermount -z -u ${remdir}
rmdir ${remdir}