server_stats
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
server_stats [2015/05/10 14:35] – created luke7858 | server_stats [2024/05/23 07:26] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ---Work in progress--- | + | ===---Work in progress---=== |
<sxh bash> | <sxh bash> | ||
#!/bin/bash | #!/bin/bash | ||
+ | ##################################### | ||
+ | ##Release: | ||
+ | ##Version 1.3 | ||
+ | ##Author: Luke Shirnia | ||
+ | #################################### | ||
+ | #version 1.3 release notes: | ||
+ | #added total CPU usage for top process and all its threads | ||
+ | #added server uptime from / | ||
+ | #load average now pulled from / | ||
+ | #replaced 'free -m' with values from / | ||
+ | ##################################### | ||
+ | #Version 1.2 Update Notes: | ||
+ | #Ram usage now in MB | ||
+ | #removed ' | ||
##################################### | ##################################### | ||
##### | ##### | ||
Line 9: | Line 23: | ||
RED=$ESC_SEQ" | RED=$ESC_SEQ" | ||
RESET=$ESC_SEQ" | RESET=$ESC_SEQ" | ||
+ | BLUE=$ESC_SEQ" | ||
##### | ##### | ||
BOLD=$ESC_SEQ" | BOLD=$ESC_SEQ" | ||
bold=$(tput bold) | bold=$(tput bold) | ||
UNDERLINE=$ESC_SEQ" | UNDERLINE=$ESC_SEQ" | ||
- | # | ||
##################################### | ##################################### | ||
neat="############################################" | neat="############################################" | ||
##################################### | ##################################### | ||
#Load Average | #Load Average | ||
- | # -o = | + | loadnow=$( cut / |
- | # -h = | + | load15=$( |
- | # -e = pattern list. Specify one or more patters to be used during the search for input | + | |
- | #load2=$(w | grep -ohe 'load average[s: | + | |
- | loadnow=$(uptime | grep -ohe 'load average[s:][: ].*' | awk '{ print $3 }' | sed 's/,//'); | + | |
- | load15=$(uptime | grep -ohe 'load average[s:][: ].*' | awk '{ print $5 }'); | + | |
#Ram Usage | #Ram Usage | ||
- | free=$(free -m | grep -ohe '-/+ buffers/cache[: ].*' | + | totalc=$( grep MemTotal |
- | used=$(free -m | grep -ohe '-/+ buffers/cache[: ].*' | awk '{ print $3 }'); | + | usedc=$( ps -Fe --sort:-rss --no-headers | awk ' |
+ | free=$( printf " | ||
+ | total=$( printf " | ||
+ | used=$( printf " | ||
topramprocess=$(ps -Fe --sort:-rss --no-headers | head -1 | awk ' | topramprocess=$(ps -Fe --sort:-rss --no-headers | head -1 | awk ' | ||
topramrss=$(ps -Fe --sort:-rss --no-headers | head -1 | awk ' | topramrss=$(ps -Fe --sort:-rss --no-headers | head -1 | awk ' | ||
#CPU Stuff | #CPU Stuff | ||
- | # old command topprocess=$(ps -eo user, | + | topprocess=$(ps -eo user, |
- | topprocess=$(ps -eo user, | + | topcpu=$(ps -eo user, |
- | # | + | |
- | topcpu=$(ps -eo user, | + | serveruptime=$(awk ' |
- | #sed to remove [ ] | + | |
- | # ps -eo user, | + | |
####################################### | ####################################### | ||
echo $neat | echo $neat | ||
- | #echo -e $bold "bold test" $RESET | ||
#####Load Average##### | #####Load Average##### | ||
+ | echo "" | ||
+ | echo " | ||
echo "" | echo "" | ||
#1 min load check | #1 min load check | ||
- | loadcheck=$(echo $loadnow '<' | + | loadcheck=$(echo |
if [ " | if [ " | ||
- | | + | echo -e "Load Average: Current$GREEN " |
- | elif [ "$loadnow" -le 0 ]; then | + | elif [ "$loadcheck" -le 0 ]; then |
- | echo -e "Load Average: Current$RED " | + | |
fi | fi | ||
#15 min load check | #15 min load check | ||
- | loadcheck15=$(echo $load15 '<' | + | loadcheck15test=$(echo |
- | if [ "$loadcheck15" -ge 1 ]; then | + | if [ "$loadcheck15test" -ge 1 ]; then |
- | echo -e "Load Average: 15min Average$GREEN " | + | echo -e "Load Average: 15min Average$GREEN " |
- | elif [ "$loadcheck15" -le 0 ]; then | + | elif [ "$loadcheck15test" -le 0 ]; then |
echo -e "Load Average: 15min Average$RED " | echo -e "Load Average: 15min Average$RED " | ||
fi | fi | ||
+ | ##### | ||
echo "" | echo "" | ||
+ | echo "" | ||
+ | echo "### | ||
- | + | echo -e "Free Ram: " | |
- | ##### | + | |
- | echo -e "Free Ram: " | + | |
echo "Used RAM: " | echo "Used RAM: " | ||
- | #bc - the -l option will load the standard math library and default the scale to 20 | + | ramtest=$( printf " |
- | #ramtest=$( printf " | + | |
- | ramtest=$( printf " | + | |
- | #ramtest=9 | + | echo "" |
echo $ramtest" | echo $ramtest" | ||
if [ $ramtest -gt 20 ]; then | if [ $ramtest -gt 20 ]; then | ||
Line 79: | Line 93: | ||
echo -e "RAM WARNING: | echo -e "RAM WARNING: | ||
fi | fi | ||
- | echo "" | + | echo "" |
- | echo "TOP RAM CONSUMER: "" | + | |
- | echo " | + | |
+ | topramMB=$( printf " | ||
+ | ramtotalprocesses=$(ps -Fe --sort:-rss | grep -v grep | grep -ic $topramprocess) | ||
+ | |||
+ | echo -e "TOP RAM CONSUMER: "" | ||
+ | echo "RAM Usage (RSS): $topramMB MB" | ||
+ | echo "Total Number of RAM Processes: $ramtotalprocesses" | ||
+ | |||
+ | |||
+ | totalRAMall=$( printf " | ||
+ | rampercentage=$( printf " | ||
+ | |||
+ | |||
+ | #command below checks total ram usage of top RAM consumer and ALL of its threads and compares to total RAM avaiable. If it is higher than the threshold of 70% then a warning is produced. | ||
+ | totalramcheck=$(echo - | awk -v ramp=$rampercentage ' | ||
+ | if [ " | ||
+ | echo -e "Total RAM Usage for all $BLUE$topramprocess$RESET processes = " $GREEN$totalRAMall" | ||
+ | echo -e $GREEN$rampercentage$RESET" | ||
+ | elif [ " | ||
+ | echo -e "Total RAM usage for all $BLUE$topramprocess$RESET processes = " $RED$totalRAMall" | ||
+ | echo -e $RED$rampercentage$RESET" | ||
+ | fi | ||
##### | ##### | ||
echo "" | echo "" | ||
- | echo "---CPU usage--- " | + | echo "" |
- | echo "Top Process: " $topprocess | + | echo "###CPU usage###" |
- | #old command with ' | + | echo -e "Top Process: " $BLUE$topprocess$RESET |
- | threads=$( ps afx | grep -v grep | grep -ic " | + | |
- | #command below can be used to exclude grep from ps results. You can then add up all the values | + | cpuchecktest=$( echo - | awk -v topcpu=$topcpu ' |
- | #ps afx | grep / | + | if [ " |
+ | echo -e "CPU % for SINGLE Top Process = " " | ||
+ | elif [ " | ||
+ | echo -e "CPU % for SINGLE Top Process = " " | ||
+ | fi | ||
+ | |||
+ | threads=$( | ||
+ | echo -e " | ||
- | #threadstest=$(( $threads | + | #add all of the processes up and then print the total: |
- | echo " | + | totalcpu=$( ps aux | grep $topprocess | grep -v grep | awk ' |
- | cpucheck=$(echo $topcpu | + | |
- | if [ "$cpucheck" -ge 1 ]; then | + | totalcpuchecktest=$( echo - | awk -v totalcpu=$totalcpu |
- | echo -e "cpu % for process | + | if [ "$totalcpuchecktest" -ge 1 ]; then |
- | elif [ "$cpucheck" -le 0 ]; then | + | echo -e "Total CPU % for $BLUE$topprocess$RESET |
- | echo -e "cpu % for process | + | elif [ "$totalcpuchecktest" -le 0 ]; then |
+ | echo -e "Total CPU % for $BLUE$topprocess$RESET | ||
fi | fi | ||
- | #add all of the processes up and then print them: | + | |
- | #ps aux | grep / | + | |
- | #echo "cpu % for top process = " " | + | |
- | echo "cpu usage for all $thread processes =" | + | |
echo "" | echo "" | ||
- | #echo " | ||
echo $neat | echo $neat | ||
- | |||
####################################### | ####################################### | ||
- | |||
</ | </ |
server_stats.1431268519.txt.gz · Last modified: 2024/05/23 07:26 (external edit)