Phase 4: Optimize & Monitor
Objective
Optimize system performance and establish observability by tuning kernel parameters, configuring logging, and deploying a monitoring stack. This checkpoint demonstrates how to measure, analyze, and visualize system health in production-like environments.
Implementation
Resource Monitoring
- Collect baseline metrics for CPU, memory, and disk utilization.
- Use tools to observe system activity.
htop # Real-time process and CPU usage
vmstat 2 # System activity every 2 seconds
iostat -x # Detailed disk I/O statistics
Kernel Tuning
- Persist changes in
/etc/sysctl.conf. - Tune TCP settings for better network performance.
sudo sysctl -w net.ipv4.tcp_fin_timeout=30
sudo sysctl -w net.ipv4.tcp_tw_reuse=1
- Adjust swappiness (controls swap usage).
sudo sysctl vm.swappiness=10
Logging Configuration
- Ensures logs are rotated, compressed, and managed efficiently.
- Configure log rotation for Nginx logs.
sudo nano /etc/logrotate.d/nginx
/var/log/nginx/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 640 www-data adm
sharedscripts
postrotate
systemctl reload nginx > /dev/null
endscript
}
Monitoring Stack Setup
- Configure Prometheus to scrape system metrics and Nginx request metrics.
- Build Grafana dashboards for:
- CPU utilization
- Memory usage
- Disk I/O
- Nginx request throughput
- Install Prometheus (metrics collection) and Grafana (visualization).
sudo apt install prometheus grafana -y
Deliverable
- Performance Report: Document baseline metrics, tuning changes, and observed improvements.
- Grafana Screenshot: Dashboard visualizing CPU, memory, disk, and Nginx metrics.
Checkpoint
Learners must:
- Identify one bottleneck (e.g. high CPU usage, memory pressure, disk latency).
- Propose a fix (e.g. kernel tuning, scaling resources, optimizing Nginx configuration).
Hackers Notebook
Performance tuning and observability are critical for production readiness:
- Resource monitoring tools (
htop,vmstat,iostat) provide real-time and historical insights. - Kernel tuning allows administrators to optimize memory and network behavior for workload demands.
- Log rotation ensures disk efficiency and long-term auditability.
- Prometheus + Grafana form a modern monitoring stack, enabling visualization of system health and application metrics.
By combining tuning and observability, administrators can detect bottlenecks, validate improvements, and maintain system reliability under load.

Updated on Dec 31, 2025