勉強日記

チラ裏

LPIC level2 v4.5 あずき本 1.2.1 総合的なリソース使用率の測定

www.shoeisha.co.jp


リソース使用率の測定とトラブルシューティング

  • 現時点における各種リソースの利用状況を計測する
  • キャパシティプランニングやパフォーマンスチューニングに必要

総合的なリソース使用率

  • CPU使用率、メモリの状況等

topコマンド

top
top - 19:53:01 up 16 days,  2:59,  1 user,  load average: 0.28, 0.30, 0.18
Tasks: 267 total,   1 running, 215 sleeping,   0 stopped,   0 zombie
%Cpu(s): 17.5 us,  4.5 sy,  0.1 ni, 77.8 id,  0.1 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  8061232 total,  1079416 free,  1943324 used,  5038492 buff/cache
KiB Swap:  2097148 total,  1631920 free,   465228 used.  5569948 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                      
 1975 wand      20   0  534744  35032  18616 S   5.9  0.4 133:25.65 Xorg                         
 2139 wand      20   0 3696252 191388  57372 S   5.9  2.4 246:07.31 gnome-shell                  
 2165 wand      20   0  356644   6852   3864 S   5.9  0.1  22:07.37 ibus-daemon                  
 9974 wand      20   0  804800  40840  30612 S   5.9  0.5   0:00.78 gnome-terminal-              
 9996 wand      20   0   42932   4004   3272 R   5.9  0.0   0:00.02 top                          
20656 wand      20   0  487756 113936  51032 S   5.9  1.4   0:58.96 emacs25                      
    1 root      20   0  226000   7032   4504 S   0.0  0.1   4:22.03 systemd                      
    2 root      20   0       0      0      0 S   0.0  0.0   0:00.26 kthreadd                     
    4 root       0 -20       0      0      0 I   0.0  0.0   0:00.00 kworker/0:0H                 
    6 root       0 -20       0      0      0 I   0.0  0.0   0:00.00 mm_percpu_wq                 
    7 root      20   0       0      0      0 S   0.0  0.0   0:06.54 ksoftirqd/0                  
    8 root      20   0       0      0      0 I   0.0  0.0   5:09.67 rcu_sched                    
    9 root      20   0       0      0      0 I   0.0  0.0   0:00.00 rcu_bh                       
   10 root      rt   0       0      0      0 S   0.0  0.0   0:00.44 migration/0                  
   11 root      rt   0       0      0      0 S   0.0  0.0   0:01.35 watchdog/0                   
   12 root      20   0       0      0      0 S   0.0  0.0   0:00.00 cpuhp/0                      
   13 root      20   0       0      0      0 S   0.0  0.0   0:00.01 cpuhp/1     

1行目

  • uptimeコマンドの表示内容と同じ
top - 19:53:01 up 16 days,  2:59,  1 user,  load average: 0.28, 0.30, 0.18
uptime
 19:54:11 up 16 days,  3:00,  1 user,  load average: 0.17, 0.26, 0.18
  • 現在日時
    • 19:54:11
  • 起動後の経過時間
    • up 16 days, 3:00
  • ログイン中のユーザ数
    • 1 user
  • ロードアベレージ
    • load average: 0.17, 0.26, 0.18
    • 直近の平均
      • 1分
      • 5分
      • 15分
    • CPU数*コア数を超えていると処理待が発生している可能性あり

2行目

Tasks: 267 total,   1 running, 215 sleeping,   0 stopped,   0 zombie
  • 総プロセス数
  • 実行状態
  • スリープ状態
  • 停止状態
  • ゾンビ状態
    • 処理は終了したもののプロセステーブルから情報が削除されていない

3行目

