Get A Leadership Summary for Service Groups in a Leader Topology


#1

I’ve been using this shell function to get a summary of leadership information for service group members in a ring:

service_group_leader() {
  if [ -z $2 ]
  then
    echo ""
    echo "usage: ${FUNCNAME[0]} '<ssh user@host>' '<service.group>'"
    echo ""
    return 1
  fi

  ssh_command=$1
  service_group=$2

  census_data=$($ssh_command 'curl --silent localhost:9631/census')
  leader_data=$(echo $census_data | jq -r ".census_groups | .\"$service_group\" | .population | .[] | select(.leader == true)")

  echo "Leader IP:        $(echo $leader_data | jq -r '.sys | .ip')"
  echo "Leader alive:     $(echo $leader_data | jq -r '.alive')"
  echo "Leader member_id: $(echo $leader_data | jq -r '.member_id')"
}