New FAMILUG

The PyMiers

Monday 2 December 2013

[Monitoring] iostat - hiển thị các thông tin thống kê về CPU và I/O

Bài này hướng đến một cuộc thảo luận hơn là một bài tut.
TODO: bài về mount, fstab (mặc dù những thứ này không thú vị cho lắm nhưng đã dùng Linux là phải biết, đặc biệt là đối với các sysadmin)

NOTE một lần nữa, nội dung bài này không thú vị, nhưng là cần thiết với các sysadmin

Bài viết thực hiện trên:
 $ uname -a
Linux archhvn 3.10.9-1-ARCH #1 SMP PREEMPT Wed Aug 21 13:49:35 CEST 2013 x86_64 GNU/Linux #đã lâu rồi không upgrade :D

nội dung có thể áp dụng tương tự cho các Linux based distro khác như Ubuntu ...

Vài thuật ngữ
IO: input/output (for devices and partitions)

report: mỗi output của iostat gọi là một report

iostat là một chương trình nằm trong package sysstat
 $ pacman -Qs iostat
local/sysstat 10.2.0-1
    a collection of performance monitoring tools (iostat,isag,mpstat,pidstat,sadf,sar)

Để cài đặt package này, dùng câu lệnh để cài tương ứng trên OS của bạn. Trên Ubuntu có thể là:
sudo apt-get install -y sysstat

Format câu lệnh iostat:
iostat  [-options ] [ interval [ count ] ]

Vài ví dụ

iostat # hiển thị report từ lúc boot
iostat 2 # hiển thị liên tục report mỗi 2 giây
iostat 2 5 # hiển thị 5 lần report mỗi lần cách nhau 2 giây.

Output của iostat gồm 2 loại report:
  1. the CPU Utilization report  (hiển thị giá trung bình nếu có nhiều CPU)
  2. the Device Utilization report.
$ iostat -y 2 1
Linux 3.10.9-1-ARCH (archhvn)     12/02/2013     _x86_64_    (4 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           2.53    0.00    0.38    4.29    0.00   92.80

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda               4.00         0.00        20.00          0         40

Option -y để bỏ qua report từ lúc boot.

Phần CPU Utilization report có 6 giá trị tính bằng đơn vị %.

3 giá trị về % CPU
  • %user: phần trăm CPU được sử dụng khi chạy các ứng dụng ở user level (tất cả những gì không thuộc về kernel)
  • %system: phần trăm CPU được sử dụng khi chạy ở system level (kernel)
  • %nice: tương tự %user nhưng với nice priority.
# Nice priority là gì? `man 2 nice` `man 1 nice`
nice numbers are used to compute the priorities but are not the priorities themselves
http://en.wikipedia.org/wiki/Nice_%28Unix%29
 3 giá trị về % thời gian 
  • %iowait: phần trăm thời gian mà CPU(s) rảnh  khi hệ thống thực hiện disk I/O request.
  • %idle: phần trăm thời gian mà CPU(s) rảnh và hệ thống không thực hiện disk I/O request.
  • %steal: xem thêm ở man 1 iostat.

phần the Device Utilization report cũng gồm 7 giá trị (tên cột / số cột hay đơn vị có thể khác nếu sử dụng các option của iostat, ở đây chỉ viết về ví dụ nói trên)
  • Device: tên device, ở đây là "sda". Một device có 1 hay nhiều partition. (dùng iostat -pd sda để hiển thị thông số cho từng partition trong sda)
  • tps: transfer per second. Mỗi  transfer là một I/O request đến device. Nhiều logical request có thể được hợp lại thành 1 I/O request đến device =>  một transfer không có kích thước cố định.
  • kB_read/s: số kilobytes đọc từ device
  • kB_read: tổng số kilobytes đọc từ device  = kB_read/s * interval (s)
  • kB_wrtn/s: số kilobytes ghi vào device
  • kB_wrtn: tổng số kilobytes ghi  từ device  = kB_read/s * interval (s)

Đến đây coi như đủ, bạn đã có thể đọc được các report của iostat.
Nhiều option khác không liệt kê ở đây, ngoài 1 vài option phổ biến sau:
  • -c: chỉ hiện CPU report
  • -d: chỉ hiện device report

Bonus: từ kernel 2.4 trở lên, 1 block tương đưong với 1 sector = 512 bytes.


Further reading:
man 1 iostat
https://www.kernel.org/doc/Documentation/iostats.txt

Các câu hỏi thảo luận:
Với lần lượt từng giá trị trong 6 giá trị của CPU, khi nó lên cao có nghĩa là gì, có vấn đề gì ?
Ví dụ: %nice tăng cao, chuyên gì đang xảy ra?

9 comments:

  1. http://serverfault.com/a/116954/129339

    On a CPU utilization graph or report, the "nice" CPU percentage is the % of CPU time occupied by processes with a positive nice value (lower scheduling priority -- see man nice for details).

    Basically it's CPU time that's currently "in use", but if a normal (nice value 0) or high-priority (negative nice value) process comes along those programs will be kicked off the CPU.

    ReplyDelete
  2. Trả lời câu hỏi thảo luận:
    - nice:
    Dùng lệnh sau để lấy ra các process có nice > 0 (nghĩa là priority thấp nhất). Tức những process này sẽ có mức độ ưu tiên dùng CPU ít hơn so với các process có nice <= 0:
    $ ps -eo nice,cmd --sort nice | egrep '^ +[1-9].+'
    5 [ksmd]
    19 [khugepaged]

    Kernel Samepage Merging
    https://www.kernel.org/doc/Documentation/vm/ksm.txt
    The KSM daemon ksmd periodically scans those areas of user memory which
    have been registered with it, looking for pages of identical content which
    can be replaced by a single write-protected page (which is automatically
    copied if a process later wants to update its content).

    KSM was originally developed for use with KVM (where it was known as
    Kernel Shared Memory), to fit more virtual machines into physical memory,
    by sharing the data common between them. But it can be useful to any
    application which generates many instances of the same data.

    kHugepages thì không thấy kết quả chính thức nào.
    2 process trên đều từng rất phổ biến trên mạng vì ngốn nhiều CPU (do bugs).

    Khi %nice cao, có nghĩa là 2 process nói trên hoặc các process được set nice cao đang chiếm nhiều CPU và rất có thể đó là do bug của 2 process nói trên.

    http://www.interphero.com/?p=219
    https://www.google.com.vn/search?q=khugepaged+linux&ie=utf-8&oe=utf-8&rls=org.mozilla:en-US:official&client=firefox-a&channel=fflb&gws_rd=cr&ei=ILucUvHFLszloASJw4KQBw

    ReplyDelete
    Replies
    1. Không thấy nói gì về Network Filesystem report. :v

      Delete
  3. So to put it in lemans terms, the faster the clock speed, the quicker the computer (not taking architecture into account, for all you techies out there).The differences between DDR3 and DDR4 RAM

    ReplyDelete
  4. On that website page, you'll see your description, why not read through this. HDPE blue drum scrap suppliers

    ReplyDelete
  5. Very interesting information, worth recommending. However, I recommend this: aktuality

    ReplyDelete
  6. Very interesting information, worth recommending. However, I recommend this: aktuality

    ReplyDelete
  7. Wonderful article. Fascinating to read. I love to read such an excellent article. Thanks! It has made my task more and extra easy. Keep rocking. mining

    ReplyDelete
  8. In the event that it does, you'll need to append the fan to the heatsink first prior to joining the heatsink to the CPU. CPS Test

    ReplyDelete