this is the funtions.sh script #!/bin/bash Function to get system load averages, CPU…
- User
this is the funtions.sh script
#!/bin/bash
Function to get system load averages, CPU info, and memory usage
hwstat_check() { echo "HWStat Check:"
echo "System Load Averages:" cat /proc/loadavg | awk '{printf "1 min: %.2f\t5 mins: %.2f\t15 mins: %.2f\n", $1, $2, $3}' echo "CPU Usage:" cpu_info=$(top -bn1 | grep 'Cpu(s)') us=$(echo $cpu_info | awk '{print $2}' | tr -d '%') sy=$(echo $cpu_info | awk '{print $4}' | tr -d '%') ni=$(echo $cpu_info | awk '{print $6}' | tr -d '%') id=$(echo $cpu_info | awk '{print $8}' | tr -d '%') wa=$(echo $cpu_info | awk '{print $10}' | tr -d '%') hi=$(echo $cpu_info | awk '{print $12}' | tr -d '%') si=$(echo $cpu_info | awk '{print $14}' | tr -d '%') st=$(echo $cpu_info | awk '{print $16}' | tr -d '%') echo "User Space: $us%" echo "System: $sy%" echo "Nice: $ni%" echo "Idle: $id%" echo "I/O Wait: $wa%" echo "Hardware IRQ: $hi%" echo "Software Interrupts: $si%" echo "Steal time: $st%" echo "Memory Usage:" free -h}
Function to get top memory-consuming processes, VE memory utilization, output traffic, and critical disk space usage
memtop_check() { echo "MemTop Check:"
echo "Top 5 Memory-Consuming Processes:" ps aux --sort -rss | head -n 5 echo "Top 5 VEs by Memory Guarantee Utilization:" sudo vzlist -o veid,kmemsize,oomguarpages,numproc,numtcpsock,tcpsndbuf,tcprcvbuf --sort=-oomguarpages | head -n 5 echo "Top 5 VEs by Output Traffic:" echo "VEID OUTPUT" for veid in $(sudo vzlist -Ho veid); do output=$(sudo vznetstat -v "$veid" -r | awk -v veid="$veid" '/^[0-9]/ {sum+=$5} END {print veid, sum}') echo "$output" done | sort -k2,2hr | head -n 5 echo "VEs with Critical Disk Space Usage:" sudo vzlist -Ho veid,diskspace,diskspace.s | awk 'BEGIN {FS=":"} {usage=($2/($3*100))*100} {if (usage > 95) print $1, usage "%"}'}
Function to get cgroup activity, directory counts, sleep and zombie processes
syspro_check() { # Add your syspro_check implementation here echo "Syspro Check: Placeholder" }
Function to analyze D state processes
dstate_check() { # Add your dstate_check implementation here echo "DState Check: Placeholder" }
Function to check network utilization, disk I/O, swap usage, and process counts
netchk_check() { # Add your netchk_check implementation here echo "NetChk Check: Placeholder" }
Function to verify resource limits, service availability, and log files
reslmt_check() { # Add your reslmt_check implementation here echo "Reslmt Check: Placeholder" }
Dispatch the check based on the provided check_name
check_name=2
- Assistant
This script contains several functions to check various system resource statuses and functionalities. Here is a brief overview of each function:
-
hwstat_check: This function retrieves system load averages, CPU usage information, and memory usage statistics. -
memtop_check: This function retrieves information on top memory-consuming processes, VE (Virtual Environment) memory utilization, output traffic, and critical disk space usage. -
syspro_check: This function is a placeholder for checking cgroup activity, directory counts, sleep processes, and zombie processes. -
dstate_check: This function is a placeholder for analyzing processes in a D state. -
netchk_check: This function is a placeholder for checking network utilization, disk I/O, swap usage, and process counts. -
: This function is a placeholder for verifying resource limits, service availability, and log files.
-