Logging and monitoring are among the most valuable skills every Raspberry Pi owner should learn. Whether your Raspberry Pi acts as a home server, IoT controller, media centre, web server, NAS, or development platform, understanding what your system is doing makes it significantly easier to identify problems before they become serious.
Many beginners only investigate their Raspberry Pi after something has already failed. However, Linux continuously records detailed information about hardware, software, networking, services and applications. Combined with live monitoring tools, these logs provide an accurate picture of how your Raspberry Pi is performing.
This guide explores the most important logging systems, monitoring techniques, diagnostic commands and best practices that help keep a Raspberry Pi reliable over the long term.
What Is Logging?
Logging is the process of recording events that occur while the operating system and applications are running.
Every important activity may generate log entries, including:
- System startup
- Shutdown events
- User logins
- Network connections
- Service failures
- Hardware errors
- USB device detection
- Application crashes
- Security events
- Software updates
Each event is timestamped, allowing administrators to reconstruct exactly what happened before a problem occurred.
Without logs, diagnosing issues often becomes guesswork.
What Is Monitoring?
Monitoring is different from logging.
Logging records historical events.
Monitoring observes the current state of the system.
Typical monitoring includes:
- CPU usage
- Memory usage
- Disk usage
- Network traffic
- Temperature
- Running processes
- Storage health
- System load
- Service status
Good monitoring allows problems to be identified before users even notice them.
Why Logging Matters
Suppose a Raspberry Pi reboots unexpectedly every few hours.
Without logs you might suspect:
- Faulty power supply
- Software bug
- Overheating
- SD card corruption
- Memory problems
The system logs may immediately reveal messages such as:
Under-voltage detected
or
Kernel panic
or
Out of memory
Finding the actual cause can reduce troubleshooting from hours to minutes.
The Linux Logging System
Modern Raspberry Pi OS uses systemd together with the system journal.
Older Linux systems primarily relied on plain text log files managed by rsyslog.
Today both methods often coexist.
Common log locations include:
/var/log/
Inside this directory are numerous files containing information from different parts of the operating system.
Examples include:
auth.log
kern.log
daemon.log
syslog
boot.log
dpkg.log
Each serves a different purpose.
Viewing the System Journal
One of the most useful commands is:
journalctl
This displays messages stored by systemd.
Because there may be thousands of entries, filtering becomes essential.
To view only today’s messages:
journalctl --since today
To show recent messages:
journalctl -n 50
To continuously watch new entries:
journalctl -f
This behaves similarly to watching a live log file.
Viewing Traditional Log Files
Many logs remain as plain text.
For example:
cat /var/log/syslog
However, large files are easier to browse using:
less /var/log/syslog
Useful navigation includes:
- Space to scroll
- Up and down arrows
- Search using
/ - Press q to quit
Following Logs Live
The tail command displays the end of a file.
tail /var/log/syslog
To continuously monitor changes:
tail -f /var/log/syslog
This is particularly useful while:
- Restarting services
- Plugging in USB devices
- Testing applications
- Debugging Python programs
As events occur, new log entries appear immediately.
Monitoring CPU Usage
One of the first things to monitor is processor activity.
The classic utility is:
top
This updates every few seconds and displays:
- CPU utilisation
- Memory usage
- Running processes
- Load averages
- Process IDs
- User ownership
Processes consuming excessive CPU quickly become obvious.
Using htop
Many users prefer:
htop
Advantages include:
- Colourful interface
- Easier navigation
- Mouse support
- CPU history graphs
- Memory graphs
- Process searching
- Process filtering
It is often considered one of the best Linux monitoring tools.
Understanding Load Average
Load average is often misunderstood.
Three numbers represent average system load over:
- 1 minute
- 5 minutes
- 15 minutes
For a Raspberry Pi with four CPU cores:
0.50
means the processor is lightly loaded.
4.00
means all cores are busy.
8.00
means processes are waiting for CPU time.
Consistently high load averages may indicate inefficient software or insufficient processing power.
Monitoring Memory Usage
Memory pressure causes many Raspberry Pi performance problems.
Use:
free -h
Example output:
Total
Used
Free
Shared
Buffers
Cache
Available
The “Available” value is usually more useful than “Free” because Linux intentionally uses spare memory for caching.
Monitoring Storage Usage
Storage can fill unexpectedly due to logs, databases or media files.
Check available space:
df -h
Example:
Filesystem
Size
Used
Available
Use%
If storage approaches 100%, services may begin failing.
Finding Large Directories
To identify storage usage:
du -sh *
Or recursively:
du -h --max-depth=1 /
This quickly identifies folders consuming excessive space.
Monitoring Temperature
Temperature directly affects stability.
Check current temperature:
vcgencmd measure_temp
Example:
temp=47.2'C
Typical values:
- Idle: 35–50°C
- Moderate load: 50–65°C
- Heavy load: 65–80°C
Above approximately 80°C, CPU throttling may begin.
Detecting Thermal Throttling
Firmware records throttling events.
Check:
vcgencmd get_throttled
A value of:
0x0
indicates no throttling has occurred.
Other values may indicate:
- Under-voltage
- Current throttling
- Temperature throttling
This command is invaluable when diagnosing unexplained slowdowns.
Monitoring Network Activity
Several tools monitor network performance.
Useful commands include:
ip addr
Shows network interfaces.
ip route
Displays routing information.
ss -tuln
Shows listening ports.
ping
Tests network connectivity.
Watching Running Services
System services can be monitored using:
systemctl status nginx
or
systemctl status ssh
This displays:
- Running status
- Recent log entries
- Startup time
- Exit codes
- Failure messages
Monitoring Failed Services
To identify failed services:
systemctl --failed
This provides a quick overview of components requiring attention.
Monitoring Boot Performance
Slow boot times may indicate problematic services.
View boot timing:
systemd-analyze
More detailed analysis:
systemd-analyze blame
This lists services in order of startup duration, helping identify bottlenecks.
Monitoring Process Resources
Detailed information about individual processes can be viewed with:
ps aux
To locate Python programs:
ps aux | grep python
This displays CPU usage, memory usage, runtime and command-line arguments.
Monitoring Disk Activity
High storage activity may indicate excessive logging or inefficient applications.
Useful tools include:
- iostat
- iotop
- vmstat
These provide insight into:
- Read operations
- Write operations
- Queue length
- Wait times
Monitoring Log Growth
Some applications generate very large logs.
Check directory size:
du -sh /var/log
Large or rapidly growing logs may indicate recurring software problems or debugging left enabled.
Log Rotation
Linux automatically prevents logs from growing forever.
The log rotation system:
- Compresses old logs
- Archives previous files
- Deletes very old entries
- Creates new active log files
This prevents storage exhaustion.
Monitoring Custom Python Applications
Python applications should generate their own logs.
Example:
import logging
logging.basicConfig(
filename="sensor.log",
level=logging.INFO
)
logging.info("Temperature reading successful")
Advantages include:
- Easier debugging
- Historical analysis
- Error tracking
- Performance measurements
Remote Monitoring
Multiple Raspberry Pi systems can be monitored remotely.
Common approaches include:
- SSH
- Central log servers
- Dashboard software
- SNMP
- MQTT status reporting
This is especially useful when managing fleets of IoT devices.
Automating Health Checks
Simple shell scripts can periodically check:
- Disk usage
- CPU temperature
- Available memory
- Network connectivity
- Running services
If thresholds are exceeded, the script can:
- Write a log
- Restart a service
- Send an email
- Trigger an alert
Automation often prevents small issues becoming major outages.
Common Problems Revealed by Logs
System logs frequently expose issues such as:
- Power supply instability
- SD card failures
- Memory exhaustion
- USB disconnects
- Driver errors
- Network failures
- Authentication failures
- Service crashes
- Permission errors
- Filesystem corruption
Learning to interpret these messages significantly reduces troubleshooting time.
Best Practices
To maintain a healthy Raspberry Pi:
- Review logs regularly rather than only after failures.
- Monitor CPU temperature, memory and storage usage.
- Keep sufficient free disk space.
- Use descriptive logging in your own applications.
- Rotate or archive custom logs where appropriate.
- Investigate repeated warning messages instead of ignoring them.
- Test monitoring scripts before relying on them in production.
- Monitor long-running services for memory leaks or unexpected restarts.
- Record changes made to the system so they can be correlated with log entries.
Conclusion
Effective logging and monitoring transform a Raspberry Pi from a simple hobby computer into a reliable platform suitable for long-term projects, home servers and professional deployments. By combining system logs with real-time monitoring tools, you gain complete visibility into the health of your device, making it far easier to diagnose faults, optimise performance and maintain stable operation.
Whether you are running a web server, home automation platform, media centre or custom IoT solution, investing time in learning Linux logging and monitoring techniques will save countless hours of troubleshooting. Developing the habit of checking logs, watching system resources and automating health checks ensures your Raspberry Pi continues to perform reliably even under demanding workloads.
