"how to get docker stats using shell script" Code Answer's
You're definitely familiar with the best coding language TypeScript that developers use to develop their projects and they get all their queries like "how to get docker stats using shell script" answered properly. Developers are finding an appropriate answer about how to get docker stats using shell script related to the TypeScript coding language. By visiting this online portal developers get answers concerning TypeScript codes question like how to get docker stats using shell script. Enter your desired code related query in the search bar and get every piece of information about TypeScript code related question on how to get docker stats using shell script.
how to get docker stats using shell script
#!/bin/bash
# This script is used to complete the output of the docker stats command.
# The docker stats command does not compute the total amount of resources (RAM or CPU)
# Get the total amount of RAM, assumes there are at least 1024*1024 KiB, therefore > 1 GiB
HOST_MEM_TOTAL=$(grep MemTotal /proc/meminfo | awk '{print $2/1024/1024}')
# Get the output of the docker stat command. Will be displayed at the end
# Without modifying the special variable IFS the ouput of the docker stats command won't have
# the new lines thus resulting in a failure when using awk to process each line
IFS=;
DOCKER_STATS_CMD=`docker stats --no-stream --format "table {{.MemPerc}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.Name}}"`
SUM_RAM=`echo $DOCKER_STATS_CMD | tail -n +2 | sed "s/%//g" | awk '{s+=$1} END {print s}'`
SUM_CPU=`echo $DOCKER_STATS_CMD | tail -n +2 | sed "s/%//g" | awk '{s+=$2} END {print s}'`
SUM_RAM_QUANTITY=`LC_NUMERIC=C printf %.2f $(echo "$SUM_RAM*$HOST_MEM_TOTAL*0.01" | bc)`
# Output the result
echo $DOCKER_STATS_CMD
echo -e "${SUM_RAM}%\t\t\t${SUM_CPU}%\t\t${SUM_RAM_QUANTITY}GiB / ${HOST_MEM_TOTAL}GiB\tTOTAL"
Source: stackoverflow.com
All those coders who are working on the TypeScript based application and are stuck on how to get docker stats using shell script can get a collection of related answers to their query. Programmers need to enter their query on how to get docker stats using shell script related to TypeScript code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about how to get docker stats using shell script for the programmers working on TypeScript code while coding their module. Coders are also allowed to rectify already present answers of how to get docker stats using shell script while working on the TypeScript language code. Developers can add up suggestions if they deem fit any other answer relating to "how to get docker stats using shell script". Visit this developer's friendly online web community, CodeProZone, and get your queries like how to get docker stats using shell script resolved professionally and stay updated to the latest TypeScript updates.