The container's memory usage is reported by cgroup and can be retrieved using the following procedures.
1. Retrieve the guid of the app.
######MBP:Downloads ###### cf app cook --guid aee32c4b-####-####-a74d-695676528000
2. Find out the diego_cell where this app instance is running.
#####MBP:Downloads ###### cf curl /v2/apps/aee32c4b-####-####-a74d-695676528000/stats
{
"0": {
"state": "RUNNING",
"isolation_segment": null,
"stats": {
"name": "cook",
"uris": [
"cookie.apps.####.apj-###.#####.com"
],
"host": "10.##.##.##",
"port": 61068,
"uptime": 2180,
"mem_quota": 1073741824,
"disk_quota": 1073741824,
"fds_quota": 16384,
"usage": {
"time": "2020-07-03T02:06:12+00:00",
"cpu": 0.008487803282072376,
"mem": 258871171,
"disk": 145375232
}
}
}
}
3. bosh ssh into this diego_cell.
4. Find out the instance_id of this app's container with a filter of the guid.
diego_cell/8b9fbe9f-####-####-a5af-525df19d920e:~# cfdot actual-lrps |grep aee32c4b-642c-####-####-695676528000|jq .
{
"process_guid": "aee32c4b-####-####-a74d-695676528000-647e08f1-####-####-ae9e-7a4719552a60",
"index": 0,
"domain": "cf-apps",
"instance_guid": "3b09f328-####-####-6781-ad69",
"cell_id": "8b9fbe9f-####-####-####-525df19d920e",
"address": "10.###.##.##",
"ports": [
{
"container_port": 8080,
"host_port": 61068,
"container_tls_proxy_port": 61001,
"host_tls_proxy_port": 61070
},
{
"container_port": 2222,
"host_port": 61069,
"container_tls_proxy_port": 61002,
"host_tls_proxy_port": 61071
}
],
"instance_address": "10.###.###.153",
"preferred_address": "HOST",
"crash_count": 1,
"crash_reason": "CELL/SSHD: Exited with status 137",
"state": "RUNNING",
"since": 1593739792034621000,
"modification_tag": {
"epoch": "6e4db726-####-####-7dc0-871cdc210b72",
"index": 5
},
"presence": "ORDINARY"
5. Go to the cgroup folder of this app instance with the instance_guid, /sys/fs/cgroup/memory/system.slice/garden.service/garden/instance_guid.
diego_cell/8b9fbe9f-####-####-####-525df19d920e:~# cd /sys/fs/cgroup/memory/system.slice/garden.service/garden/3b09f328-0053-####-####-ad69
6. Print out the memory usage, memory.usage_in_bytes.
diego_cell/8b9fbe9f-e883-####-####-525df19d920e:/sys/fs/cgroup/memory/system.slice/garden.service/garden/3b09f328-0053-####-####-ad69# more memory.usage_in_bytes 281792512
7. Observe that It matches the output of the cf app output:
DavidZhouMBP:Downloads dzhou$ cf app cook
Showing health and status for app cook in org system / space system as admin...
name: cook
requested state: started
routes: cookie.apps.####.apj-###.#####.com
last uploaded: Tue 30 Jun 12:07:01 CST 2020
stack: cflinuxfs3
buildpacks: client-certificate-mapper=1.11.0_RELEASE container-security-provider=1.16.0_RELEASE
java-buildpack=v4.26-offline-https://github.com/cloudfoundry/java-buildpack.git#e06e00b java-main java-opts java-security
jvmkill-agent=1.16.0_RELEASE open-jdk...
type: web
instances: 1/1
memory usage: 1024M
state since cpu memory disk details
#0 running 2020-07-03T01:29:52Z 0.9% 246.9M of 1G 138.6M of 1G