#linux #sre ## **System Load** - **Uptime:**   ```bash uptime ``` Displays how long the system has been running and the load averages. - **Active Connections and Processes:** ```bash netstat -tlpn # Requires package: net-tools ps auxf # Displays current processes in a tree view ``` **Memory Usage** - **Virtual Memory Stats (VMStat):** - **r:** Runnable processes (running or waiting to run in queue) - **b:** Processes in uninterruptible sleep (D in ps) ```bash vmstat # Summary of system processes, memory, paging, block IO, traps, and CPU. vmstat 1 5 -w # Run every 1 sec, print 5 times. First line is since reboot (wide mode). vmstat -s # Memory summary ``` - **Free Memory (in MB):** ```bash free -m ``` - **Out of Memory (OOM) Log Search:** ```bash grep -i oom /var/log/messages # or /var/log/syslog ``` **CPU Usage** - **CPU Summary:** ```bash top ``` - **CPU Balance (requires package **sysstat**):** ```bash mpstat -P ALL # Display CPU balance across all processors ``` - **Processor Information:** ```bash lscpu ``` - **Process-Level CPU Usage:** ```bash pidstat ``` **Disk Usage** - **Disk Statistics:** ```bash vmstat -d ``` - **Disk Free Space:** ```bash df -h # Human-readable format df -i # Show inode usage ``` - **Disk I/O Stats (every 1 sec):** ```bash iostat -xz 1 ``` - **Find Largest Files in / Directory:** ```bash du -mxS / | sort -n | tail -10 # List top 10 largest files or directories ``` **Network Statistics** - **Network Throughput (requires package **sysstat**):** ```bash sar -n DEV 1 # Display network device statistics every second sar -n TCP,ETCP 1 # Display TCP and extended TCP stats every second ``` - **Network Summary:** ```bash netstat -s ss -s # Socket statistics ``` - **Interface Statistics:** ```bash netstat -i ip -s link ``` **Distribution & Kernel Info** - **Distribution Version:** ```bash cat /etc/debian_version # For Debian-based systems lsb_release -a # Requires package: lsb-release ``` - **Kernel Information:** ```bash uname -a # Full system and kernel information sysctl -a # List all kernel parameters ``` **Log Management** - **Journalctl (system logs):** ```bash journalctl # View system logs journalctl -n 20 --no-pager -u nginx # View the last 20 lines of logs for nginx journalctl --since yesterday --until "1 hour ago" # Filter logs by time range journalctl -k # View kernel logs (dmesg) journalctl -p err # View logs of priority err (0, 1, 2, 3) ``` - **Kernel Logs:** ```bash dmesg | tail # View the most recent kernel messages ``` - **Other Logs:** ```bash tail /var/log/messages # System messages (/var/log/syslog or /var/log/kern.log) last -a # Show last logins ``` **Systemd Management** - **Service Management:** ```bash systemctl # List active units (services) systemctl cat <service> # View configuration for a specific service systemctl list-unit-files # List all unit files and their statuses (enabled/disabled/masked) systemctl reload unit # Reload a service after changes ``` - **Failed Units:** ```bash systemctl --failed # List failed services ``` - **Systemd Analyze:** ```bash systemd-analyze # Analyze boot-up performance systemd-analyze blame # Show a breakdown of services and their startup times ``` **Filesystems and Volumes** - **Disk and Filesystem Information:** ```bash fdisk -l # List disk partitions df -lT # Show local filesystems with type lsblk -f # Display block device information including filesystem file -s /dev/hda1 # Check filesystem on device blkid /dev/hda1 # Show UUID of filesystem ``` - **Mounts:** ```bash mount # Show currently mounted filesystems cat /etc/fstab # View static filesystem information ``` **Networking Tools** - **Socket Statistics:** ```bash ss -s # Show summary of sockets ``` - **Routing Table:** ```bash ip route # Display routing table netstat -r # View the routing table ``` - **Network Interfaces:** ```bash ifconfig # Show network interfaces lsof -i # List open network files (sockets) sar -n DEV # Network statistics ``` - **Firewall (iptables):** ```bash iptables -L # List iptables rules iptables -t nat -L # View NAT table ```