System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple Core Monitoring script

 
Boerbokrib
Advisor

Multiple Core Monitoring script

Hi

 

I have been asked to monitor the cores of the multicore processors on our linux app servers.

 

I have the below script which catches the info to a file. I pull this into an excel spread sheet and use the following formula to get the percentage of each core used.(1000*($DIFF_TOTAL-$DIFF_IDLE)/$DIFF_TOTAL)/10".

 

However when i do a ps there are multiple sessions of the script running. How would i get this to run infinitley collect the data but not spawn so many sessions?

 


#!/bin/bash
# script to capture the core statistics of the cpu's
#Wayne McN 18/10/2011

DAT=`date +"%Y%m%d"`
HOSTNAM=`hostname -s`
LOGDIR=/home/sys_logs
LOGNAM=$LOGDIR/${HOSTNAM}_cpu_core.$DAT
dtim=`date +"%T"`


CPU_NO=`cat /proc/stat | grep cpu | wc -l`
CPU=1

echo "$dtim" >> $LOGNAM
while [ $CPU -le $CPU_NO ] ;do
cat /proc/stat | awk 'NR ==  '$CPU' { print " ",$0 >>  "'$LOGNAM'" } '
CPU=$[CPU+1]
done
sleep 1


 # If the date has changed stop the process
  CURDAT=`date +"%Y%m%d"`
  if [ $DAT != $CURDAT ]
  then
    exit
  fi

sh /home/sys_scripts/cpu_core_stats.sh

2 REPLIES 2
Boerbokrib
Advisor

Re: Multiple Core Monitoring script

Ok got it working.

 

now is there a way to do the cpu calculations within the script?

 

#!/bin/bash
# script to capture the core statistics of the cpu's
#Wayne McN 18/10/2011

DAT=`date +"%Y%m%d"`
HOSTNAM=`hostname -s`
LOGDIR=/home/sys_logs
LOGNAM=$LOGDIR/${HOSTNAM}_cpu_core.$DAT
#dtim=`date +"%T"`

while true ; do

dtim=`date +"%T"`
CPU_NO=`cat /proc/stat | grep cpu | wc -l`
CPU=1

echo "$dtim" >> $LOGNAM
while [ $CPU -le $CPU_NO ] ;do
cat /proc/stat | awk 'NR ==  '$CPU' { print " ",$0 >>  "'$LOGNAM'" } '
CPU=$[CPU+1]
done
sleep 1


 # If the date has changed stop the process
  CURDAT=`date +"%Y%m%d"`
  if [ $DAT != $CURDAT ]
  then
    exit
  fi

done

Dennis Handly
Acclaimed Contributor

Re: Multiple Core Monitoring script

>now is there a way to do the CPU calculations within the script?

 

What type of calculations?

(Note it would be very helpful if you indented the bodies of your two while loops so the control flow becomes more obvious.)