You can do this for all worker nodes using the following bash command:
docker node ls | grep -v Leader | grep -v Reachable | cut -c 31-47 | grep -v HOSTNAME | xargs -I"SERVER" sh -c "echo SERVER; ssh SERVER docker stats --no-stream"
This command works as follows.
List all Docker swarm nodes:
docker node ls
Filter out the manager nodes:
grep -v Leader | grep -v Reachable
Select the ip-addresses of the worker nodes:
cut -c 31-47
Remove the column header from the result:
grep -v HOSTNAME
Print the ip-address of the worker node and execute docker stats on the worker node:
xargs -I"SERVER" sh -c "echo SERVER; ssh SERVER docker stats --no-stream"