While Loops For Holistic Logging
while true
do
echo -e "$(date '+TIME:%Y-%m-%d-%H:%M:%S')\n $(docker stats --no-stream)" | tee -a docker_stats_--no-stream
done
- The next command is to capture the output of
docker info:while true do echo -e "$(date '+TIME:%Y-%m-%d-%H:%M:%S')\n $(docker info)" | tee -a docker_info done - Again, created another
tmuxwindow and wanted to capture the output ofdocker ps -a.while true do echo -e "$(date '+TIME:%Y-%m-%d-%H:%M:%S')\n $(docker ps -a)" | tee -a docker_ps_-a done - Command to capture the running processes.
while true do echo -e "$(date '+TIME:%Y-%m-%d-%H:%M:%S')\n $(ps aux)" | tee -a ps_aux done - Capture the output of
top.while true do echo -e "$(date '+TIME:%Y-%m-%d-%H:%M:%S')\n $(top -b -n1)" | tee -a top_output done - Installed the
sysstatpackage, to then be able to usempstat:sudo dnf install -y sysstat - Command to capture the
mpstatoutput for each processor core.while true do echo -e "$(date '+TIME:%Y-%m-%d-%H:%M:%S')\n $(mpstat -P ALL)" | tee -a mpstat done - Command to capture
iostatoutput.while true do echo -e "$(date '+TIME:%Y-%m-%d-%H:%M:%S')\n $(iostat)" | tee -a iostat done - Run
docker inspecton select containers to see CPU and memory usage.while true do echo -e "$(date '+TIME:%Y-%m-%d-%H:%M:%S')\n $(docker inspect <YOUR_CONTAINER_NAME_HERE>)" | tee -a docker_inspect_<YOUR_CONTAINER_NAME_HERE> done - In addition, alongside the
docker inspectcommand, take regular readings of the same container’scpuacct.usage_allfile.while true do echo -e "$(date '+TIME:%Y-%m-%d-%H:%M:%S')\n $(cat /sys/fs/cgroup/cpu/docker/<YOUR_CONTAINER_ID_HERE>/cpuacct.usage_all)" | tee -a cpuacct.usage_all_<YOUR_CONTAINER_ID_HERE> done - Capturing memory output.
while true do echo -e "$(date '+TIME:%Y-%m-%d-%H:%M:%S')\n $(free -h)" | tee -a free_-h done - Continuously capture the output of
dmesg.dmesg -T --follow > dmesg_output.log - Write the output of
ethtool -Sto a file.while true do echo -e "$(date '+TIME:%Y-%m-%d-%H:%M:%S')\n $(ethtool -S <YOUR_INTERFACE_HERE>)" | tee -a ethtool_-s_<YOUR_INTERFACE_HERE> done - Output CPU
sarreadings to a file.sar -u ALL 1 | tee -a sar_cpu - Output memory
sarreadings to a file.sar -r 1 | tee -a sar_memory - Output swap
sarreadings to a file.sar -S 1 | tee -a sar_swap - Output I/O
sarreadings to a file.sar -b 1 | tee -a sar_io - Record IO for individual block devices.
sar -p -d 1 | tee -a sar_block_device_io - Record context switches per second.
sar -w 1 | tee -a sar_context_switches - Note run queue and load average.
sar -q 1 | tee -a sar_run_queue_load_average - Check network statistics.
sar -n ALL 1 | tee -a sar_network_statistics