title: Performance monitoring script in linux
body: <p>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:</p>
  
  <pre><code>#!/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 "=================================================="
  ) &gt;&gt; $OUTPUT
  </code></pre>
  
  <p>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:</p>
  
  <ol>
  <li>Load Average</li>
  <li>CPU Idle Percentage</li>
  <li>Kernel Utilization </li>
  <li>Memory Utilization</li>
  <li>Swapping activity</li>
  </ol>
  
  <p>I'm trying to use these commands to generate these 5 files and seem to be having difficulty.</p>
  
  <pre><code>grep "load avg" /home/test/logs/ServerPerf180610.out | awk '{ print $6 }' | awk -F, '{ print $1 }' &gt; load_avg.txt
  grep "CPU states" /home/test/logs/ServerPerf180610.out | awk '{ print $3 }' | awk -F% '{ print $1 }' &gt; cpu_idle.txt
  grep "CPU states" /home/test/logs/ServerPerf180610.out | awk '{ print $7 }' | awk -F% '{ print $1 }' &gt; cpu_kernel.txt
  grep "Memory" /home/test/logs/ServerPerf180610.out | awk '{ print $5 }' | awk -FG '{ print $1 }' &gt; memory_util.txt
  grep "Memory" /home/test/logs/ServerPerf180610.out | awk '{ print $11 }' | awk -FG '{ print $1 }' &gt; swap_util.txt
  </code></pre>
  
  <p>While these commands run the output files are just empty. Does anyone know why I'm unable to generate these files?</p>
  
  <p>I really appreciate your help. </p>
  
  <p>Thank you,
  Aaron</p>
  
  <p><strong>UDPATE</strong>: Here is a copy of the output file:
  <a href="http://www.queencitytech.com/ServerPerfRepo180610.out" rel="nofollow noreferrer">http://www.queencitytech.com/ServerPerfRepo180610.out</a></p>