This script provides real-time monitoring of system resources on an Ubuntu server. It displays various metrics, including CPU and memory usage, network statistics, disk usage, system load, memory usage, process details, and service statuses. The dashboard can be refreshed every few seconds and allows users to view specific sections of the dashboard using command-line switches.
- Top 10 Applications: Displays the top 10 applications consuming the most CPU and memory.
- Network Monitoring: Shows the number of concurrent connections, packet drops, and network traffic (MB in and out).
- Disk Usage: Displays disk space usage by mounted partitions and highlights partitions using more than 80% of disk space.
- System Load: Shows the current load average and a breakdown of CPU usage.
- Memory Usage: Displays total, used, and free memory, including swap memory usage.
- Process Monitoring: Lists the number of active processes and the top 5 processes by CPU and memory usage.
- Service Monitoring: Monitors the status of essential services like
sshd
,nginx
, andiptables
.
To set up the environment on an EC2 Ubuntu instance, follow these steps:
-
Update Package Lists:
sudo apt update
-
Install Required Packages:
sudo apt install -y net-tools procps sysstat gawk
-
Make the Script Executable:
- Save the script to a file, e.g.,
monitor.sh
. - Make it executable with:
chmod +x monitor.sh
- Save the script to a file, e.g.,
Run the script by executing the following command:
./monitor.sh
The script will display a full dashboard by default. You can also use command-line switches to view specific parts of the dashboard:
-
Display Top 10 Applications:
./monitor.sh -top
-
Network Monitoring:
./monitor.sh -network
-
Disk Usage:
./monitor.sh -disk
-
System Load:
./monitor.sh -load
-
Memory Usage:
./monitor.sh -memory
-
Process Monitoring:
./monitor.sh -process
-
Service Monitoring:
./monitor.sh -services
When running ./monitor.sh -disk
, you might see:
Partitions with more than 80% disk usage will be highlighted in red.
- Instance Type: The script can run on a
t2.micro
instance, but monitor CPU and memory usage to ensure it meets your performance needs. If performance issues arise, consider upgrading to a larger instance type. - Script Refresh: The script refreshes data every 5 seconds. Adjust the
sleep
interval in the script if needed.
- Script Errors: Ensure all required packages are installed and that the script has execute permissions.
- Performance Issues: If running on a
t2.micro
instance, check CPU and memory usage. Consider upgrading the instance if necessary.