Skip to content
Tutorials Center
My learning

Topics

Lesson 22 of 37 ยท Linux on the Pi

Temperature, Throttling and Performance Monitoring

Monitor a Raspberry Pi's health: read the CPU temperature, decode vcgencmd get_throttled flags, understand under-voltage, and measure load, memory and disk.

A Pi has no fan by default and runs from a cheap USB power supply, so heat and power are the two things that most often make it slow or unstable. The board protects itself: when it gets too hot or the voltage sags, the firmware lowers the CPU speed. This is called throttling. Knowing how to read these signals turns "my Pi feels slow" into a concrete cause.

This lesson shows the real commands read-only (they need Pi hardware) and builds runnable Python stand-ins that decode their output and compute the same statistics from sample data.

Reading the temperature

The SoC reports its temperature through two interfaces. The kernel file gives thousandths of a degree Celsius; the firmware tool prints a formatted value:

Terminal
cat /sys/class/thermal/thermal_zone0/temp   # e.g. 48312  means 48.312 C
vcgencmd measure_temp                       # e.g. temp=48.3'C
vcgencmd measure_clock arm                  # current CPU frequency in Hz

In Python you can read the file directly:

Python
def cpu_temp_c() -> float:
    with open("/sys/class/thermal/thermal_zone0/temp") as f:
        return int(f.read()) / 1000

Rough thresholds for the Pi 4 and Pi 5: below 60 C is comfortable; around 80 C the firmware starts to reduce the clock; at 85 C it throttles hard. A case with no airflow in a sunny window can get there under load. A heatsink or a small fan fixes most cases, and the official Pi 5 active cooler is designed for it.

The stand-in below converts the raw value and classifies it. The numbers are samples, not a live reading.

Python Stand-in: convert and classify temperatures

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Decoding get_throttled

vcgencmd get_throttled prints a hexadecimal bit mask, for example throttled=0x50005. Each bit is one condition. The lower four bits are now; the bits sixteen places higher mean "has happened since boot".

Bit Meaning
0 Under-voltage detected right now
1 ARM frequency capped now
2 Currently throttled
3 Soft temperature limit active
16 Under-voltage has occurred
17 Frequency capping has occurred
18 Throttling has occurred
19 Soft temperature limit has occurred

0x0 is perfect. 0x50005 means under-voltage and throttling both happening now and having happened before. Decode it with bit operations:

Python Stand-in: decode the get_throttled bit mask

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Under-voltage is the most common culprit. A Pi 4 needs a 5 V supply that can deliver 3 A, and a Pi 5 wants 5 A over USB-C PD. A thin or long cable drops voltage; a phone charger rated 1 A will cause warnings (and a lightning-bolt icon on the desktop). Fix it with the official supply and a short, thick cable. USB devices such as a camera, an SSD and a Wi-Fi dongle add up, so power hungry ones belong on a powered hub.

Load, memory and disk

Temperature tells you about hardware; these tell you about software:

Terminal
uptime                 # load average over 1, 5 and 15 minutes
top                    # live process list (q to quit); htop is nicer
free -h                # RAM and swap
df -h /                # disk space on the card
vmstat 1 5             # CPU, memory and I/O every second

The load average counts processes wanting a CPU. On a four-core Pi, a load of 4.0 means all cores are fully busy; consistently above 4 means a queue. A high wait time (wa in top) often means a slow SD card.

Logging your own metrics

You can read these in Python and log them for later graphing. This stand-in feeds a list of samples to a rolling monitor that reports the average and warns when a limit is crossed, the same logic a real monitor script would use with cpu_temp_c().

Python Stand-in: a rolling temperature monitor

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Averaging avoids false alarms from a single spike. With the systemd service lesson you can run such a monitor all the time and send results to the journal.

What to do about heat

flowchart TD
    A["Pi feels slow"] --> B{"get_throttled is 0x0?"}
    B -- "no, bit 0 or 16" --> C["Better power supply and cable"]
    B -- "no, bit 3 or 19" --> D["Heatsink, fan or airflow"]
    B -- "yes" --> E{"High load or memory use?"}
    E -- "yes" --> F["Find the process with top"]
    E -- "no" --> G["Check SD card speed and disk space"]

Start with the throttle flags, then move on to software causes.

Other tips: avoid overclocking unless you also add cooling; use a good A1/A2-rated card or boot from SSD; keep swap small on an SD card.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. The file /sys/class/thermal/thermal_zone0/temp contains 63400. What is the temperature?

    The value is in thousandths of a degree Celsius.
  2. 2. get_throttled reports 0x0. What does that mean?

    No flag bits are set, so there was no under-voltage or throttling.
  3. 3. Which is the most common cause of under-voltage warnings?

    The supply or cable cannot deliver the required current at 5 V.
  4. 4. On a four-core Pi, which load average suggests a constant queue of work?

    More runnable tasks than cores (4) means processes wait.

Summary

  • Read temperature from /sys/class/thermal/thermal_zone0/temp (thousandths of a degree) or vcgencmd measure_temp.
  • Around 80 C the firmware lowers the clock; keep the Pi cool with a heatsink or fan.
  • vcgencmd get_throttled is a bit mask: bit 0 under-voltage, bit 2 throttled, bits 16 and up "has occurred".
  • Use a proper power supply; most instability is power.
  • uptime, top, free and df explain software slowness.

Next: Network Setup: Wi-Fi, Ethernet and Static IPs