Server Resource Monitoring with htop and glances is a common requirement for VPS administrators. This guide provides practical instructions that you can follow on Ubuntu 22.04/24.04 or Debian 12, though most steps apply to other distributions as well.
Prerequisites
- Basic familiarity with the Linux command line
- Root access to the server
- Root or sudo access to the server
- A registered domain name (for public-facing services)
- SSH client on your local machine
Initial Setup
After applying these changes, monitor the server's resource usage for at least 24 hours to ensure stability. Tools like htop, iostat, and vmstat can provide real-time insights into system performance.
# Systemd service management
sudo systemctl status nginx
sudo systemctl enable --now nginx
sudo systemctl restart nginx
# View service logs
sudo journalctl -u nginx -f --since "10 minutes ago"
# List all running services
systemctl list-units --type=service --state=running
These commands should be run as root or with sudo privileges. If you're using a non-root user, prefix each command with sudo.
- Scale vertically before scaling horizontally
- Implement caching at every appropriate layer
- Profile before optimizing - measure first
- Start with the minimum required resources
- Use connection pooling for database connections
Configuration Steps
For production deployments, consider implementing high availability by running multiple instances behind a load balancer. This approach provides both redundancy and improved performance under heavy load.
# Server resource monitoring
htop # Interactive process viewer
iostat -x 1 5 # Disk I/O stats (5 samples)
vmstat 1 5 # Virtual memory stats
ss -tlnp # Open listening ports
netstat -an | wc -l # Total connections
The configuration above sets the recommended values for a VPS with 2-4GB of RAM. Adjust the memory-related settings proportionally if your server has different specifications.
- Maintain runbooks for common operations
- Document all configuration changes
- Set up monitoring before going to production
Automation and Scheduling
The glances component plays a crucial role in the overall architecture. Understanding how it interacts with htop will help you make better configuration decisions.
# Systemd service management
sudo systemctl status nginx
sudo systemctl enable --now nginx
sudo systemctl restart nginx
# View service logs
sudo journalctl -u nginx -f --since "10 minutes ago"
# List all running services
systemctl list-units --type=service --state=running
Each line in the configuration serves a specific purpose. The comments explain the reasoning behind each setting, making it easier to customize for your specific use case.
Summary
You've successfully configured htop on your VPS. Remember to monitor performance, keep your software updated, and maintain regular backups. If you run into issues, consult the official documentation or open a support ticket for assistance.