-
Notifications
You must be signed in to change notification settings - Fork 7
/
orstatus-stats.sh
executable file
·72 lines (62 loc) · 1.63 KB
/
orstatus-stats.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
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0-or-later
# set -x
# work on output of orstatus.py, eg.: plot a histogram for specific event reason:
#
# orstatus.py --address ::1 --ctrlport 29051 >> /tmp/orstatus.29051 &
# sleep 3600
# orstatus-stats.sh /tmp/orstatus.29051 IOERROR
#######################################################################
set -eu
export LANG=C.utf8
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
files=""
reason=""
for opt in "$@"; do
if [[ -e $opt ]]; then
files+=" $opt"
else
reason=$opt
fi
done
if [[ -z $files ]]; then
echo " no files ?!"
exit 1
fi
# count per reason
awk '{ print $2 }' $files | sort | uniq -c |
perl -wane 'BEGIN { $sum = 0 } { $sum += $F[0]; print } END { printf("%7i\n", $sum) }'
if [[ -n $reason ]]; then
# plot for given reason
tmpfile=$(mktemp /tmp/$(basename $0)_XXXXXX.tmp)
grep -h " $reason " $files |
awk '{ print $3 }' | sort | uniq -c |
awk '{ print $1 }' | sort -bn | uniq -c |
awk '{ print $1, $2 }' |
tac >$tmpfile
echo
echo "fingerprint(s) x $reason"
lines=$(wc -l <$tmpfile)
if [[ $lines -gt 7 ]]; then
head -n 3 $tmpfile
echo '...'
tail -n 3 $tmpfile
else
cat $tmpfile
fi
if [[ $lines -gt 1 ]]; then
m=$(grep -hc " $reason " $files)
n=$(grep -h " $reason " $files | awk '{ print $1 }' | sort -u | wc -l)
gnuplot -e '
set terminal dumb;
set border back;
set title "'$n' fingerprint(s) closed '$m' x due to '$reason'";
set key noautotitle;
set xlabel "fingerprints";
set logscale x 10;
set logscale y 2;
plot "'$tmpfile'" pt "o";
'
fi
rm $tmpfile
fi