You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.6 KiB

  1. #!/bin/bash
  2. # check-usability-of-sims
  3. # HS-Fulda - sebastian.rieger@informatik.hs-fulda.de
  4. #
  5. # changelog:
  6. # V1.0 initial version
  7. # usage
  8. if [ ! $# -gt 2 ] ; then
  9. echo -e "usage: $0 <username> <password> <timeout> [sim-regexp] [debug level], e.g.,\n"
  10. echo "$0 guest password 0.5"
  11. exit -1
  12. fi
  13. USERNAME=$1
  14. PASSWORD=$2
  15. TIMEOUT=$3
  16. if [ $4 ]; then
  17. SIM_FILTER_REGEXP=$4
  18. else
  19. SIM_FILTER_REGEXP="VIRLBENCH-(.*)@(.*)-[_a-zA-Z0-9]{6}"
  20. fi
  21. if [ $5 ]; then
  22. DEBUG=$5
  23. else
  24. DEBUG=0
  25. fi
  26. # get all running benchmark simulations
  27. SIMS=$(virl_std_client --username $USERNAME --password $PASSWORD --quiet --json simengine-list 2>&1 | egrep -o -e "$SIM_FILTER_REGEXP")
  28. if [ $DEBUG -gt 1 ]; then
  29. echo "Running simulations:"
  30. for SIM in $SIMS; do
  31. echo $SIM
  32. done
  33. echo
  34. fi
  35. # Check if the nodes are ready-for-use using websocket consoles
  36. TOTAL_USABLE_COUNT=0
  37. TOTAL_AVG_DURATION=0
  38. for SIM in $SIMS; do
  39. USABLE_COUNT=0
  40. AVG_DURATION=0
  41. WS_COUNT=$(virl_std_client --username $USERNAME --password $PASSWORD --quiet --json simengine-serial-port --session-id $SIM 2>&1 | grep -c "ws://")
  42. WS_NODES=$(virl_std_client --username $USERNAME --password $PASSWORD --quiet --json simengine-serial-port --session-id $SIM 2>&1 | grep "ws://")
  43. while [ $USABLE_COUNT -lt $WS_COUNT ]
  44. do
  45. USABLE_COUNT=0
  46. AVG_DURATION=0
  47. IFS=$'\n'
  48. for WS_NODE in $WS_NODES; do
  49. NODE=$(echo $WS_NODE | cut -d "\"" -f 2)
  50. WS_URL=$(echo $WS_NODE | cut -d "\"" -f 4)
  51. WS_RESULT=$(./check-reachability-websocket.py $WS_URL $NODE $TIMEOUT $DEBUG)
  52. if [ $? -eq 0 ]; then
  53. if [ $DEBUG -gt 0 ] ; then echo "$WS_RESULT: $NODE in $SIM is usable"; fi
  54. DURATION=$(echo $WS_RESULT | egrep -o -e '[0-9]\.[0-9]{6} \*sec elapsed\*' | cut -d ' ' -f 1)
  55. AVG_DURATION=$(awk "BEGIN {print $AVG_DURATION + $DURATION}")
  56. USABLE_COUNT=$(expr $USABLE_COUNT + 1)
  57. else
  58. if [ $DEBUG -gt 0 ] ; then echo "$WS_RESULT: $NODE in $SIM is unusable"; fi
  59. fi
  60. done
  61. done
  62. # compute average in millisecs
  63. TOTAL_AVG_DURATION=$(awk "BEGIN {print $TOTAL_AVG_DURATION + $AVG_DURATION}")
  64. TOTAL_USABLE_COUNT=$(expr $TOTAL_USABLE_COUNT + $USABLE_COUNT)
  65. AVG_DURATION=$(awk "BEGIN {print $AVG_DURATION / $USABLE_COUNT * 1000}")
  66. if [ $DEBUG -gt 0 ] ; then echo "$USABLE_COUNT of $WS_COUNT nodes in $SIM are usable... (avg console delay $AVG_DURATION ms)"; fi
  67. done
  68. # compute average in millisecs
  69. TOTAL_AVG_DURATION=$(awk "BEGIN {print $TOTAL_AVG_DURATION / $TOTAL_USABLE_COUNT * 1000}")
  70. if [ $DEBUG -gt 0 ] ; then echo "$TOTAL_USABLE_COUNT nodes usable total in all sims... (total avg console delay $TOTAL_AVG_DURATION ms)"; fi
  71. echo "avgconsoledelay:$TOTAL_AVG_DURATION"