-
Notifications
You must be signed in to change notification settings - Fork 0
/
statistiche.sh
91 lines (73 loc) · 3.22 KB
/
statistiche.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
#!/bin/bash
LOGFILE=$1
if [ -z "$LOGFILE" ]
then
echo "No logfile path provided. Assuming default location"
LOGFILE='/tmp/LSOfilestorage.log'
fi
echo "Parsing $LOGFILE"
if [ ! -f "$LOGFILE" ]; then
echo "File '$LOGFILE' does not exist."
exit
fi
TEXT="$(tac "$LOGFILE" | sed '/Up and running/Q' | tac)"
READS="$(echo "$TEXT" | grep "Sent file to client" | grep -Eo "[0-9]* bytes" | grep -Eo "[0-9]*")"
READCOUNT="$(echo "$READS" | grep -c .)"
READAVG=0
if [[ "$READCOUNT" -ne 0 ]]
then
IFS=$'\n'
for line in ${READS//\\n/$cr}
do
CURRENTREAD="$(echo "$line")"
READAVG=$((READAVG + CURRENTREAD))
done
READAVG=$((READAVG / READCOUNT))
fi
WRITES="$(echo "$TEXT" | grep "Received file from client" | grep -Eo "[0-9]* bytes" | grep -Eo "[0-9]*")"
WRITECOUNT="$(echo "$WRITES" | grep -c .)"
WRITEAVG=0
if [[ "$WRITECOUNT" -ne 0 ]]
then
IFS=$'\n'
for line in ${WRITES//\\n/$cr}
do
CURRENTWRITE="$(echo "$line")"
WRITEAVG=$((WRITEAVG + CURRENTWRITE))
done
WRITEAVG=$((WRITEAVG / WRITECOUNT))
fi
echo "Number of reads: $READCOUNT, average size: $READAVG bytes"
echo "Number of writes: $WRITECOUNT, average size: $WRITEAVG bytes"
echo "Number of locks explicitly acquired (locks obtained with open-lock not counted): $(echo "$TEXT" | grep -c "successfully locked")"
echo "Number of open-lock operations: $(($(echo "$TEXT" | grep -c "successfully opened and locked") + $(echo "$TEXT" | grep -c "flags: 2")))"
echo "Number of locks explicitly released (locks released with close/remove not counted): $(echo "$TEXT" | grep -c "successfully unlocked")"
echo "Number of file close operations: $(echo "$TEXT" | grep -c "successfully closed the file")"
echo "Max size reached: $(echo "scale=4; $(echo "$TEXT" | grep -Eo "Max storage size.*" | grep -Eo "[0-9]*")/1024/1024" | bc -l)MB"
echo "Max files stored: $(echo "$TEXT" | grep -Eo "Max number of files stored.*" | grep -Eo "[0-9]*")"
echo "Num files evicted: $(echo "$TEXT" | grep -Eo "Number of files evicted.*" | grep -Eo "[0-9]*")"
echo "$TEXT" | grep -Eo "Worker #[0-9]* has served [0-9]* requests"
echo "Max clients connected: $(echo "$TEXT" | grep -Eo "Max number of clients simultaneously connected.*" | grep -Eo "[0-9]*")"
echo "Number of files compressed: $(echo "$TEXT" | grep -c "File has been compressed")"
SIZECOMPRESSED=0
SIZEUNCOMPRESSED=0
STORES="$(echo "$TEXT" | grep "File has been compressed" | sed "s/[^0-9 ]//g; s/^[0-9]* *[0-9]* *//; s/ \{2,\}/ /")"
IFS=$'\n'
for line in ${STORES//\\n/$cr}
do
CURRENTSTORE="$(echo "$line")"
CURRENTUNCOMPRESSED=$(echo $CURRENTSTORE | cut -d " " -f 1)
SIZEUNCOMPRESSED=$((SIZEUNCOMPRESSED + CURRENTUNCOMPRESSED))
CURRENTCOMPRESSED=$(echo $CURRENTSTORE | cut -d " " -f 2)
SIZECOMPRESSED=$((SIZECOMPRESSED + CURRENTCOMPRESSED))
done
STORES="$(echo "$TEXT" | grep "File not compressed" | grep -Eo "[0-9]* bytes" | grep -Eo "[0-9]*")"
IFS=$'\n'
for line in ${STORES//\\n/$cr}
do
CURRENTSTORE="$(echo "$line")"
SIZEUNCOMPRESSED=$((SIZEUNCOMPRESSED + CURRENTSTORE))
SIZECOMPRESSED=$((SIZECOMPRESSED + CURRENTSTORE))
done
echo "Size compressed $SIZECOMPRESSED bytes, size uncompressed: $SIZEUNCOMPRESSED bytes, bytes saved: $((SIZEUNCOMPRESSED - SIZECOMPRESSED))"
echo "Compression ratio: $(echo "scale=4; $SIZECOMPRESSED / $SIZEUNCOMPRESSED * 100" | bc -l)%"