Labels

Monday, December 3, 2012

Commands for System Statistics (UNIX)

Regular Resource Monitoring UNIX Commands:

1. iostat
2. free
3. mpstat
4. sar
4. ps -aux
5. ps -eo pcpu,pid,user,args | sort -r -k1 | less
6. ps -eo pid,pcpu,comm
7.ps -eo pid,pcpu,user,cmd | awk '{if ($3 == "h06adm") print }'
8. fdisk -l | grep Disk  - Display total hard disk size
9. df -h - Display disk free in Human understandable format (In GB)
10. cat /proc/cpuinfo  ( To check the CPU Core)
11. lscpu (to check the cpu)
12. /hwinfo  - To get hardware details
13. /usr/sbin/dmidecode - To get the internals of hardware
14. cat /proc/meminfo   or   free -g   (To check Ram)
15. Sed (2/String1/String2) - String editor to replae
16. mpstat -p All  - To check each core of cpu


Example shell Program:

#!/bin/sh
ps -eo pid,pcpu,comm | awk '{if ($2 > 4) print }' >> ~/ps_eo_test.txt





#!/bin/bash
# by Paul Colby (http://colby.id.au), no rights reserved ;)

PREV_TOTAL=0
PREV_IDLE=0

while true; do
  CPU=(`cat /proc/stat | grep '^cpu '`) # Get the total CPU statistics.
  unset CPU[0]                          # Discard the "cpu" prefix.
  IDLE=${CPU[4]}                        # Get the idle CPU time.

  # Calculate the total CPU time.
  TOTAL=0
  for VALUE in "${c...@]}"; do
    let "TOTAL=$TOTAL+$VALUE"
  done

  # Calculate the CPU usage since we last checked.
  let "DIFF_IDLE=$IDLE-$PREV_IDLE"
  let "DIFF_TOTAL=$TOTAL-$PREV_TOTAL"
  let "DIFF_USAGE=(1000*($DIFF_TOTAL-$DIFF_IDLE)/$DIFF_TOTAL+5)/10"
  echo -en "\rCPU: $DIFF_USAGE%  \b\b"

  # Remember the total and idle CPU times for the next check.
  PREV_TOTAL="$TOTAL"
  PREV_IDLE="$IDLE"

  # Wait before checking again.
  sleep 1
done

No comments:

Learn German - Quick Reference