Created
August 5, 2019 13:24
-
-
Save corenel/d722385855521459a944abdd6bb3dbfc to your computer and use it in GitHub Desktop.
Logging system status
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
log_path=${HOME}/status_history.log | |
title="date,cpu_temp(celsius),cpu_load_1min(%),cpu_load_5min(%),cpu_load_15min(%),mem_free(MB),mem_total(MB)" | |
if [[ ! -f "${log_path}" ]]; then | |
echo -e ${title} > ${log_path} | |
echo -e ${title} | |
fi | |
tput setaf 3 | |
echo "Press CTRL+C to stop..." | |
tput sgr0 | |
for (( ; ; )) | |
do | |
date=$(date +"%Y-%m-%d %H:%M:%S") | |
cpu_load_1min=$(cat /proc/loadavg | awk '{printf "%.2f", $(NF-4)}') | |
cpu_load_5min=$(cat /proc/loadavg | awk '{printf "%.2f", $(NF-3)}') | |
cpu_load_15min=$(cat /proc/loadavg | awk '{printf "%.2f", $(NF-2)}') | |
cpu_temp=$(cat /sys/devices/virtual/thermal/thermal_zone0/temp | awk '{printf "%d\n", $1/1000}') | |
mem_usage=$(free -m | awk 'NR==2{printf "%s,%s", $3,$2 }') | |
log_str="${date},${cpu_temp},${cpu_load_1min},${cpu_load_5min},${cpu_load_15min},${mem_usage}" | |
echo -e ${log_str} >> ${log_path} | |
echo -e ${log_str} | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment