开发者

Performance monitoring script in linux

I'm trying to create a script that will allow me to monitor CPU Utilization, Memory Utilization, I/O Utilization, and Network Utilization. Currently, I have a script that should run the necessary commands on linux. Hopefully in the end, I'll be able to run this every 15 or so minutes and then use specific information to analyze the data. Below is the script:

#!/bin/sh
########################################################
OUTPUT="ServerPerf`date '+%d%m%y'`.out"
(
echo "=================================================="
echo " Script Starting Time : `date` "
echo "================================================="
echo " Disk I/O Status "
echo "================================================="
echo
iostat
echo
echo "================================================="

echo "##################################################"
echo " NETWORK TCP PARAMETERS STATUS "
echo "#################################################开发者_StackOverflow#"
echo
echo
netstat -sp tcp
echo
echo " Processes List "
echo
ps -elf
echo
echo " END "
echo
echo "##################################################"
echo "##################################################"
echo " NETWORK CONNECTION PARAMETER "
echo "##################################################"
echo
echo
netstat -an
echo
echo
echo "##################################################"
echo " NETWORK TRAFFIC STATUS ON INTERFACES "
echo "##################################################"
echo
echo
netstat -i
echo
echo
echo "##################################################"
echo " SERVER MEMORY/CPU Utilization Report "
echo "##################################################"
echo
top -d1 -n 5
echo "=================================================="
echo " VMSTAT INFO "
echo "=================================================="
echo
vmstat 5 5
echo
echo "=================================================="
echo " Script Ending Time : `date` "
echo
echo "=================================================="
) >> $OUTPUT

Now, I'd like to take useful data from these files that are created. There are a few categories that the data can be sorted into:

  1. Load Average
  2. CPU Idle Percentage
  3. Kernel Utilization
  4. Memory Utilization
  5. Swapping activity

I'm trying to use these commands to generate these 5 files and seem to be having difficulty.

grep "load avg" /home/test/logs/ServerPerf180610.out | awk '{ print $6 }' | awk -F, '{ print $1 }' > load_avg.txt
grep "CPU states" /home/test/logs/ServerPerf180610.out | awk '{ print $3 }' | awk -F% '{ print $1 }' > cpu_idle.txt
grep "CPU states" /home/test/logs/ServerPerf180610.out | awk '{ print $7 }' | awk -F% '{ print $1 }' > cpu_kernel.txt
grep "Memory" /home/test/logs/ServerPerf180610.out | awk '{ print $5 }' | awk -FG '{ print $1 }' > memory_util.txt
grep "Memory" /home/test/logs/ServerPerf180610.out | awk '{ print $11 }' | awk -FG '{ print $1 }' > swap_util.txt

While these commands run the output files are just empty. Does anyone know why I'm unable to generate these files?

I really appreciate your help.

Thank you, Aaron

UDPATE: Here is a copy of the output file: http://www.queencitytech.com/ServerPerfRepo180610.out


Perhaps it is a typo, but the files you are searching and the files you are creating are different.

That is, the OUTPUT=... line says DAY-MONTH-YEAR, but the grep lines say MONTH-DAY-YEAR

EDIT: OK, you posted the output file. There are all kinds of special chars in there, from the top command. Can you add the batch (top -d1 -n1 -b) arg to top to hide that?

ANOTHER EDIT: Your grep commands appear to be case-specific. Is that intentional? The result has no matches for several of your grep filters. Try adding ignore case (grep -i) to the commands. Also, you are searching for "load avg" but the output says "load average" so you should never find it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