I am looking to script a way to get an output that tells me how many instances I have running (not stopped) in PCF. I understand that there is a way to show how many instances there are through a concourse pipeline, but I want to know how many of them are actually running. Any help would be great! Thanks.
Asked
Active
Viewed 304 times
1 Answers
0
You can use the Cloud Foundry's cloud controller API to list your applications with their states. Then it's a simple script to count how many are running.
You can query the API via this endpoint: http://api.run.pivotal.io/v2/apps
You will need an API token; a simple way is to invoke cf oauth-token
from an authenticated prompt.
An example of invoking the API using curl and unix tools to count applications that are started:
curl -k -i --raw "http://api.run.pivotal.io/v2/apps" -H "Host: api.run.pivotal.io" -H "Authorization: bearer put_your_auth_token_here" | grep -Po '"state": "STARTED"' | cut -d: -f2 | tr -d '",' | wc -l

nimeshjm
- 1,665
- 10
- 13