Monitoring Tools
Complete guide to monitoring your VPS with Prometheus, Grafana, Nagios, and other tools. Learn system monitoring, alerting, and performance tracking.
- Root or sudo access to your VPS
- Basic understanding of Linux system administration
- Email server configured for alerts (optional)
- Sufficient system resources for monitoring tools
- Understanding of your application stack
Effective monitoring is crucial for maintaining server health, performance, and availability. A good monitoring system helps you detect issues before they become critical problems.
Key Monitoring Areas:
- System Resources - CPU, memory, disk, network
- Application Performance - Response times, error rates
- Security Events - Failed logins, suspicious activity
- Service Availability - Uptime, service status
- Logs and Events - Application and system logs
# Basic system monitoring commands
# CPU usage
top
htop
mpstat 1
# Memory usage
free -h
vmstat 1
cat /proc/meminfo
# Disk usage
df -h
du -sh /var/log/*
iostat -x 1
# Network monitoring
ifconfig
ip addr
netstat -tlnp
ss -tlnpThe Prometheus and Grafana combination is one of the most popular open-source monitoring solutions. Prometheus handles metrics collection and storage, while Grafana provides beautiful dashboards and visualization.
Architecture Overview:
- Prometheus - Metrics collection and storage
- Grafana - Dashboard and visualization
- Node Exporter - System metrics exporter
- Alertmanager - Alert handling and routing
# Install Prometheus
sudo apt update
sudo apt install prometheus prometheus-node-exporter -y
# Start and enable services
sudo systemctl enable prometheus
sudo systemctl enable prometheus-node-exporter
sudo systemctl start prometheus
sudo systemctl start prometheus-node-exporter
# Check status
sudo systemctl status prometheus
curl http://localhost:9090
# Install Grafana
sudo apt install software-properties-common -y
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
sudo apt update
sudo apt install grafana -y
# Start Grafana
sudo systemctl enable grafana-server
sudo systemctl start grafana-server
# Access Grafana at http://your-server:3000
# Default credentials: admin/adminNagios is a powerful monitoring system that provides comprehensive monitoring of hosts, services, and networks. It's highly configurable and supports extensive plugin ecosystem.
Nagios Features:
- Host and service monitoring
- Alerting and notifications
- Performance data collection
- Web interface for status viewing
- Plugin architecture for extensibility
# Install Nagios
sudo apt update
sudo apt install nagios4 nagios-plugins -y
# Install additional plugins
sudo apt install nagios-plugins-contrib -y
# Configure Nagios admin password
sudo htpasswd -c /etc/nagios4/htpasswd.users nagiosadmin
# Add your server to monitoring
sudo nano /etc/nagios4/conf.d/localhost_nagios2.cfg
# Basic host definition example:
define host {
use linux-server
host_name your-server
alias Your VPS Server
address 127.0.0.1
}
# Restart Nagios
sudo systemctl restart nagios4
# Access web interface: http://your-server/nagios4
# Username: nagiosadminCommand-line monitoring tools provide real-time system information and are essential for troubleshooting and performance analysis.
Essential CLI Tools:
- htop - Interactive process viewer
- iotop - I/O monitoring
- nload - Network bandwidth monitoring
- dstat - System resource statistics
- glances - System monitoring overview
# Install monitoring tools
sudo apt install htop iotop nload dstat glances -y
# htop - Interactive process viewer
htop
# iotop - I/O monitoring
sudo iotop
# nload - Network monitoring
nload
# dstat - Comprehensive system stats
dstat -cdngy 1
# glances - System overview
glances
# Monitor specific processes
ps aux | grep apache
pgrep -f apache | xargs ps -p
# Monitor system logs in real-time
tail -f /var/log/syslog
tail -f /var/log/auth.logLog files contain valuable information about system events, errors, and security incidents. Effective log monitoring helps identify issues and security threats.
Log Monitoring Tools:
- rsyslog - System logging daemon
- logrotate - Log rotation utility
- journalctl - Systemd journal viewer
- fail2ban - Log-based intrusion prevention
- ELK Stack - Log aggregation and analysis
# View system logs
sudo journalctl -u apache2 -f # Follow Apache logs
sudo journalctl -u mysql -f # Follow MySQL logs
sudo journalctl --since "1 hour ago"
# Monitor specific log files
tail -f /var/log/apache2/access.log
tail -f /var/log/apache2/error.log
# Search logs for specific patterns
grep "error" /var/log/apache2/error.log
grep "404" /var/log/apache2/access.log
# Configure logrotate
sudo nano /etc/logrotate.d/apache2
# Example logrotate configuration:
/var/log/apache2/*.log {
daily
missingok
rotate 52
compress
delaycompress
notifempty
create 644 root root
postrotate
systemctl reload apache2
endscript
}
# Monitor disk space used by logs
du -sh /var/log/* | sort -hr | head -10Alerts notify you when something goes wrong with your system. Setting up proper alerting ensures you respond quickly to critical issues.
Alerting Strategies:
- Email notifications
- SMS alerts for critical issues
- Slack/Discord integrations
- PagerDuty/opsgenie for on-call
- Custom webhooks
# Configure email alerts
sudo apt install mailutils -y
# Test email functionality
echo "Test message" | mail -s "Test Subject" your-email@example.com
# Configure SMTP for alerts
sudo nano /etc/ssmtp/ssmtp.conf
# Example ssmtp configuration:
# root=your-email@example.com
# mailhub=smtp.gmail.com:587
# AuthUser=your-email@gmail.com
# AuthPass=your-app-password
# UseTLS=YES
# UseSTARTTLS=YES
# Create alert script
sudo nano /usr/local/bin/alert.sh
#!/bin/bash
SUBJECT="$1"
MESSAGE="$2"
TO_EMAIL="admin@example.com"
echo "$MESSAGE" | mail -s "$SUBJECT" $TO_EMAIL
# Make it executable
sudo chmod +x /usr/local/bin/alert.sh
# Test the alert system
/usr/local/bin/alert.sh "Test Alert" "This is a test alert from your server"Performance monitoring helps identify bottlenecks and optimize system resources. Regular performance analysis ensures optimal server operation.
Performance Metrics:
- CPU utilization and load averages
- Memory usage and swap activity
- Disk I/O and storage performance
- Network throughput and latency
- Application response times
# Performance monitoring commands
# CPU performance
vmstat 1
mpstat -P ALL 1
sar -u 1
# Memory analysis
free -m
cat /proc/meminfo
ps aux --sort=-%mem | head -10
# Disk performance
iostat -x 1
fio --name=readtest --rw=randread --bs=4k --numjobs=4 --runtime=10
# Network performance
sar -n DEV 1
iperf3 -s # Server mode
iperf3 -c server-ip # Client mode
# Application performance
# Apache/Nginx
curl -w "@curl-format.txt" -o /dev/null -s http://localhost/
# MySQL
mysql -e "SHOW PROCESSLIST;"
mysql -e "SHOW ENGINE INNODB STATUS;"
# PHP performance
php -r "echo 'PHP version: ' . phpversion() . PHP_EOL;"Can't find what you're looking for? Our support team is here to help.
