-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetect.sh
executable file
·111 lines (99 loc) · 4.13 KB
/
detect.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
#!/bin/bash
debugmode=false
cd /opt/q-indexer
source lib/functions.sh
function print_usage() {
echo -e 'Usage:
'$0 '2021-12-31 10:00:00" "2021-12-31 10:59:00" 0.5.0.1 test
'$0" 2021-12-31 10:00:00" "2021-12-31 10:59:00" 0.5.0.1 test "10.10.2.10:32011 (for AIO)"'
'$0" 2021-12-31 10:00:00" "2021-12-31 10:59:00" 0.5.0.1 test "10.10.2.10:32006 (for EC or Datanode)"'
'$0" 2021-12-26 2021-12-31 0.56.0.1 test 90001 '10.10.2.10:32011' -action=fix"'
'$0" 2022-01-06 2022-01-09 0.56.0.1 test 90001 '127.0.0.1:32006' 172.16.60.41 -action=fix"
}
if [[ -z "$6" ]]; then
print_usage
exit 1
fi
export startdt="$1"
export enddt="$2"
export start="$1"
export end="$2"
export testip="$3"
export sessionname="$4"
export key="$5"
export arielproxyserver="$6"
export sshhost="$7"
export action="$8"
export startts="$(date "+%s" -d "$startdt")"
export endts="$(date "+%s" -d "$enddt")"
plog INFO "Parameters:"
plog INFO "[1]: startts=$startts ($startdt)"
plog INFO "[2]: endts=$endts ($enddt)"
plog INFO "[3]: AQL selector ip: $testip"
plog INFO "[4]: session name: $sessionname"
plog INFO "[5]: AQL selector key: $key"
plog INFO "[6]: arielproxyserver: $arielproxyserver"
plog INFO "[7]: ssh host: $sshhost"
plog INFO "[8]: $action"
fark="$(expr $(expr $endts - $startts) / 86400)"
plog INFO "difference: $(expr $fark + 1) days"
for d in $(seq 0 $(expr $fark)); do
secs="$(expr $d \* 86400)"
#plog DEBUG "expr $startts + $secs"
mydaystart="$(date "+%F" -d @$(expr $startts + $secs))"
mydayend="$(date "+%F" -d @$(expr $startts + $secs))"
nextday="$(date "+%Y/%m/%d" -d @$(expr $startts + $secs + 86400))"
logfile="/tmp/$mydaystart-action.log"
#plog INFO "Processing $mydaystart ..."
if [[ ! -z "$arielproxyserver" ]]; then
searchcmd="./qactl -checkdatafilecount $key '$mydaystart 00:00:00' '$mydayend 23:59:59' $testip $arielproxyserver"
else
searchcmd="./qactl -checkdatafilecount $key '$mydaystart 00:00:00' '$mydayend 23:59:59' $testip"
fi
plog INFO cmd: "$searchcmd"
#stats="$(eval $searchcmd | grep 'FileCount|seconds' | paste - - | sed -r 's#.+dataFileCount is ([0-9]+).+indexFileCount is ([0-9]+).+#\1;\2#')"
statfile="/tmp/q-indexer_$mydaystart-search-stats.log"
eval $searchcmd &>$statfile
cat $statfile
stats="$(cat $statfile | grep 'FileCount' | paste - - | sed -r 's#.+dataFileCount is ([0-9]+).+indexFileCount is ([0-9]+).+#\1;\2#')"
datastat="$(echo $stats | awk -F';' '{print $1}')"
indexstat="$(echo $stats | awk -F';' '{print $2}')"
if [[ "$datastat" -gt 3 ]]; then
plog "WARNING" "index corruption detected on $mydaystart"
if [[ "$action" == "-action=fix" ]]; then
if [[ ! -z "$arielproxyserver" ]]; then
actioncmd="time ssh $sshhost '/opt/q-indexer/qactl -db "'"'"$nextday 00:00"'"'" 1440'"
plog INFO "creating indexes for $mydaystart with cmd: $actioncmd"
plog INFO logfile: $logfile
eval $actioncmd &> /tmp/$mydaystart-action.log
tail /tmp/$mydaystart-action.log
plog INFO "after fix, perform a search and check search stats again"
eval $searchcmd | egrep "FileCount|seconds"
else
actioncmd="time /opt/q-indexer/qactl -db '$nextday 00:00' 1440"
plog INFO "creating indexes for $mydaystart with cmd: $actioncmd"
plog INFO logfile: $logfile
eval $actioncmd &> /tmp/$mydaystart-action.log
tail /tmp/$mydaystart-action.log
plog INFO "after fix, perform a search and check search stats again"
eval $searchcmd | egrep "FileCount|seconds"
fi
fi
fi
if [[ "$action" == "-action=delete" ]]; then
if [[ ! -z "$arielproxyserver" ]]; then
actioncmd="time ssh $sshhost '/opt/q-indexer/qactl -d "'"'"$nextday 00:00"'"'" 1440'"
plog "INFO deleting indexes for $mydaystart in $sshhost, cmd: $actioncmd"
plog INFO logfile: $logfile
eval $actioncmd &> /tmp/$mydaystart-action.log
tail /tmp/$mydaystart-action.log
else
plog INFO deleting indexes
plog DEBUG "index process is starting for $mydaystart with cmd: $actioncmd"
actioncmd="time /opt/q-indexer/qactl -d '$nextday 00:00' 1440"
eval $actioncmd &> /tmp/$mydaystart-action.log
tail /tmp/$mydaystart-action.log
fi
fi
wlog "$mydaystart;dataFilecount:$datastat;indexFileCount:$indexstat;$searchcmd;$actioncmd"
done