LoginSignup
2
5

More than 3 years have passed since last update.

Linuxリソース管理コマンドまとめ

Posted at

総合的なリソース管理

top

  • システム全体のCPU,メモリ,スワップ,ロードアベレージの確認
  • 各プロセスの状態,CPU,,メモリ使用率の確認
  • 定期的な表示更新による監視
top - 15:00:31 up  5:02,  1 user,  load average: 0.00, 0.01, 0.05
Tasks: 131 total,   1 running, 130 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.3 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :   498888 total,    49300 free,   323580 used,   126008 buff/cache
KiB Swap:  2097148 total,   956264 free,  1140884 used.   144772 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND                                                                                                     
 2892 isucon    20   0   37280    260      0 S  0.3  0.1   0:01.83 h2o                                                                                                         
    1 root      20   0  125460   2716   1636 S  0.0  0.5   0:01.72 systemd                                                                                                     
    2 root      20   0       0      0      0 S  0.0  0.0   0:00.03 kthreadd                                                                                                    
    3 root      20   0       0      0      0 S  0.0  0.0   0:03.76 ksoftirqd/0  

sar

  • システム全体のCPU,メモリ,I/O,ネットワーク受送信量の確認
  • 定期的にログを取得し、過去に遡ってリソース状況を確認

メモリの管理

free

  • システム全体のメモリ,スワップ使用量の確認
$ free -h
              total        used        free      shared  buff/cache   available
Mem:           487M        322M         32M        1.1M        132M        134M
Swap:          2.0G        1.1G        938M

vmstat

  • システム全体のメモリ,スワップ,ディスクアクセス,CPUの確認
vmstat 5 3
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 2  0 1140884  48924      0 126580  253  223   834   299   60   96  1  1 98  0  0
 0  0 1140884  48924      0 126580    0    0     0     0    8   33  0  0 100  0  0
 0  0 1140884  48924      0 126580    0    0     0     0    8   33  0  0 100  0  0

ディスクI/Oの管理

iostat

  • デバイス毎のI/O情報、システム全体のCPU使用率の確認
 iostat 5
Linux 3.10.0-957.12.2.el7.x86_64 (webapp1)  09/11/2019  _x86_64_    (1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.61    0.00    0.78    0.46    0.00   98.16

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda              26.62       826.70       295.85   15166570    5427575

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.00    0.00    0.00    0.00    0.00  100.00

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda               0.20         1.59         0.00          8          0

iotop

  • topコマンドのようにI/O情報を監視
  • root権限が必要
# iotop 

Total DISK READ :      50.92 M/s | Total DISK WRITE :       0.00 B/s
Actual DISK READ:      50.92 M/s | Actual DISK WRITE:      15.17 M/s
  TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN     IO>    COMMAND
 3559 be/4 root       22.89 M/s    0.00 B/s  0.00 % 12.63 % python /sbin/iotop
 3179 be/4 root        2.17 M/s    0.00 B/s  0.00 %  8.26 % python2 -Es /usr/sbin/tuned -l -P
 3168 be/4 mysql       0.00 B/s    0.00 B/s  0.00 %  6.14 % mysqld --basedir=/

プロセスの管理

ps

  • プロセス毎のCPU,メモリ,状態,スレッド数などの確認
# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.4 125460  2252 ?        Ss   09:57   0:01 /usr/lib/systemd/systemd --switched-root --system --deserialize 21
root         2  0.0  0.0      0     0 ?        S    09:57   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    09:57   0:03 [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S<   09:57   0:00 [kworker/0:0H]
root         7  0.0  0.0      0     0 ?        S    09:57   0:00 [migration/0]

ディスク容量の管理

df

  • ファイルシステム毎のディスク使用量の確認
$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        40G  5.7G   35G  15% /
devtmpfs        236M     0  236M   0% /dev
tmpfs           244M     0  244M   0% /dev/shm
tmpfs           244M  4.5M  240M   2% /run
tmpfs           244M     0  244M   0% /sys/fs/cgroup
tmpfs            49M     0   49M   0% /run/user/1000

du

  • ディレクトリ毎のディスク使用量の確認
$ sudo du /var/ --max-depth=1
4   /var/tmp
131852  /var/lib
25516   /var/log
0   /var/adm
318004  /var/cache
8   /var/db
0   /var/empty
0   /var/games
0   /var/gopher
0   /var/local
0   /var/nis
0   /var/opt
0   /var/preserve
16  /var/spool
0   /var/yp
0   /var/kerberos
4   /var/www
475408  /var/
2
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
5