Linux Monitoring for cpu and Memory
Oswatcher logs
Using Tfactl :
tfactl analyze -comp osw -last 6h
tfactl oswbb
Cpu :
top
top -o %CPU | head -n 16
top -b -n 1 | head -n 12
top -b -n 1 | awk 'NR>7 && NR<11 {printf "top: %5s %6d %s %s\n",$9,$1,$12,$13}'
top -b -n 1 | head -n 20
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head -n 11
ps aux --sort -%cpu
ps aux | sort -nrk 3,3 | head -n 5
ps --sort=-pcpu | head -n 6
ps -Ao user,uid,comm,pid,pcpu,tty --sort=-pcpu | head -n 6
ps ahux --sort=-c | awk 'NR<=5{printf"%s %6d %s\n",$3,$2,$11}'
ps -eo pcpu,pid,user,args | tail -n +2 | sort -k1 -r -n | head -10
ps -eo pcpu,args --sort=-%cpu|head
ps ahux --sort=-c | awk 'NR<=5{printf"%s %6d %s\n",$3,$2,$11}'
mpstat 5 7 -- cpu snap
nmon
cat /proc/cpuinfo
cat /proc/meminfo
Memory :
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | awk 'NR==1 || NR<=11 { printf "%-8s %-8s %-40s %-6s %-6s\n", $1, $2, substr($3,0,40), $4, $5 }'
ps aux --sort -%mem
ps -eo pid,ppid,cmd,comm,%mem,%cpu --sort=-%mem | head -10
ps -eo pid,comm,%cpu,%mem --sort=-%mem | head -n 5
top -o %MEM
top -o %MEM | head -n 16
ipcs -l
free –m
IO
pidstat -d 1 3 | grep -v Linux | sort -k6 -nr | head -n 10
iostat -dx 1
ps -eo pid,comm,io_write,io_read --sort=-io_write | head -n 10
pidstat -d 1
sudo iotop -o
sudo iotop -o -a
sudo iotop -o -P --sort=read_bytes
#!/bin/bash
echo "Top 10 Processes by I/O Usage:"
echo "------------------------------"
# Check if iotop is available
if ! command -v iotop &> /dev/null
then
echo "Error: 'iotop' is not installed. Install it with: sudo apt install iotop"
exit 1
fi
# Run iotop for 3 seconds and show top 10 by I/O
sudo iotop -b -n 3 | grep -vE '^Total' | sort -k10 -nr | head -n 10
Load Average:
sar -q -f /var/log/sa/sa17
# cat load_usage.sh
#!/bin/bash
Hostnames=$(uname -n | cut -d. -f1)
os_type=$(uname -s)
case "$os_type" in
Linux)
# Define color variables
GREEN="\033[0;32m"
YELLOW="\033[0;33m"
NC="\033[0m" # No Color
cputhreshold=99.0
# Get the CPU load averages
load_avg_1min=$(uptime | awk -F'load average: ' '{print $2}' | cut -d ',' -f1 | tr -d ' ')
load_avg_5min=$(uptime | awk -F'load average: ' '{print $2}' | cut -d ',' -f2 | tr -d ' ')
load_avg_15min=$(uptime| awk -F'load average: ' '{print $2}' | cut -d ',' -f3 | tr -d ' ')
# Get the number of CPU cores
cpu_core=$(nproc --all)
# Calculate percentages
percentage_1min=$(echo "scale=2; ($load_avg_1min / $cpu_core) * 100" | bc)
percentage_5min=$(echo "scale=2; ($load_avg_5min / $cpu_core) * 100" | bc)
percentage_15min=$(echo "scale=2; ($load_avg_15min / $cpu_core) * 100" | bc)
if (( $(echo "$percentage_1min >= $cputhreshold" | bc -l) )); then
# Print the table header in a box
printf "+------------------+-------------------+------------------+-----------------+--------+\n"
printf "| %-16s | %-17s | %-16s | %-14s | %-06s |\n" "HostName" "Time Intervals" "Load Average" "System Load (%)" "Status"
printf "+------------------+-------------------+------------------+-----------------+--------+\n"
# Print the table rows
printf "| %-16s | %-17s | %-16s | %-15s | ${YELLOW}%-06s${NC} |\n" "" "1 minute" "$load_avg_1min" "$percentage_1min%" ""
printf "| %-16s | %-17s | %-16s | %-15s | ${YELLOW}%-06s${NC} |\n" "$Hostnames" "5 minutes" "$load_avg_5min" "$percentage_5min%" "High"
printf "| %-16s | %-17s | %-16s | %-15s | ${YELLOW}%-06s${NC} |\n" "" "15 minutes" "$load_avg_15min" "$percentage_15min%" ""
# Print the bottom border of the table box
printf "+------------------+-------------------+------------------+-----------------+--------+\n"
else
# Print the table header in a box
printf "+------------------+-------------------+------------------+-----------------+--------+\n"
printf "| %-16s | %-17s | %-16s | %-14s | %-06s |\n" "HostName" "Time Intervals" "Load Average" "System Load (%)" "Status"
printf "+------------------+-------------------+------------------+-----------------+--------+\n"
# Print the table rows
printf "| %-16s | %-17s | %-16s | %-15s | ${GREEN}%-06s${NC} |\n" "" "1 minute" "$load_avg_1min" "$percentage_1min%" ""
printf "| %-16s | %-17s | %-16s | %-15s | ${GREEN}%-06s${NC} |\n" "$Hostnames" "5 minutes" "$load_avg_5min" "$percentage_5min%" "Normal"
printf "| %-16s | %-17s | %-16s | %-15s | ${GREEN}%-06s${NC} |\n" "" "15 minutes" "$load_avg_15min" "$percentage_15min%" ""
# Print the bottom border of the table box
printf "+------------------+-------------------+------------------+-----------------+--------+\n"
fi
;;
*)
echo -e "This script is not supported for $os_type - $Hostnames"
;;
esac
Comments
Post a Comment