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.

66 lines
1.5KB

  1. #!/bin/bash
  2. if [ -z ${1} ] ; then
  3. echo "usage: status.sh interface "
  4. exit
  5. fi
  6. CHECK="off";
  7. ACTIVITY="off";
  8. net=${1}
  9. ping_c=2 # stop after sending packets
  10. ping_i=1 # set interval in seconds
  11. ping_w=2 # timeout in seconds
  12. ping_iptmp=$(ip addr show $net | grep -o "inet [0-9]*\.[0-9]*\.[0-9]*" | grep -o "[0-9]*\.[0-9]*\.[0-9]*")
  13. ping_ip="$ping_iptmp.1"
  14. #ping_ip=10.13.13.1
  15. if [[ -d /sys/class/net/$net ]]; then
  16. CHECK="on";
  17. T1=$(cat /sys/class/net/$net/statistics/tx_bytes)
  18. ping -I $net -c $ping_c -i $ping_i -w $ping_w $ping_ip &> /dev/null
  19. T2=$(cat /sys/class/net/$net/statistics/tx_bytes)
  20. tot=$(( (T2 - T1)))
  21. if [ $tot -ne 0 ]; then
  22. ACTIVITY="on";
  23. fi
  24. fi
  25. #echo "check $CHECK activity $ACTIVITY"
  26. if [ "$CHECK" == "on" ] && [ "$ACTIVITY" == "on" ] ; then
  27. hybridswarm='Online'
  28. else
  29. hybridswarm='NotOnline'
  30. fi
  31. dockerswarm=$(docker info --format "{{json .}}" | jq .Swarm.LocalNodeState)
  32. tempswarm="${dockerswarm%\"}"
  33. tempswarm="${tempswarm#\"}"
  34. dockerswarm=$tempswarm
  35. if [ "$dockerswarm" == "active" ] ; then
  36. dockerswarmid=$(docker info --format "{{json .}}" | jq .Swarm.NodeID)
  37. tempswarm1="${dockerswarmid%\"}"
  38. tempswarm1="${tempswarm1#\"}"
  39. swarmlabid=$tempswarm1
  40. else
  41. swarmlabid="-1";
  42. fi
  43. if [ -z "$dockerswarm" ] ; then
  44. dockerswarm=none
  45. fi
  46. jq \
  47. --arg key0 'swarmlab' --arg swarmlab $dockerswarm \
  48. --arg key1 'hybrid' --arg hybrid $hybridswarm \
  49. --arg key2 'swarmlabid' --arg swarmlabid $swarmlabid \
  50. '. | .[$key0]=$swarmlab | .[$key1]=$hybrid | .[$key2]=$swarmlabid' <<<'{}'