Better script to log and analyse L5 heat and activity

Due to several threads (over the years) that have discussed about the heat issues of L5, I’ve had this idea at some point about how useful it would be to have a graph that had lines for temps + CPU + network (or separated for cable/wifi/mobile) and maybe memory so that it would be easier to track how directly these influence each other. Even better would be if automatically the most active (CPU, network, memory use) apps would be included in the data, as to show why. The current graphical apps won’t do those simultaneously and they need to be on, which is a problem because they add to the load and they leave no record for later (unless you count screengrabs).

For better troubleshooting and general analysis, I’d like to propose a little brainstorming on this thread, can we create a script that would create a log record that gathers these values from various sensors or secondary sources for later analysis. The TODO list that I’d like input from all, for now:

  • specs for the data: what data is needed (minimum or optimal, probably not all possible) to analyse L5 heat creation and optimal use
  • data sources: which ones can be used (via script/terminal commands), which ones are efficient and give data in right format
  • output format: maybe write a CSV txt file that’s updated every few seconds, but it would be good to have it simple for looking at it in an office spreadsheet software and translate into a graph
  • for UI/UX i’m imagining for now a text script where user could adjust how often data is retrieved, how long it would run, and that it could be started from desktop icon (bonus, if it could be stopped from desktop too)

No full solutions needed, participate as much as you can.

5 Likes

I’m thinking top and some grepping to get basic use info…? But how to combine temperature to that?

Or maybe installing htop would be better (it’s got temp under F2), but I’m not sure how to get that info out of it.

Psensor would be GUI solution but it doesn’t record (that I know of), fit to L5 screen and does increase the load a bit.

2 Likes

I asked AI for an example, something to start from. Opinions and corrections welcome, as I’m not sure what’s going on yet or how this may need to be modified for L5.

NOTE: I haven’t tested this yet (that may take a few days for me atm - anyone is welcome to it)


Write a script example for debian based linux that captures all temperature readings in celsius from CPUs, battery, and other sensors, CPU load percentage, ram and zram memory uses in percentage, all network data traffic speeds in bytes per second for uploads and downloads, and forwards those values once per two seconds to a text file in csv format appending to a new line

Certainly! Below is a script example for a Debian-based Linux system that captures the required sensor readings, CPU load, memory usage, and network traffic speeds, and then appends these values to a CSV file every two seconds.

bash

#!/bin/bash

# Define the CSV file
CSV_FILE="/path/to/your/sensor_data.csv"

# Function to get temperature readings
get_temperatures() {
    echo -n "$(sensors | grep -E '(Core [0-9]+|Physical id [0-9]+|temp[0-9]+|Package id [0-9]+):' | awk '{print $3}' | tr -d '+°C')" | tr '\n' ','
}

# Function to get CPU load percentage
get_cpu_load() {
    top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1}'
}

# Function to get RAM and ZRAM usage in percentage
get_memory_usage() {
    total_mem=$(free -m | awk '/^Mem:/ {print $2}')
    used_mem=$(free -m | awk '/^Mem:/ {print $3}')
    zram_used=$(cat /proc/meminfo | grep Zram | awk '{print $2}')
    zram_total=$(cat /proc/meminfo | grep Zram | awk '{print $1}' | tr -d 'Zram:')

    ram_percent=$(echo "scale=2; ($used_mem / $total_mem) * 100" | bc)
    zram_percent=$(echo "scale=2; ($zram_used / $zram_total) * 100" | bc)

    echo -n "$ram_percent,$zram_percent"
}

# Function to get network traffic speeds in bytes per second
get_network_speeds() {
    OLD_RX=$(cat /proc/net/dev | grep 'eth0' | awk '{print $2}')
    OLD_TX=$(cat /proc/net/dev | grep 'eth0' | awk '{print $10}')
    sleep 1
    NEW_RX=$(cat /proc/net/dev | grep 'eth0' | awk '{print $2}')
    NEW_TX=$(cat /proc/net/dev | grep 'eth0' | awk '{print $10}')

    RX_SPEED=$(( (NEW_RX - OLD_RX) / 1 ))
    TX_SPEED=$(( (NEW_TX - OLD_TX) / 1 ))

    echo -n "$RX_SPEED,$TX_SPEED"
}

# Main loop
while true; do
    TEMPERATURES=$(get_temperatures)
    CPU_LOAD=$(get_cpu_load)
    MEMORY_USAGE=$(get_memory_usage)
    NETWORK_SPEEDS=$(get_network_speeds)

    TIMESTAMP=$(date +"%Y-%m-%d %H:%M:%S")

    echo "$TIMESTAMP,$TEMPERATURES,$CPU_LOAD,$MEMORY_USAGE,$NETWORK_SPEEDS" >> $CSV_FILE

    sleep 2
done

Explanation:

  1. Temperature Readings:
  • Uses the sensors command to fetch temperature readings from various sensors.
  1. CPU Load:
  • Uses the top command to get the CPU load percentage.
  1. Memory Usage:
  • Uses the free command to get RAM usage and reads from /proc/meminfo to get ZRAM usage.
  1. Network Traffic Speeds:
  • Reads network data from /proc/net/dev to calculate the upload and download speeds.
  1. Main Loop:
  • Collects all the necessary data and appends it to the CSV file every two seconds.

Note:

  • Replace /path/to/your/sensor_data.csv with the actual path where you want to store the CSV file.
  • Ensure that sensors is installed and configured on your system.
  • Adjust the network interface name (eth0) if your system uses a different interface.

Save this script to a file, for example, sensor_data.sh, make it executable with chmod +x sensor_data.sh, and then run it with ./sensor_data.sh.

[by Mistral Large 2]

3 Likes

Cool! ……….

1 Like

Oh, yes this is my kind of thread. Might take me a little to look at this closer myself but I’m definitely interested in this little research project.

2 Likes

What hardware and configuration are you using to run this? (Is it freedom respecting?) Maybe it’s a question for another topic that should split off

2 Likes