%Cpu(s): 17.5 us,  4.5 sy,  0.1 ni, 77.8 id,  0.1 wa,  0.0 hi,  0.0 si,  0.0 st
  • us: user
    • ユーザープロセスがCPUを使用している時間の割合
  • sy: system
  • ni: nice
    • 優先度が変更されたプロセスがCPUを使用している時間の割合
  • id: idle
    • CPUがアイドル状態の時間の割合
    • ディスクI/O待ちを除く
      • それはwa
  • wa: io wait
    • ディスクI/O待ちの時間の割合
  • hi: hardware irq
    • ハードウェア割り込み要求時間の割合
  • si: software irq
    • ソフトウェア割り込み要求時間の割合
  • st: steal
    • ゲストOSがCPUを割り当てられなかった時間の割合
    • 仮想環境において、ゲストOSが要求したにもかかわらずCPUリソースを割り当ててもらえず待機させられた
    • 0%: 要求どおりにCPUを割り当てられている
    • 0%より高い: ホストOSや他のゲストOSとCPUを奪い(steal)合っている

4-5行目

KiB Mem :  8061232 total,  1079416 free,  1943324 used,  5038492 buff/cache
KiB Swap:  2097148 total,  1631920 free,   465228 used.  5569948 avail Mem 
  • 【補】freeコマンドと似たような内容
free
              total        used        free      shared  buff/cache   available
Mem:        8061232     1940416     1080252      231336     5040564     5571808
Swap:       2097148      465228     1631920
  • 4行目
    • 全物理メモリ量
    • 空きメモリ量
    • 使用中のメモリ量
    • バッファおよびキャッシュサイズ
  • 5行目
man top
       The avail number on line 2 is an  estimation  of  physical  memory
       available for starting new applications, without swapping.  Unlike
       the free field, it attempts to  account  for  readily  reclaimable
       page  cache  and  memory  slabs.  It is available on kernels 3.14,
       emulated on kernels 2.6.27+, otherwise the same as free.

のこり

  • タスクエリア
    • プロセスごとの情報
  • デフォルトCPU時間降順
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                      
 1975 wand      20   0  534744  35032  18616 S   5.9  0.4 133:25.65 Xorg                         
 2139 wand      20   0 3696252 191388  57372 S   5.9  2.4 246:07.31 gnome-shell                  
 2165 wand      20   0  356644   6852   3864 S   5.9  0.1  22:07.37 ibus-daemon                  
 9974 wand      20   0  804800  40840  30612 S   5.9  0.5   0:00.78 gnome-terminal-              
  • 【補】PID昇順にしてみる
top -o PID
(R押下: Reverse)
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                      
    1 root      20   0  226000   7032   4504 S   0.0  0.1   4:22.50 systemd                      
    2 root      20   0       0      0      0 S   0.0  0.0   0:00.26 kthreadd                     
    4 root       0 -20       0      0      0 I   0.0  0.0   0:00.00 kworker/0:0H                 
    6 root       0 -20       0      0      0 I   0.0  0.0   0:00.00 mm_percpu_wq                 
    7 root      20   0       0      0      0 S   0.0  0.0   0:06.55 ksoftirqd/0                  
    8 root      20   0       0      0      0 I   0.3  0.0   5:10.51 rcu_sched                    
...
  • topコマンドの表示項目(タスクエリア)
    • 【補】fまたはFを入力すると対話的に表示/非表示切り替えできる
項目 説明
PID プロセスID
PPID 親プロセスID
USER ユーザ名
RUSER 実ユーザ名
UID UID
GROUP グループ名
PR 実行優先度
NI nice値
VIRT 使用中の仮想メモリ(KB)
RES 使用中の実メモリ(KB)
SHR 共有メモリサイズ(KB)
S プロセスの状態
TTY 制御端末名
%CPU CPUの使用率(%)
%MEM 物理メモリの使用率(%)
TIME+ プロセスが開始してから使用したCPU時間の総計
COMMAND 実行コマンド
  • 対話操作が死ぬほどいっぱいある
       Listed below is a brief index of commands within categories.  Some
       commands  appear  more  than  once  --  their meaning or scope may
       vary depending on the context in which they are issued.

         4a. Global-Commands
               <Ent/Sp> ?, =, 0,
               A, B, d, E, e, g, h, H, I, k, q, r, s, W, X, Y, Z
         4b. Summary-Area-Commands
               C, l, t, m, 1, 2, 3
         4c. Task-Area-Commands
               Appearance:  b, J, j, x, y, z
               Content:     c, f, F, o, O, S, u, U, V
               Size:        #, i, n
               Sorting:     <, >, f, F, R
         4d. Color-Mapping
               <Ret>, a, B, b, H, M, q, S, T, w, z, 0 - 7
         5b. Commands-for-Windows
               -, _, =, +, A, a, g, G, w
         5c. Scrolling-a-Window
               C, Up, Dn, Left, Right, PgUp, PgDn, Home, End
         5d. Searching-in-a-Window
               L, &
  • ソート順変える
  • 表示項目変える
  • killする
    1. PID指定
    2. SIG指定

vmstatコマンド

vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0 465228 733500 1232248 3398104    1    4    21    83   36   18 17  4 78  0  0
  • 1秒間隔で3回表示
vmstat 1 3
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0 465228 728212 1232296 3396372    1    4    21    83   36   18 17  4 78  0  0
 0  0 465228 726972 1232304 3396696    0    0     0    76  443  799  5  1 94  0  0
 1  0 465228 727476 1232304 3396360    0    0     0     0  237  858  1  0 99  0  0
VMSTAT(8)                    System Administration                   VMSTAT(8)

NAME
       vmstat - Report virtual memory statistics

SYNOPSIS
       vmstat [options] [delay [count]]

...

OPTIONS
       delay  The delay between updates in seconds.  If no delay is specified,
              only one report is printed with the average values since boot.

       count  Number  of updates.  In absence of count, when delay is defined,
              default is infinite.
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0 465228 733500 1232248 3398104    1    4    21    83   36   18 17  4 78  0  0
  • みかた
FIELD DESCRIPTION FOR VM MODE
   Procs
       r: The number of runnable processes (running or waiting for run time).
       b: The number of processes in uninterruptible sleep.

   Memory
       swpd: the amount of virtual memory used.
       free: the amount of idle memory.
       buff: the amount of memory used as buffers.
       cache: the amount of memory used as cache.
       inact: the amount of inactive memory.  (-a option)
       active: the amount of active memory.  (-a option)

   Swap
       si: Amount of memory swapped in from disk (/s).
       so: Amount of memory swapped to disk (/s).

   IO
       bi: Blocks received from a block device (blocks/s).
       bo: Blocks sent to a block device (blocks/s).

   System
       in: The number of interrupts per second, including the clock.
       cs: The number of context switches per second.

   CPU
       These are percentages of total CPU time.
       us: Time spent running non-kernel code.  (user time, including nice time)
       sy: Time spent running kernel code.  (system time)
       id: Time spent idle.  Prior to Linux 2.5.41, this includes IO-wait time.
       wa: Time spent waiting for IO.  Prior to Linux 2.5.41, included in idle.
       st: Time stolen from a virtual machine.  Prior to Linux 2.6.11, unknown.
  • コンテキストスイッチ
    • 複数のプロセスで1つのCPUを共有するための技術
    • 状態の保存・復元
  • 活用例
    • swpdが高く、freeやbuff/cacheが低く、si/soが高い => メモリ不足を疑う
    • b列の値が0より高い => I/O待ちなどで割り込み不可になっているプロセスがある。0が望ましい

iostatコマンド

  • ディスクI/O等の調査
iostat
Linux 4.15.0-47-generic (wand-ThinkPad-X240s)    2019年04月28日   _x86_64_    (4 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
          17.13    0.07    4.46    0.09    0.00   78.26

Device             tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
loop0             0.00         0.00         0.00        220          0
loop1             0.00         0.00         0.00       2258          0
loop2             0.00         0.00         0.00        264          0
...
  • CPU使用率のみ
iostat -c
Linux 4.15.0-47-generic (wand-ThinkPad-X240s)    2019年04月28日   _x86_64_    (4 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
          17.13    0.07    4.46    0.09    0.00   78.26
  • 時刻添える
iostat -c -t
Linux 4.15.0-47-generic (wand-ThinkPad-X240s)    2019年04月28日   _x86_64_    (4 CPU)

2019年04月28日 21時15分05秒
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
          17.13    0.07    4.46    0.09    0.00   78.26
  • ディスクI/Oのみ
iostat -d
Linux 4.15.0-47-generic (wand-ThinkPad-X240s)    2019年04月28日   _x86_64_    (4 CPU)

Device             tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
loop0             0.00         0.00         0.00        220          0
loop1             0.00         0.00         0.00       2258          0
loop2             0.00         0.00         0.00        264          0
loop3             0.00         0.00         0.00       2316          0
...
  • MB単位
iostat -d -m
Linux 4.15.0-47-generic (wand-ThinkPad-X240s)    2019年04月28日   _x86_64_    (4 CPU)

Device             tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn
loop0             0.00         0.00         0.00          0          0
loop1             0.00         0.00         0.00          2          0
loop2             0.00         0.00         0.00          0          0
loop3             0.00         0.00         0.00          2          0
...
  • デフォルトKB単位(-k)だった
  • 教科書的にはデフォルトはブロック単位??
  • 表示間隔(interval)・回数(count)指定可能
    • 省略すると1回のみ
    • 回数のみ省略するとinfinite
IOSTAT(1)                  Linux User's Manual                  IOSTAT(1)

NAME
       iostat  -  Report  Central  Processing  Unit  (CPU) statistics and
       input/output statistics for devices and partitions.

SYNOPSIS
       iostat [ -c ] [ -d ] [ -h ] [ -k | -m ] [ -N ] [ -s ] [ -t ] [  -V
       ] [ -x ] [ -y ] [ -z ] [ -j { ID | LABEL | PATH | UUID | ... } ] [
       -o JSON ] [ [ -H ] -g group_name ] [  --human  ]  [  -p  [  device
       [,...] | ALL ] ] [ device [...] | ALL ] [ interval [ count ] ]

iotopコマンド

IOTOP(8)                 System Manager's Manual                 IOTOP(8)

NAME
       iotop - simple top-like I/O monitor
  • I/O情報をtopコマンドのように表示
sudo iotop
Total DISK READ :       0.00 B/s | Total DISK WRITE :       0.00 B/s
Actual DISK READ:       0.00 B/s | Actual DISK WRITE:       0.00 B/s
  TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN     IO>    COMMAND                                              
    1 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % init splash
    2 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kthreadd]
    4 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kworker/0:0H]
    6 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [mm_percpu_wq]
    7 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [ksoftirqd/0]
    8 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcu_sched]
    9 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcu_bh]
   10 rt/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [migration/0]
   11 rt/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [watchdog/0]
   12 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [cpuhp/0]
   13 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [cpuhp/1]
   14 rt/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [watchdog/1]
   15 rt/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [migration/1]
   16 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [ksoftirqd/1]
   18 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kworker/1:0H]
   19 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [cpuhp/2]
...
  • root権限必要
  • 手元のUbuntuには入ってなかった
sudo apt install -y iotop

sarコマンド

SAR(1)                     Linux User's Manual                     SAR(1)

NAME
       sar - Collect, report, or save system activity information.
  • 非常に多機能
  • さまざまなシステム統計情報のレポートを得る
sar
/var/log/sysstat/sa28 を開けません: そのようなファイルやディレクトリはありません
データ収集が有効になっているかを確認してください
  • sysstatサービスが有効になっていること
systemctl is-active sysstat
active
  • sadcによるログが/var/log/sa/ディレクトリ以下のsaXXファイルに格納されることになっている
  • 【補】手元のUbuntuでは/var/log/sysstat/ディレクトリ以下みたい
  • sa2828は、今日が4月28日だから(四葉ちゃんの日!)
    • ので、一ヶ月たつと古いログが上書きされる
  • 有効化
  #
  # Default settings for /etc/init.d/sysstat, /etc/cron.d/sysstat
  # and /etc/cron.daily/sysstat files
  #
   
  # Should sadc collect system activity informations? Valid values
  # are "true" and "false". Please do not put other values, they
  # will be overwritten by debconf!
- ENABLED="false"
+ ENABLED="true"
  • 設定更新
sudo systemctl restart sysstat
systemctl is-active sysstat
active
  • ログアウトしたらつかえるようになった
sar
Linux 4.15.0-47-generic (wand-ThinkPad-X240s)    2019年04月28日   _x86_64_    (4 CPU)

21:36:01     LINUX RESTART  (4 CPU)

21:53:15     LINUX RESTART  (4 CPU)

21時55分01秒     CPU     %user     %nice   %system   %iowait    %steal     %idle
22時05分01秒     all      5.78      0.00      1.09      0.06      0.00     93.07
平均値:      all      5.78      0.00      1.09      0.06      0.00     93.07
  • cronの設定
  • /etc/cron.d/sysstat
# The first element of the path is a directory where the debian-sa1
# script is located
PATH=/usr/lib/sysstat:/usr/sbin:/usr/sbin:/usr/bin:/sbin:/bin

# Activity reports every 10 minutes everyday
5-55/10 * * * * root command -v debian-sa1 > /dev/null && debian-sa1 1 1

# Additional run at 23:59 to rotate the statistics file
59 23 * * * root command -v debian-sa1 > /dev/null && debian-sa1 60 2
  • -bオプションの表示項目
    • ディスクの入出力と転送レート情報を表示
Linux 4.15.0-47-generic (wand-ThinkPad-X240s)    2019年04月28日   _x86_64_    (4 CPU)

21:36:01     LINUX RESTART  (4 CPU)

21:53:15     LINUX RESTART  (4 CPU)

21時55分01秒       tps      rtps      wtps   bread/s   bwrtn/s
22時05分01秒     13.12      8.17      4.95    670.00    441.76
平均値:      13.12      8.17      4.95    670.00    441.76
項目 説明
tps I/O転送リクエスト数/秒
rtps read
wtps write
bread/s ディスク読み込みブロック数/秒
bwrtn/s ディスク書き込みブロック数/秒
  • -n DEVオプションの表示項目
    • ネットワーク関連の情報を表示する
Linux 4.15.0-47-generic (wand-ThinkPad-X240s)    2019年04月28日   _x86_64_    (4 CPU)

21:36:01     LINUX RESTART  (4 CPU)

21:53:15     LINUX RESTART  (4 CPU)

21時55分01秒     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s   %ifutil
22時05分01秒 br-6d041025d893      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
22時05分01秒        lo      1.43      1.43      0.15      0.15      0.00      0.00      0.00      0.00
22時05分01秒 br-d85b89bb30a7      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
22時05分01秒 br-44d1bd312b90      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
22時05分01秒 br-994051d4ecb5      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
22時05分01秒 br-864d5373b5ba      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
22時05分01秒   docker0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
22時05分01秒    wlp3s0     16.19     11.28      9.41      2.12      0.00      0.00      0.00      0.00
22時05分01秒   enp0s25      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
平均値:  br-6d041025d893      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
平均値:         lo      1.43      1.43      0.15      0.15      0.00      0.00      0.00      0.00
平均値:  br-d85b89bb30a7      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
平均値:  br-44d1bd312b90      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
平均値:  br-994051d4ecb5      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
平均値:  br-864d5373b5ba      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
平均値:    docker0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
平均値:     wlp3s0     16.19     11.28      9.41      2.12      0.00      0.00      0.00      0.00
平均値:    enp0s25      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
項目 説明
IFACE ネットワークインターフェース名
rxpck/s 受信パケット/秒
txpck/s 送信パケット/秒
rxkB/s 受信キロバイト数/秒
txkB/s 送信キロバイト数/秒
rxcmp/s 圧縮パケットの受信バイト数/秒
txcmp/s 圧縮パケットの送信バイト数/秒
rmcst/s マルチキャストパケットの受信パケット数/秒
  • 略語の意味
    • t: transmitting
    • r: received
  • -n EDEVオプションの表示項目
    • ネットワーク関連のエラー情報を表示する
Linux 4.15.0-47-generic (wand-ThinkPad-X240s)    2019年04月28日   _x86_64_    (4 CPU)

21:36:01     LINUX RESTART  (4 CPU)

21:53:15     LINUX RESTART  (4 CPU)

