Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # mtop - A simple system monitoring tool
- # Define color codes
- RED='\033[0;31m'
- GREEN='\033[0;32m'
- YELLOW='\033[0;33m'
- BLUE='\033[0;34m'
- MAGENTA='\033[0;35m'
- CYAN='\033[0;36m'
- WHITE='\033[0;37m'
- NC='\033[0m' # No Color
- # Function to display CPU usage
- function cpu_usage() {
- echo -e "${CYAN}==================== CPU Usage ====================${NC}"
- mpstat 1 1 | awk '/Average:/ {printf "${YELLOW}:User %.2f%%\nSystem: %.2f%%\nIdle: %.2f%%\n${NC}", $3, $5, $12;}'
- echo ""
- }
- # Function to display Memory usage
- function memory_usage() {
- echo -e "${CYAN}==================== Memory Usage ====================${NC}"
- free -h | awk 'NR==2{printf "${YELLOW}Used: %s\nFree: %s\nTotal: %s\n${NC}", $3, $4, $2;}'
- echo ""
- }
- # Function to display Disk usage
- function disk_usage() {
- echo -e "${CYAN}==================== Disk Usage ====================${NC}"
- df -h | awk 'NR>1{printf "%-20s: ${YELLOW}%s used, %s available${NC}\n", $1, $3, $4;}'
- echo ""
- }
- # Function to display Top Processes
- function top_processes() {
- echo -e "${CYAN}==================== Top Processes ====================${NC}"
- echo -e "${WHITE}USER %MEM %CPU COMMAND${NC}"
- echo "-----------------------------------------------------"
- ps aux --sort=-%mem | awk 'NR<=10{printf "%-20s %-10s %-10s %-10s\n", $1, $3, $4, $11;}'
- echo ""
- }
- # Function to display Network Usage
- function network_usage() {
- echo -e "${CYAN}==================== Network Usage ====================${NC}"
- echo -e "${WHITE}Interface\tReceived\t\tSent${NC}"
- echo "-----------------------------------------------------"
- for iface in $(ls /sys/class/net/); do
- if [ "$iface" != "lo" ]; then
- rx_bytes=$(cat /sys/class/net/$iface/statistics/rx_bytes)
- tx_bytes=$(cat /sys/class/net/$iface/statistics/tx_bytes)
- echo -e "$iface\t\t$(numfmt --to=iec-i --suffix=B $rx_bytes)\t$(numfmt --to=iec-i --suffix=B $tx_bytes)"
- fi
- done
- echo ""
- }
- # Function to display Uptime
- function system_uptime() {
- echo -e "${CYAN}==================== System Uptime ====================${NC}"
- uptime | awk -F', ' '{printf "${YELLOW}Uptime: %s\n${NC}", $1;}'
- echo ""
- }
- # Function to display Load Average
- function load_average() {
- echo -e "${CYAN}==================== Load Average ====================${NC}"
- uptime | awk -F'load average:' '{printf "${YELLOW}Load Average: %s\n${NC}", $2;}'
- echo ""
- }
- # Main loop to refresh the output
- while true; do
- clear
- echo -e "${GREEN}==================== mtop ====================${NC}"
- cpu_usage
- memory_usage
- disk_usage
- network_usage
- system_uptime
- load_average
- top_processes
- echo -e "${MAGENTA}Press [CTRL+C] to stop...${NC}"
- sleep 1 # Reduced sleep duration for more real-time output
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement