Hour power update
All checks were successful
Generate Power Graph / plot (push) Successful in 2m12s

This commit is contained in:
mrkmntal 2025-11-07 13:09:17 -05:00
commit 6a048792eb
3 changed files with 2250 additions and 6 deletions

View file

@ -7,7 +7,7 @@ APU_HWMON="/sys/class/hwmon/hwmon5" # APU sensor
GPU_HWMON="/sys/class/drm/card0/device/hwmon/hwmon4" # dGPU sensor
INTERVAL=1 # seconds between refreshes
LOGFILE="power_log.csv" # CSV output file
MAX_LINES=500 # limit to last 500 lines
RETENTION_SECONDS=3600 # keep roughly 1 hour of samples
# --- Helpers ---
read_watts() {
@ -57,12 +57,16 @@ while true; do
# --- Append to CSV ---
echo "$TIME,$APU_PWR,$GPU_PWR,$TOTAL,$APU_TEMP,$GPU_TEMP" >> "$LOGFILE"
# --- Keep only last $MAX_LINES lines ---
# --- Keep roughly 1 hour of samples (plus header) ---
MAX_SAMPLES=$(( (RETENTION_SECONDS + INTERVAL - 1) / INTERVAL ))
MAX_LINES_WITH_HEADER=$(( MAX_SAMPLES + 1 ))
LINES=$(wc -l < "$LOGFILE")
if (( LINES > MAX_LINES )); then
tail -n $MAX_LINES "$LOGFILE" > "${LOGFILE}.tmp" && mv "${LOGFILE}.tmp" "$LOGFILE"
if (( LINES > MAX_LINES_WITH_HEADER )); then
{
head -n 1 "$LOGFILE"
tail -n "$MAX_SAMPLES" "$LOGFILE"
} > "${LOGFILE}.tmp" && mv "${LOGFILE}.tmp" "$LOGFILE"
fi
sleep $INTERVAL
done