21時55分01秒     IFACE   rxerr/s   txerr/s    coll/s  rxdrop/s  txdrop/s  txcarr/s  rxfram/s  rxfifo/s  txfifo/s
22時05分01秒 br-6d041025d893      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
22時05分01秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
22時05分01秒 br-d85b89bb30a7      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
22時05分01秒 br-44d1bd312b90      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
22時05分01秒 br-994051d4ecb5      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
22時05分01秒 br-864d5373b5ba      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
22時05分01秒   docker0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
22時05分01秒    wlp3s0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
22時05分01秒   enp0s25      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
平均値:  br-6d041025d893      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
平均値:         lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
平均値:  br-d85b89bb30a7      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
平均値:  br-44d1bd312b90      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
平均値:  br-994051d4ecb5      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
平均値:  br-864d5373b5ba      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
平均値:    docker0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
平均値:     wlp3s0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
平均値:    enp0s25      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
項目 説明
IFACE ネットワークインターフェース名
rxerr/s 受信エラーパケット/秒
txerr/s 送信エラーパケット/秒
coll/s 衝突パケット数/秒
rxdrop/s バッファ不足による受信取りこぼしパケット数/秒
txdrop/s バッファ不足による送信取りこぼしパケット数/秒
txcarr/s 送信時のキャリアエラーパケット数/秒
rxfram/s 受信時のフレーム同期エラーパケット数/秒
rxfifo/s 受信時のFIFOオーバーランパケット数/秒
txfifo/s 送信時のFIFOオーバーランパケット数/秒
  • TCP/IP送受信バッファサイズ
  • -rの表示項目
    • メモリ関連情報
Linux 4.15.0-47-generic (wand-ThinkPad-X240s)    2019年04月28日   _x86_64_    (4 CPU)

21:36:01     LINUX RESTART  (4 CPU)

21:53:15     LINUX RESTART  (4 CPU)

21時55分01秒 kbmemfree   kbavail kbmemused  %memused kbbuffers  kbcached  kbcommit   %commit  kbactive   kbinact   kbdirty
22時05分01秒   5062880   6096580   2998360     37.19    157912   1272788   6218412     61.21   1721180    893096      8252
平均値:    5062880   6096580   2998360     37.19    157912   1272788   6218412     61.21   1721180    893096      8252
項目 説明
%memused メモリの使用率
kbbuffers バッファの使用量(KB)
kbcached キャッシュの使用量(KB)
kbcommit 現在必要とされているメモリ総量(KB)
%commit メモリ総量(RAM+スワップ)における必要メモリ量の割合(%)
kbactive activeなメモリ(KB)
kbinact inactiveなメモリ(KB)
kbdirty dirtyなメモリ(KB)
  • ページキャッシュの状態
    • active
      • 最近利用された頻度が高い
    • inactive
      • メモリが不足するとinactiveなページから解放されていく
    • dirty
      • ページがディスクに同期されていない(まだwrite-backされていない)
    • writeback
      • ディスクへの同期中

sadcコマンド

SADC(8)                    Linux User's Manual                    SADC(8)

NAME
       sadc - System activity data collector.
  • データ集める人

sadfコマンド

SADF(1)                    Linux User's Manual                    SADF(1)

NAME
       sadf - Display data collected by sar in multiple formats.

SYNOPSIS
       sadf  [  -C ] [ -c | -d | -g | -j | -p | -r | -x ] [ -H ] [ -h ] [
       -T | -t | -U ] [ -V ] [ -O opts [,...] ] [ -P { cpu_list | ALL } ]
       [  -s  [ hh:mm[:ss] ] ] [ -e [ hh:mm[:ss] ] ] [ -- sar_options ] [
       interval [ count ] ] [ datafile | -[0-9]+ ]
  • sadcにより収集されたログを整形
       -j     Print  the  contents  of  the data file in JSON (JavaScript
              Object Notation) format. Timestamps can  be  controlled  by
              options -T and -t.
...
       -x     Print  the  contents of the data file in XML format.  Time‐
              stamps can be controlled by options -T and -t.  The  corre‐
              sponding  DTD (Document Type Definition) and XML Schema are
              included in the  sysstat  source  package.  They  are  also
              available                  at                 http://pages‐
              perso-orange.fr/sebastien.godard/download.html
...
       -t     Display  timestamp  in  the original local time of the data
              file creator instead of UTC (Coordinated Universal Time).
  • --
    • 以降のオプションはsarに渡す
  • メモリ関連情報をXMLで出力する例
sadf -x -- -r
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sysstat PUBLIC "DTD v3.4 sysstat //EN"
"http://pagesperso-orange.fr/sebastien.godard/sysstat-3.4.dtd">
<sysstat
xmlns="http://pagesperso-orange.fr/sebastien.godard/sysstat"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pagesperso-orange.fr/sebastien.godard sysstat.xsd">
    <sysdata-version>3.4</sysdata-version>
    <host nodename="wand-ThinkPad-X240s">
        <sysname>Linux</sysname>
        <release>4.15.0-47-generic</release>
        <machine>x86_64</machine>
        <number-of-cpus>4</number-of-cpus>
        <file-date>2019-04-28</file-date>
        <file-utc-time>12:36:01</file-utc-time>
        <statistics>
            <timestamp date="2019-04-28" time="13:05:01" utc="1" interval="600">
                <memory per="second" unit="kB">
                    <memfree>5062880</memfree>
                    <avail>6096580</avail>
                    <memused>2998360</memused>
                    <memused-percent>37.19</memused-percent>
                    <buffers>157912</buffers>
                    <cached>1272788</cached>
                    <commit>6218412</commit>
                    <commit-percent>61.21</commit-percent>
                    <active>1721180</active>
                    <inactive>893096</inactive>
                    <dirty>8252</dirty>
                </memory>
            </timestamp>
            <timestamp date="2019-04-28" time="13:15:01" utc="1" interval="600">
                <memory per="second" unit="kB">
                    <memfree>4973356</memfree>
                    <avail>6050760</avail>
                    <memused>3087884</memused>
                    <memused-percent>38.31</memused-percent>
                    <buffers>166504</buffers>
                    <cached>1298276</cached>
                    <commit>6245564</commit>
                    <commit-percent>61.48</commit-percent>
                    <active>1846540</active>
                    <inactive>846316</inactive>
                    <dirty>92</dirty>
                </memory>
            </timestamp>
        </statistics>
        <restarts>
            <boot date="2019-04-28" time="12:36:01" utc="1" cpu_count="4"/>
            <boot date="2019-04-28" time="12:53:15" utc="1" cpu_count="4"/>
        </restarts>
    </host>
</sysstat>

uptimeコマンド

  • topコマンドの1行目とほぼ同じ
uptime
 21:37:43 up 16 days,  4:44,  1 user,  load average: 0.24, 0.33, 0.34

wコマンド

W(1)                          User Commands                          W(1)

NAME
       w - Show who is logged on and what they are doing.

SYNOPSIS
       w [options] user [...]
w
 21:38:46 up 16 days,  4:45,  1 user,  load average: 0.41, 0.37, 0.35
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
wand     :0       :0               12 4月19 ?xdm?   2:53m  0.01s /usr/lib/gdm3/gdm-x-session --run-script env GNOME_
  • 現在ログインしているユーザ
  • 各ユーザのプロセス情報
COMMAND-LINE OPTIONS
       -h, --no-header
              Don't print the header.
...
       -s, --short
              Use the short format.  Don't print the login time, JCPU  or
              PCPU times.
  • ログインヘッダ表示しない
w -h
wand     :0       :0               12 4月19 ?xdm?   2:54m  0.01s /usr/li
  • ログイン時刻、JCPU,PCPU表示しない
w -s
 21:41:56 up 16 days,  4:48,  1 user,  load average: 0.37, 0.38, 0.36
USER     TTY      FROM              IDLE WHAT
wand     :0       :0               ?xdm?  /usr/lib/gdm3/gdm-x-session
  • 表示項目
項目 説明
USER ユーザ名
TTY 端末名
FROM リモートホスト
LOGIN@ ログイン時刻
IDLE アイドル時間
JCPU 当該端末から実行されている全プロセスが消費したCPU時間
PCPU WHAT欄に表示されるカレントプロセスが消費したCPU時間
WHAT 実行されているコマンド
       The  JCPU  time  is the time used by all processes attached to the
       tty.  It does not include past background jobs, but  does  include
       currently running background jobs.

       The  PCPU  time  is the time used by the current process, named in
       the "what" field.