How to check the total log size of an application in PCF Metrics 1.6.x DB
search cancel

How to check the total log size of an application in PCF Metrics 1.6.x DB

book

Article ID: 298057

calendar_today

Updated On:

Products

VMware Tanzu Application Service for VMs

Issue/Introduction

Sometimes customer may want to know the log size of an application (in bytes) so that they can find the busiest application and adjust the application accordingly to avoid potential impact to PCF Metrics.

With our current tool set, we only have the ability to get the log size in lines, not in bytes.

This article is aimed to demonstrate steps of getting log size in bytes from PCF metrics DB.

Resolution

1) Login into App Metrics Postgres VM via 'bosh ssh' command.
2) Switch to root user via 'sudo su'.
3) Login into postgres DB via '/var/vcap/packages/postgres-9.6.8/bin/psql -h localhost -p 5524 -U pgadmin metrics'
4) Run the following SQL query.

select sum(pg_column_size(message)),application_id as total_size from app_log group by application_id;

Here is an example output:

   sum    |              total_size
----------+--------------------------------------
       88 | <APP-GUID>

The 1st column is the total log message size in bytes, the 2nd column is the application GUID.

5) (Optional) The following script can give you a more human-readable format of the output. Assuming you keep the output from step 4 in a text file called "message_size.csv" and you put it under the same folder as the script.
Once done you just execute the script and it will show you the 'name', 'space name', 'org name' of each application.

#!/bin/bash

while read line; do
  size=$(echo $line | awk -v FS=',' '{print $1}')
  app_guid=$(echo $line | awk -v FS=',' '{print $2}')
  app_name=$(cf curl /v2/apps/$app_guid | jq .entity.name)
  space_guid=$(cf curl /v2/apps/$app_guid/summary | jq .space_guid)
  space_guid=$(echo $space_guid | sed 's/"//g')
  space_name=$(cf curl /v2/spaces/$space_guid | jq .entity.name)
  org_guid=$(cf curl /v2/spaces/$space_guid | jq .entity.organization_guid)
  org_guid=$(echo $org_guid | sed 's/"//g')
  org_name=$(cf curl /v2/organizations/$org_guid | jq .entity.name)
  echo $line,$app_name,$space_name,$org_name
done < message_size.csv

Below is an example output, note that you may see lines with null for app name, space name and org name.
That means the app GUID belongs to a deleted app, but its log data still exists in App Metrics DB.
Usually, such log data will be removed after it reaches the log retention period (14 days by default) and you can simply ignore it.

88,<APP-GUID>,"scheduler-broker","scheduler","system"