views:

123

answers:

1

Hello,

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 "##################################################"
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

A: 

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.

MJB
Actually, I apologize that was a typo on my part. When I ran the command it followed the same as the files.
Aaron
that makes sense. when i add the ignore case and proper "load average" search all i'm getting in the file is "day" with 4 zeros underneath?
Aaron
Did you also add the batch option to top? I think that top is generating screen control codes to highlight, blink, home, etc, and that might be messing up your output.
MJB
Also, there is no "memory" data. There are sections called Memory, but if you return only those lines you get no data. Also, there are no lines called "CPU States". Where did you get your filters? They just don't exist in the data.
MJB
I'm not exactly sure about the batch option. I actually have found this on a blog and have been trying to make it work for awhile now. Here is the page (part 2) http://kumudunix.blogspot.com/2010/01/unix-performance-monitoring-data_08.html It was originally written for Solaris and I modified some commands so they would work on linux. I guess its possible that by changing them I broke the script.
Aaron
From that blog, you can get to Part 1 which has the original script. However I did find some errors such as a missing "|" before each of the awk's. I do see what you mean by "memory" data.
Aaron
Well, I think you can make it work, but I also think that you are better off re-starting. There are probably linux commands and utilities that give you what you want. If, however, the point is to grow your own in an effort to learn, I say keep at it. But check your inputs and the steps, rather than waiting til the end.
MJB