Server Monitoring and Logs
Effective monitoring and log analysis are crucial for maintaining a healthy, secure, and performant server. This guide introduces the best tools and commands for keeping an eye on your Linux system.
1. Real-Time Resource Monitoring
Understanding your server's current resource usage helps you identify bottlenecks instantly.
Using bpytop
bpytop is a visually appealing, interactive process viewer that provides a real-time overview of your CPU, RAM, disk, and network usage.
# Install bpytop
sudo apt install bpytop -y
# Run bpytop
bpytopUsing vmstat
vmstat reports information about processes, memory, paging, block IO, traps, and CPU activity.
# View summary every 2 seconds
vmstat 22. Disk Space Monitoring
Running out of disk space can cause databases to crash and services to fail.
Check overall disk usage
Use the df (disk free) command to see available space on all mounted filesystems:
df -hFind large files and directories
Use the du (disk usage) command to find what is consuming space:
# See the sizes of folders in the current directory
du -sh *
# Find the top 10 largest directories in /var
sudo du -ah /var | sort -rh | head -n 103. Understanding System Logs
Logs are your primary source of truth when troubleshooting errors or investigating security incidents. Most Linux logs are stored in the /var/log directory.
Viewing logs with journalctl
Systemd uses the journal system to manage logs. journalctl is the tool used to query these logs.
# View all logs (use space to paginate, q to quit)
journalctl
# Follow the log file in real-time (like tail -f)
journalctl -f
# View logs for a specific service (e.g., SSH)
journalctl -u sshEssential Log Files
If you need to read logs directly, here are the most important ones:
/var/log/syslogor/var/log/messages: General system messages and service logs./var/log/auth.logor/var/log/secure: Authentication logs, including SSH logins andsudousage./var/log/apt/history.log: History of apt package installations and updates.
Use tail to view the end of a log file:
# View the last 50 lines of the auth log
sudo tail -n 50 /var/log/auth.log4. Advanced Monitoring (Prometheus & Grafana)
For a visual and long-term monitoring solution, consider deploying Prometheus (to collect metrics) and Grafana (to visualize them). This setup allows you to create comprehensive dashboards alerting you before resources run out.
Looking for the right Linux VPS?
Put your project into practice right away: Our KVM VPS provide full root access, lightning-fast NVMe storage, and reliable KVM isolation. Flexible prepaid billing with no subscription and personal Discord support.