Skip to content

althropic/Server-Performance-Stats

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Server Performance Stats

A comprehensive bash script for analyzing basic server performance statistics on Linux servers.

Overview

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.

Features

Core Requirements ✓

  • 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

Stretch Goals ✓

  • 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

Project Structure

server-stats/
├── src/
│   └── server-stats.sh    # Main implementation script
├── tests/
│   └── test-server-stats.sh  # Test suite
├── README.md              # Project documentation
└── .gitignore            # Git ignore policy

Requirements

  • Linux operating system
  • Bash shell (4.0+)
  • Standard Linux utilities: ps, df, free, uptime, who, top

Installation

  1. Clone the repository or download the script:

    git clone <repository-url>
    cd server-stats
  2. Make the script executable:

    chmod +x src/server-stats.sh

Usage

Run the script directly:

./src/server-stats.sh

Or with bash:

bash src/server-stats.sh

Output Example

╔═══════════════════════════════════════════╗
║      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
  ...

Testing

Run the test suite to verify all requirements are met:

chmod +x tests/test-server-stats.sh
./tests/test-server-stats.sh

Test Coverage

The test suite verifies:

  • All core requirement implementations
  • Stretch goal implementations
  • Bash syntax validation
  • Script structure validation
  • Functional tests (on Linux)

Technical Details

CPU Usage Calculation

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 Usage

Memory statistics are extracted from /proc/meminfo with proper calculation of:

  • Total, used, and available memory
  • Buffers and cached memory
  • Swap usage with percentage

Disk Usage

Uses df -h to get filesystem usage, with color-coded output based on usage percentage (<60% green, 60-80% yellow, >80% red).

Security Considerations

  • The script does not require root privileges for basic functionality
  • Failed login detection may require elevated permissions for /var/log/auth.log or /var/log/secure
  • Network statistics are gathered using publicly available tools

Limitations

  • Some features require Linux-specific utilities
  • Failed login detection depends on available log files and permissions
  • Network statistics require ss or netstat commands

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run the test suite
  5. Submit a pull request

License

MIT License - See LICENSE file for details

Acknowledgments

  • roadmap.sh for the project specification
  • The Linux community for documentation on system monitoring tools

About

A bash script for analyzing Linux server performance statistics. Features CPU, memory, disk usage, process monitoring, and system information.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages