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
#!/bin/bash
# Author christian.gerdes@lightsinline.se
# Compares to output files generated by "varnishstat -1 > file1.dat"
# Uses the file last modified timestamps to calculate the time between the files
# Outputs values that have changed only, the change between the files and per sec
if [ $# -lt 2 ]
then
echo "Need at least 2 files."
exit 0
fi
if ! [ -a $1 ]
then
echo "File $1 does not exist"
exit 0
fi
if ! [ -a $2 ]
then
echo "File $2 does not exist"
exit 0
fi
if [ $1 -nt $2 ]
then
echo "File $1 is newer than file $2"
exit 0
fi
TS1=$(stat -c "%Y" $1)
TS2=$(stat -c "%Y" $2)
TS=$[ $TS2 - $TS1 ]
echo "Time diff is $TS seconds"
echo
echo "$(printf '%-40s' NAME) $(printf '%10s' CHANGE) PER SEC"
X=1
LINE=$(printf '%sq;d' $X)
NAME1=$(sed $LINE $1 | awk '{print $1}')
VAL1=$(sed $LINE $1 | awk '{print $2}')
NAME2=$(sed $LINE $2 | awk '{print $1}')
VAL2=$(sed $LINE $2 | awk '{print $2}')
while [ -n "$NAME1" ]; do
if [ "$NAME1" != "$NAME2" ]
then
echo "Files do not match (each line has to be the same variable in the two files)"
exit 0
fi
VALDIFF=$[ $VAL2 - $VAL1 ]
if [ $VALDIFF -ne 0 ]
then
VALDIFFPS=$(awk "BEGIN { print $VALDIFF/$TS }")
echo "$(printf '%-40s' $NAME1) $(printf '%10s' $VALDIFF) $VALDIFFPS"
fi
X=$[ $X + 1 ]
LINE=$(printf '%sq;d' $X)
NAME1=$(sed $LINE $1 | awk '{print $1}')
VAL1=$(sed $LINE $1 | awk '{print $2}')
NAME2=$(sed $LINE $2 | awk '{print $1}')
VAL2=$(sed $LINE $2 | awk '{print $2}')
done
echo
echo "Done"