mkarthik415
asked on
CPU utilization command
what is the command to find average, minimum and maximum cpu utilization in percentages for linux servers.
sar -u will give you a history. the sysstat package needs to be installed. Most distros have it.
Hi,
If you might like to insall the package called systat and you can use these commands :
sar
mpstat
The usage is :
sar -u 5 10
will get statistics for 5 seconds and repeat 10 times.
mpstat 5 10
Will do this for 10 times with 5 seconds delay.
sar
Sample sar output is like this:
# sar
Linux 2.6.9-78.0.22.EL (host.domain.com.tr) 07/15/2009
12:00:01 AM CPU %user %nice %system %iowait %idle
12:10:01 AM all 2.74 0.00 0.52 0.36 96.38
12:20:01 AM all 0.99 0.00 0.32 0.06 98.62
12:30:01 AM all 2.37 0.00 0.50 0.28 96.84
12:40:01 AM all 1.03 0.00 0.33 0.08 98.56
12:50:01 AM all 1.05 0.00 0.37 0.06 98.51
01:00:01 AM all 1.23 0.00 0.37 0.12 98.27
01:10:01 AM all 0.70 0.00 0.31 0.05 98.94
01:20:01 AM all 0.78 0.00 0.29 0.13 98.80
01:30:01 AM all 2.58 0.00 0.35 0.20 96.87
01:40:01 AM all 0.65 0.00 0.24 0.03 99.08
01:50:01 AM all 1.41 0.00 0.35 0.13 98.10
02:00:01 AM all 0.95 0.00 0.29 0.12 98.63
02:10:01 AM all 0.57 0.00 0.20 0.03 99.20
02:20:01 AM all 1.13 0.00 0.33 0.06 98.47
02:30:01 AM all 1.60 0.00 0.31 0.13 97.96
02:40:01 AM all 1.11 0.00 0.33 0.14 98.42
02:50:01 AM all 1.02 0.00 0.33 0.07 98.58
03:00:01 AM all 1.95 0.00 1.13 2.16 94.75
03:10:01 AM all 2.11 0.00 0.95 5.32 91.62
Average: all 1.37 0.00 0.41 0.50 97.72
and
mpstat
Sample mpstat output is:
# mpstat
Linux 2.6.9-78.0.22.EL (host.domain.com.tr) 07/15/2009
03:23:38 AM CPU %user %nice %system %iowait %irq %soft %idle intr/s
03:23:38 AM all 1.64 0.00 0.32 0.17 0.00 0.00 97.86 1018.63
Will collect information and when executed in their own they will display the historic data of CPU utilization. You might as well use top if you want interactive display.
the command
w
will display you momentarily CPU usage like this:
# w
03:21:56 up 12 days, 11:58, 4 users, load average: 0.02, 0.02, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root :0 - 02Jul09 ?xdm? 1:55m 1.66s /usr/bin/gnome-session
root pts/1 :0.0 02Jul09 12days 0.07s 0.07s bash
root pts/2 host.dom.com 23:35 0.00s 0.28s 0.00s w
root pts/3 host.dom.com 03:01 18:21 0.04s 0.04s -bash
Uptime is smilar and itwill only show the first line of what w displays.
Cheers,
K.
If you might like to insall the package called systat and you can use these commands :
sar
mpstat
The usage is :
sar -u 5 10
will get statistics for 5 seconds and repeat 10 times.
mpstat 5 10
Will do this for 10 times with 5 seconds delay.
sar
Sample sar output is like this:
# sar
Linux 2.6.9-78.0.22.EL (host.domain.com.tr) 07/15/2009
12:00:01 AM CPU %user %nice %system %iowait %idle
12:10:01 AM all 2.74 0.00 0.52 0.36 96.38
12:20:01 AM all 0.99 0.00 0.32 0.06 98.62
12:30:01 AM all 2.37 0.00 0.50 0.28 96.84
12:40:01 AM all 1.03 0.00 0.33 0.08 98.56
12:50:01 AM all 1.05 0.00 0.37 0.06 98.51
01:00:01 AM all 1.23 0.00 0.37 0.12 98.27
01:10:01 AM all 0.70 0.00 0.31 0.05 98.94
01:20:01 AM all 0.78 0.00 0.29 0.13 98.80
01:30:01 AM all 2.58 0.00 0.35 0.20 96.87
01:40:01 AM all 0.65 0.00 0.24 0.03 99.08
01:50:01 AM all 1.41 0.00 0.35 0.13 98.10
02:00:01 AM all 0.95 0.00 0.29 0.12 98.63
02:10:01 AM all 0.57 0.00 0.20 0.03 99.20
02:20:01 AM all 1.13 0.00 0.33 0.06 98.47
02:30:01 AM all 1.60 0.00 0.31 0.13 97.96
02:40:01 AM all 1.11 0.00 0.33 0.14 98.42
02:50:01 AM all 1.02 0.00 0.33 0.07 98.58
03:00:01 AM all 1.95 0.00 1.13 2.16 94.75
03:10:01 AM all 2.11 0.00 0.95 5.32 91.62
Average: all 1.37 0.00 0.41 0.50 97.72
and
mpstat
Sample mpstat output is:
# mpstat
Linux 2.6.9-78.0.22.EL (host.domain.com.tr) 07/15/2009
03:23:38 AM CPU %user %nice %system %iowait %irq %soft %idle intr/s
03:23:38 AM all 1.64 0.00 0.32 0.17 0.00 0.00 97.86 1018.63
Will collect information and when executed in their own they will display the historic data of CPU utilization. You might as well use top if you want interactive display.
the command
w
will display you momentarily CPU usage like this:
# w
03:21:56 up 12 days, 11:58, 4 users, load average: 0.02, 0.02, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root :0 - 02Jul09 ?xdm? 1:55m 1.66s /usr/bin/gnome-session
root pts/1 :0.0 02Jul09 12days 0.07s 0.07s bash
root pts/2 host.dom.com 23:35 0.00s 0.28s 0.00s w
root pts/3 host.dom.com 03:01 18:21 0.04s 0.04s -bash
Uptime is smilar and itwill only show the first line of what w displays.
Cheers,
K.
With UNIX systems you mainly use :
sat, mpstat, top and uptime
commands to get an information about CPU usage.
sat, mpstat, top and uptime
commands to get an information about CPU usage.
ASKER
I want only average, minimum and maximum cpu utilization. I think we would require a script to get this.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
then you'll need sar. since it keeps statistics in 10 minutes periods. This command below will show it. You'll need to install the package called sysstat first. On my system the sample output is :
Highest= 3.62
Lowest=1.38
Average=2.39
Highest= 3.62
Lowest=1.38
Average=2.39
# sar | grep "^[0-9]" | grep -v CPU | awk 'NR==1 {print "Highest= " 100 -$8} END {print "Lowest=" 100 - $8}' ; sar | tail -1 | awk '{print "Average=" 100 - $7}'
you may use top in batch mode
top -b -d1 | grep stat
top -b -d1 | grep stat
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can use vmstat to log historical.
vmstat 5
Will print a line every 5 seconds with CPU and other stats.
The uptime command will show load avg for last 1, 5 and 15 minutes, but does not show CPU %