bugfix to monitor script to correct resource usage queries

Two bugs are fixed by this commit. First, a typo in the format string used write
resource usage data to the systemlog caused the systemlog to (correctly) reject
the string as invalid json. The second fix is to handle a case where a .env file
is present, but does not define the APP_CONTAINER variable. In this case the
container name is left empty. This is not an immediate issue, but would become
problematic in the future if additional containers were to be added.
This commit is contained in:
2024-04-11 11:46:23 -07:00
parent e35fc56163
commit 6896f639bd
@@ -9,7 +9,7 @@ fi
# get container info # get container info
APP_CONTAINER=${APP_CONTAINER:-streamline-emr} APP_CONTAINER=${APP_CONTAINER:-streamline-emr}
if [ -f ${LOCATION}/.env ]; then if grep -q "^APP_CONTAINER=" ${LOCATION}/.env > /dev/null 2>&1; then
APP_CONTAINER=$(sed -n 's/APP_CONTAINER=//p' ${LOCATION}/.env) APP_CONTAINER=$(sed -n 's/APP_CONTAINER=//p' ${LOCATION}/.env)
fi fi
@@ -29,7 +29,7 @@ pushd $LOCATION > /dev/null
done done
# get resource usage # get resource usage
echo "checking streamline-emr resource usage" echo "checking streamline-emr resource usage"
status=$(docker stats --no-stream --format '{"name":"{{.Name}}","cpu_p":"{{.CPUPerc}}","mem_p":"{{.MemPerc}}","mem_u":"{{.MemUsage}}","net_io":"{{.NetIO}}"},"block_io":"{{.BlockIO}}"}' ${APP_CONTAINER}) status=$(docker stats --no-stream --format '{"name":"{{.Name}}","cpu_p":"{{.CPUPerc}}","mem_p":"{{.MemPerc}}","mem_u":"{{.MemUsage}}","net_io":"{{.NetIO}}","block_io":"{{.BlockIO}}"}' ${APP_CONTAINER})
if [ "${status}" ]; then if [ "${status}" ]; then
echo $status echo $status
if [ "$SYSTEMLOG" -eq 1 ]; then if [ "$SYSTEMLOG" -eq 1 ]; then