A comprehensive bash script for analyzing basic server performance statistics on Linux servers.
This project implements a server monitoring script that provides essential performance statistics. It was created as part of the roadmap.sh backend developer roadmap project.
- Total CPU Usage - Real-time CPU utilization calculation
- Total Memory Usage - Free vs Used memory with percentage breakdown
- Total Disk Usage - Filesystem usage statistics with percentage
- Top 5 Processes by CPU - Most CPU-intensive running processes
- Top 5 Processes by Memory - Most memory-intensive running processes
- OS Version - Operating system and kernel information
- Uptime - System uptime and boot time
- Load Average - 1, 5, and 15-minute load averages
- Logged in Users - Current user sessions
- Failed Login Attempts - Security monitoring for failed logins
- Network Statistics - Active connections and interface information
server-stats/
├── src/
│ └── server-stats.sh # Main implementation script
├── tests/
│ └── test-server-stats.sh # Test suite
├── README.md # Project documentation
└── .gitignore # Git ignore policy
- Linux operating system
- Bash shell (4.0+)
- Standard Linux utilities:
ps,df,free,uptime,who,top
-
Clone the repository or download the script:
git clone <repository-url> cd server-stats
-
Make the script executable:
chmod +x src/server-stats.sh
Run the script directly:
./src/server-stats.shOr with bash:
bash src/server-stats.sh╔═══════════════════════════════════════════╗
║ SERVER PERFORMANCE STATISTICS ║
╚═══════════════════════════════════════════╝
========================================
OS Version
========================================
Ubuntu 22.04.3 LTS
Kernel: 5.15.0-91-generic
Architecture: x86_64
========================================
Uptime
========================================
up 45 days, 12:34:56
Boot time: 2024-01-15 08:00
========================================
Load Average
========================================
1 minute: 0.25
5 minutes: 0.32
15 minutes: 0.28
CPU Cores: 4
========================================
CPU Usage
========================================
Total CPU Usage: 12.5%
Top 5 CPU intensive processes:
------------------------------------------------
PID CPU % Command
------------------------------------------------
1234 5.2% python3
5678 3.1% node
...
========================================
Memory Usage
========================================
Total Memory: 15.6 GB
Used Memory: 8.2 GB (52.5%)
Available Memory: 7.4 GB (47.5%)
Top 5 Memory intensive processes:
------------------------------------------------
PID MEM % Command
------------------------------------------------
...
========================================
Disk Usage
========================================
Filesystem Usage:
----------------------------------------------------------------------
Filesystem Size Used Use% Mounted on
----------------------------------------------------------------------
/dev/sda1 50G 25G 50% /
========================================
Logged in Users
========================================
Users logged in: 2
...
Run the test suite to verify all requirements are met:
chmod +x tests/test-server-stats.sh
./tests/test-server-stats.shThe test suite verifies:
- All core requirement implementations
- Stretch goal implementations
- Bash syntax validation
- Script structure validation
- Functional tests (on Linux)
The script calculates CPU usage by reading /proc/stat values and computing the difference over a short interval, or uses top output when available.
Memory statistics are extracted from /proc/meminfo with proper calculation of:
- Total, used, and available memory
- Buffers and cached memory
- Swap usage with percentage
Uses df -h to get filesystem usage, with color-coded output based on usage percentage (<60% green, 60-80% yellow, >80% red).
- The script does not require root privileges for basic functionality
- Failed login detection may require elevated permissions for
/var/log/auth.logor/var/log/secure - Network statistics are gathered using publicly available tools
- Some features require Linux-specific utilities
- Failed login detection depends on available log files and permissions
- Network statistics require
ssornetstatcommands
- Fork the repository
- Create a feature branch
- Make your changes
- Run the test suite
- Submit a pull request
MIT License - See LICENSE file for details
- roadmap.sh for the project specification
- The Linux community for documentation on system monitoring tools