cloudfoundry - number of instances the cloud foundry app is running -


my app needs number of instances in running, (in runtime app uses info in program logic). (vcap_application env variables cannot provide info. ) calling api directly , using "instances" attribute option, dont know how call apps api directly in app. please let me know how call it. below link got app api: http://apidocs.cloudfoundry.org/218/apps/retrieve_a_particular_app.html

in order use api, first need authenticate. in order authenticate, need retrieve authorization endpoint.

to retrieve authorization endpoint, issue following curl request (i using pivotal web services in example, replace https://api.run.pivotal.io cloud foundry api endpoint using.

curl -h 'content-type: application/x-www-form-urlencoded;charset=utf-8' \ -h 'accept: application/json;charset=utf-8' \ https://api.run.pivotal.io/v2/info 

you'll looks this:

{ "name": "vcap", "build": "2222", "support": "http://support.cloudfoundry.com", "version": 2, "description": "cloud foundry sponsored pivotal", "authorization_endpoint": "https://login.run.pivotal.io", "token_endpoint": "https://uaa.run.pivotal.io", "min_cli_version": null, "min_recommended_cli_version": null, "api_version": "2.36.0", "app_ssh_endpoint": "ssh.run.pivotal.io:2222", "app_ssh_host_key_fingerprint": "e7:13:4e:32:ee:39:62:df:54:41:d7:f7:8b:b2:a7:6b", "logging_endpoint": "wss://loggregator.run.pivotal.io:443", "doppler_logging_endpoint": "wss://doppler.run.pivotal.io:443" } 

grab authorization_endpoint value, in case is:

https://login.run.pivotal.io

you need grab authentication token. issue following curl command replacing [my user name] , [my password] , [my authorization endpoint] values. please note should url encode password.

curl -h 'content-type: application/x-www-form-urlencoded;charset=utf-8' \ -h 'accept: application/json;charset=utf-8' \ -h 'authorization: basic y2y6' \ -d "username=[my user name]&password=[my password]&grant_type=password" \ [my authorization endpoint]/oauth/token 

you response looks this:

{ "access_token": "very_long_token.very_long_token.very_long_token", "token_type": "bearer", "refresh_token": "very_long_token.very_long_token.very_long_token", "expires_in": 599, "scope": "cloud_controller.read password.write cloud_controller.write openid", "jti": "shorter_value" } 

you interested in access_token value (access_token, refresh_token, , jti have been changed actual values in example)

now @ point can use api information our app. use link provided above, use api endpoint, need guid of app. instead recommend using list apps endpoint , use query filter on app information. here curl command (replace [my authorization token] auth token previous step, replace [my api endpoint] api endpoint use cloud foundry, replace [my app name] name of app:

curl -h "authorization: bearer [my authorization token]" \ [my api endpoint]/v2/apps?q=name:[my app name] -x 

you'll receive message looks this:

{ "total_results": 1, "total_pages": 1, "prev_url": null, "next_url": null, "resources": [ {   "metadata": {     "guid": "blah-blah",     "url": "/v2/apps/blah-blah",     "created_at": "time_stamp",     "updated_at": null   },   "entity": {     "name": "my-app",     "production": false,     "space_guid": "blah-blah",     "stack_guid": "blah-blah",     "buildpack": null,     "detected_buildpack": null,     "environment_json": {      },     "memory": 1024,     "instances": 3,     "disk_quota": 1024,     "state": "stopped",     "version": "blah-blah",     "command": null,     "console": false,     "debug": null,     "staging_task_id": null,     "package_state": "staged",     "health_check_type": "port",     "health_check_timeout": null,     "staging_failed_reason": null,     "staging_failed_description": null,     "diego": false,     "docker_image": null,     "package_updated_at": "time stamp",     "detected_start_command": "",     "enable_ssh": true,     "docker_credentials_json": {       "redacted_message": "[private data hidden]"     },     "space_url": "/v2/spaces/blah-blah",     "stack_url": "/v2/stacks/blah-blah",     "events_url": "/v2/apps/blah-blah/events",     "service_bindings_url": "/v2/apps/blah-blah/service_bindings",     "routes_url": "/v2/apps/blah-blah/routes"   } } ] } 

you can grab instances message. if want use api in original link, can grab metadata.guid use in call.

hope helps!


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -