Resource management - GradedJestRisk/linux-training GitHub Wiki

Resource management

processes

List processes running in background :jobs

View process tree of a user

pstree -u <USER>
(..)
init─┬─atd
     ├─console-kit-dae───63*[{console-kit-da}]
     ├─crond
(..)

load average

Show load average for 1, 5, 15 minutes.

uptime
11:00:02 up 104 days, 23:08,  7 users,  load average: 1.01, 1.05, 0.66

Get load average each minute: while sleep 60; do uptime; done;

IO

IO wait : time spent by CPU waiting for IO

Handful:

  • get iowait: vmstat, column
  • get all processes waiting for IO : watch -n 1 "(ps aux | awk '\$8 ~ /D/ { print \$0 }')"
  • get IO wait for last 5 secondes : sar 5 | awk '/all|iowait/{print $7}'

vmstat (I/O used - blocks read and write)

It displays the header, then output each 2 seconds

vmstat --one-header 2

You get

procs -----------memory---------- ---swap-- -----io---- -system-- -------cpu-------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st gu
 0  0   1024 19533884 235128 7451124    0    0     0   162 12113 6263  0  0 99  0  0  0
 1  0   1024 19498524 235156 7447020    0    0    14   350 12690 8005  1  0 99  0  0  0

On line 2:

  • 14 blocks were read (bi)
  • 350 blocks were written (bo)

We are interested in bi, bo, which 9 and 10th column

# doesn't work, don't know why
vmstat --one-header 2 | awk 'BEGIN {print "bi -bo"} {print $9  " - " $10}'
# even  this one doesn't work
vmstat --one-header 2 | awk '{print $1}'

Reference

iostat (I/O speed, I/O used)

Install

apt install sysstat

Output each 2 secondes

iostat --human 2

It displays some average, then for each device the stat

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           4,0%    0,0%    1,9%    0,1%    0,0%   94,0%

Device             tps    kB_read/s    kB_wrtn/s    kB_dscd/s    kB_read    kB_wrtn    kB_dscd
dm-0             70,00         0,0k       320,0k         0,0k       0,0k     640,0k       0,0k
dm-2              0,00         0,0k         0,0k         0,0k       0,0k       0,0k       0,0k

We are interested in a specific device

iostat --human 2 | grep "nvme0n1" --line-buffered

We are interested in kB_read/s, kB_wrtn/s, which 3 and 4th column, for a specific device.

iostat --human 2 | awk 'BEGIN {print "Speed (R - W)"} /nvme0n1/  {print $3  " - " $4}'

We are interested in kB_read, kB_wrtn, which 6 and 7th column, for a specific device.

iostat --human 2 | awk 'BEGIN {print "Size(R - W)"} /nvme0n1/  {print $6  " - " $7}'

Reference

⚠️ **GitHub.com Fallback** ⚠️