Hi
Can we monitor service replicas from a manager node using a bash script? I googled but didn’t find any useful documents. Can you please help me with this.
A quick response will be appreciated.
Thanks
Share and learn in the Docker community.
Hi
Can we monitor service replicas from a manager node using a bash script? I googled but didn’t find any useful documents. Can you please help me with this.
A quick response will be appreciated.
Thanks
What do you mean by “monitor service replicas” ?
Counting how many replicas the service has ?
docker service ps myServiceName --filter desired-state=running --format "{{.Name}}"|wc -l
should do the trick
If you prefer to go wild on json output instead, try docker service ps myServiceName --filter desired-state=running --format='{{json .}}'
. Then pipe it into jq
and do whatever you like with it!
Update: instead of returning a sinlge json array with all replica elements, it returns all replicas in a seperate json, which kind of beats the idea to do some jq magic on the output. Pitty.