Kamal Nasser

Check How Many SaltStack Minions are Connected

October 10 2013 post

As you might know, you can run salt '*' test.ping to see which minions are connected. However, if you have a lot of minions set up, it's hard to keep track of which servers are missing from test.ping's output.

salt-key --list connected is another handy command that outputs all of the minions whose keys are accepted.

With these two commands, I was able to create a simple bash script that outputs the amount of minions that are actually connected to the master.

Sample output:

╭─user@saltmaster ~
╰─➤  ./connected.sh
26/26 (100.00%)

How to install

Simply create a file called connected.sh for instance with the contents of the connected.sh script below, and set executable permissions on it:

chmod u+x connected.sh

TOTAL=`salt-key --list accepted | wc -l`
TOTAL=`echo "$TOTAL-1" | bc`

CONNECTED=`salt '*' test.ping | wc -l`
CONNECTED=`echo "$CONNECTED/2" | bc`

PERCENT=`echo "scale=2;$CONNECTED/$TOTAL*100" | bc`