online bottlenecks soak throughtputs
[releng.git] / utils / slave-monitor-0.1.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 Linux Foundation and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 #Counts how long slaves have been online or offline
12 #exec 2>/dev/null
13
14 #Yes I know about jq
15 curlcommand() {
16 curl -s "https://build.opnfv.org/ci/computer/api/json?tree=computer\[displayName,offline\]" \
17     | awk -v k=":" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' \
18     | grep -v "_class" \
19     | awk 'NR%2{printf "%s ",$0;next;}1'  \
20     | awk -F":" '{print $2,$3}' \
21     | awk '{print $1,$3}' \
22     | sed s,\},,g \
23     | sed s,],,g \
24     | sed s,\",,g
25 }
26
27 curlcommand > /tmp/podoutput-current
28
29 declare -A slavescurrent
30
31 while read -r name status ; do
32             slavescurrent["$name"]="$status"
33 done < <(cat /tmp/podoutput-current)
34
35 #haste bin stopped allowing post :(
36 #files=(*online)
37 #for ((i=0; i<${#files[@]}; i+=9)); do
38 #./eplot -d -r [-1:74][-1:30] -m    ${files[i]} ${files[i+1]} ${files[i+2]} ${files[i+3]} ${files[i+4]} ${files[i+5]}  ${files[i+6]} ${files[i+7]} ${files[i+8]} ${files[i+9]}
39 #done  | ./haste.bash
40 ##
41 main () {
42
43 for slavename in "${!slavescurrent[@]}"; do
44
45   #Slave is online. Mark it down.
46     if [ "${slavescurrent[$slavename]}" == "false" ]; then
47
48       if  ! [ -f /tmp/"$slavename"-online ]; then
49         echo "1" > /tmp/"$slavename"-online
50                 echo "new online slave file created $slavename ${slavescurrent[$slavename]} up for 1 iterations"
51           fi
52
53                 #read and increment slavename
54                 var="$(cat /tmp/"$slavename"-online |tail -n 1)"
55                 if [[ "$var" == "0" ]]; then
56                     echo "slave $slavename ${slavescurrent[$slavename]} back up for $var iterations"
57                 fi
58                 ((var++))
59                 echo "$var" >> /tmp/"$slavename"-online
60                 unset var
61                 echo "$slavename up $(cat /tmp/$slavename-online | tail -n 10 | xargs)"
62
63     fi
64
65     #slave is offline remove all points
66     if [ "${slavescurrent[$slavename]}" == "true" ]; then
67       if  ! [ -f /tmp/"$slavename"-online ]; then
68         echo "0" > /tmp/"$slavename"-online
69                 echo "new offline slave file created $slavename ${slavescurrent[$slavename]} up for 0 iterations"
70
71           fi
72           var="$(cat /tmp/"$slavename"-online |tail -n 1)"
73
74             if [[ "$var" != "0" ]]; then
75                     echo "slave $slavename ${slavescurrent[$slavename]} was up for $var iterations"
76                 echo "slave $slavename ${slavescurrent[$slavename]} has gone offline, was $var iterations now reset to 0"
77             fi
78
79         echo "0" >> /tmp/"$slavename"-online
80             echo "$slavename down $(cat /tmp/$slavename-online | tail -n 10 | xargs)"
81             unset var
82
83     fi
84
85
86 done
87 }
88
89 main | sort | column -t