How to monitor the size of the VCAP_SERVICES environment variables
search cancel

How to monitor the size of the VCAP_SERVICES environment variables

book

Article ID: 298327

calendar_today

Updated On:

Products

VMware Tanzu Application Service for VMs

Issue/Introduction

The VCAP_SERVICES environment variable is a system-provided variable that contains information about the services bound to your applications in TAS. With the number of services increasing, the size of VCAP_SERVICES environment variable can swell dramatically and eventually exceed the hard limit of131704 characters, which is hard coded in Linux. In this article, a method is introduced to retrieve all the environment variables and calculate the number of characters regarding VCAP_SERVICES.

Environment

Product Version: 2.11

Resolution

Here are the procedures to calculate the number of characters regarding VCAP_SERVICES
1.) Find a terminal with the following command available
  • cf
  • jq
  • echo
  • curl
2.) Log in with the command "cf login"

3.) Find the guid of the app with the command "cf app YOUR_APP_NAME --guid"
For instance,
ubuntu@opsmgr-xxx-com:~$ cf app spring-music --guid
707e905e-e4b4-422d-90e6-19f0f8a8b00e

4.) Retrieve the API enpoint with the command "cf api"
For example,
ubuntu@opsmgr-xxx-com:~$ cf api
API endpoint:   https://api.xxx.vmware.com
API version:    3.85.0

5.) Retrieve the total length of the VCAP_SERVICES with the following command. The CF_API is returned in step 4 while the APP_GUID can be found in step 3.
curl https://YOUR_CF_API/v3/apps/YOUR_APP_GUID/env -k -H "authorization: `cf oauth-token`" -s |jq .system_env_json.VCAP_SERVICES|wc -c
For your reference,
ubuntu@opsmgr-xxx-com:~$ curl https://api.xxx.vmware.com/v3/apps/707e905e-e4b4-422d-90e6-19f0f8a8b00e/env -k -H "authorization: `cf oauth-token`" -s |jq .system_env_json.VCAP_SERVICES|wc -c
    1231
As show in above example, the VCAP_SERVICES environment consists of 1231 characters in this specific application.

The above procedures target at one specific application. The following script cab be used to retrieve data for all apps in the current org / space. Target to desired org/space first before running this script.
  • Source codes:
opsmgr-xxx-com:~$ cat ./env_vcap_service.sh
#!/bin/bash

input=$(cf apps|sed '1,3d'|awk -F ' ' '{print $1}')

for i in $input; do
  guid=$(cf app $i --guid)
  vcap_service_length=$(curl https://api.xxx.vmware.com/v3/apps/$guid/env -k -H "authorization: `cf oauth-token`" -s |jq .system_env_json.VCAP_SERVICES|wc -c)
  echo -e $vcap_service_length \\t ": " $i
done
ubuntu@opsmgr-xxx-com:~$ 
  • Results:
opsmgr-xxx-com:~$ ./env_vcap_service.sh 
3        :  app-usage-scheduler
3        :  app-usage-server
313      :  app-usage-worker
3        :  apps-manager-js-blue
3        :  apps-manager-js-green
652      :  david-index
3        :  david-index-backend
3        :  david-index-front
4176     :  hello-pcf2
3        :  hello_php
1231     :  spring-music