server_stats
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
server_stats [2015/05/10 15:03] – luke7858 | server_stats [2024/05/23 07:26] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 3: | Line 3: | ||
<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" | ||
Line 17: | Line 32: | ||
##################################### | ##################################### | ||
#Load Average | #Load Average | ||
- | # -o = | + | loadnow=$( |
- | # -h = | + | load15=$( |
- | # -e = pattern list. Specify one or more patters to be used during the search for input | + | |
- | 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 ' | ||
####################################### | ####################################### | ||
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 74: | 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 "" | ||
echo "### | echo "### | ||
- | echo -e "Top Process: " $UNDERLINE$topprocess$RESET | + | echo -e "Top Process: " $BLUE$topprocess$RESET |
- | threads=$( ps afx | grep -v grep | grep -ic " | + | |
- | + | cpuchecktest=$( echo - | awk -v topcpu=$topcpu '{print ( topcpu | |
- | cpucheck=$(echo $topcpu '<' 0.50 | bc -l ) | + | if [ "$cpuchecktest" -ge 1 ]; then |
- | if [ "$cpucheck" -ge 1 ]; then | + | |
echo -e "CPU % for SINGLE Top Process = " " | echo -e "CPU % for SINGLE Top Process = " " | ||
- | elif [ "$cpucheck" -le 0 ]; then | + | elif [ "$cpuchecktest" -le 0 ]; then |
echo -e "CPU % for SINGLE Top Process = " " | echo -e "CPU % for SINGLE Top Process = " " | ||
fi | fi | ||
+ | |||
+ | threads=$( ps afx | grep -v grep | grep -ci $topprocess ) | ||
echo -e " | echo -e " | ||
+ | #add all of the processes up and then print the total: | ||
+ | totalcpu=$( ps aux | grep $topprocess | grep -v grep | awk ' | ||
- | #add all of the processes up and then print them: | ||
- | totalcpu=$(ps aux | grep $topprocess | grep -v grep | awk ' | ||
- | #echo "cpu % for top process = " " | ||
- | echo -e "cpu usage for all $UNDERLINE$topprocess$RESET processes" | ||
- | totalcpucheck=$(echo $totalcpu '<' | + | totalcpuchecktest=$( echo - | awk -v totalcpu=$totalcpu '{print ( totalcpu |
- | if [ "$totalcpucheck" -ge 1 ]; then | + | if [ "$totalcpuchecktest" -ge 1 ]; then |
- | echo -e "Total CPU % for Process | + | echo -e "Total CPU % for $BLUE$topprocess$RESET |
- | elif [ "$totalcpucheck" -le 0 ]; then | + | elif [ "$totalcpuchecktest" -le 0 ]; then |
- | echo -e "Total CPU % for Process | + | echo -e "Total CPU % for $BLUE$topprocess$RESET |
- | fi | + | fi |
- | #echo $totalcpu | ||
- | echo "" | ||
- | #echo "$threads $threadstest" | + | echo "" |
echo $neat | echo $neat | ||
####################################### | ####################################### | ||
</ | </ |
server_stats.1431270183.txt.gz · Last modified: 2024/05/23 07:26 (external edit)