キャパシティプランニング 201 重要度:6

/ LPIC / Comment[0]
http://wiki.lpi.org/wiki/LPIC-2#Topic_200:_Capacity_Planning

ハードウェアリソースとネットワーク帯域の計測方法とリソースに関するトラブルシューティング


知っておくべき項目

  • CPU使用率の計測
  • メモリ使用量の計測
  • I/Oディスクの計測
  • ネットワークI/Oの計測
  • ファイアーウォールとルーターのスループット計測
  • クライアントに帯域を割り当て
  • それらに関連したシステムの症状
  • ネットワークにおけるボトルネックとスループットを概算する

重要なコマンドや用語、ユーティリティ

  1. iostat, vmstat
  2. netstat
  3. pstree,ps
  4. w
  5. lsof
  6. top
  7. uptime
  8. sar
  9. swap
  10. processes blocked on I/O
  11. blocks in
  12. blocks out

5段階かと思われた重要度ですが、キャパシティプランニングだけは何故か6なのでこれは完璧にマスターしておきたいところです。


1. ディスクのリソース計測 iostat, vmstat


iostat


CPUI/O(Input/Output)デバイスの負荷状態を報告するコマンドです。
iostatのコマンドの出力結果は今後のシステムの設定やハードウェア構成などで参考になります。

構文: iostat [options] [<interval> [<count> ] ]


オプション:

  • -c CPU統計のみ表示
  • -d I/Oディスク統計のみ表示
  • -k KB表示
  • -m MB表示
  • -j { ID | LABEL | PATH | UUID } デバイスを指定(例: -j UUID fc94056d-c0b9-4947-ac10-f9baac30a065)


# iostat
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
0.06 0.03 0.05 0.02 0.00 99.85

Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 0.24 6.75 3.43 754958 383628
sdb 0.00 0.01 0.00 1380 0

iostatの見方

CPU:
  • %user ユーザーレベル(アプリケーション)のCPU使用率
  • %nice ユーザーレベルのプロセス優先度
  • %system カーネルレベルのCPU使用率
  • %iowait CPUのアイドル中に未処理のディスク入出力要求があった時間の割合
  • %idle CPUもI/Oもアイドルの割合

CPU使用率は%idle以外の数値の合計または、100(%)から%idleを引いた数字になります。
CPU使用率 = %user + %nice + %system + %iowait + %steal = 100 - %idle


I/O:
  • tps 毎秒のI/Oリクエスト数
  • kB_read/s 毎秒の読み込み量(kB)
  • kB_wrtn/s 毎秒の書き込み量

例: CPUと/dev/sdaと/dev/sdbの状態を1秒毎に3回表示 (/devは省略可能)

# iostat -p sda,sdb 1 3
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
4.53 0.06 5.01 1.55 0.00 88.85

Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 21.71 922.39 15.14 153974 2528
sda1 18.95 909.32 15.07 151793 2516
sda2 1.67 8.80 0.07 1469 12
sdb 2.07 8.27 0.00 1380 0
sdb1 1.16 4.65 0.00 776 0

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

Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 0.00 0.00 0.00 0 0
sda1 0.00 0.00 0.00 0 0
sda2 0.00 0.00 0.00 0 0
sdb 0.00 0.00 0.00 0 0
sdb1 0.00 0.00 0.00 0 0

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

Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 0.00 0.00 0.00 0 0
sda1 0.00 0.00 0.00 0 0
sda2 0.00 0.00 0.00 0 0
sdb 0.00 0.00 0.00 0 0
sdb1 0.00 0.00 0.00 0 0

I/Oディスクの統計だけをMB単位で1秒間隔で表示し続ける

# iostat -d -m 1
Device:            tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn
sdb 0.00 0.00 0.00 0 0
sda 57.00 0.00 24.03 0 24

Device: tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sdb 0.00 0.00 0.00 0 0
sda 30.00 0.05 8.43 0 8

Device: tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sdb 0.00 0.00 0.00 0 0
sda 241.00 3.00 16.00 3 16

Device: tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sdb 0.00 0.00 0.00 0 0
sda 193.00 0.33 54.37 0 54

Device: tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sdb 0.00 0.00 0.00 0 0
sda 2.00 0.00 0.05 0 0
:

vmstat


プロセス、メモリ、ページング(仮想メモリ)、block IO、ディスクとCPUの状態を表示するコマンドです。
基本的な構文はiostatと似ています。


構文: vmstat [options] [delay [count] ]


オプション

  • -a, --active アクティブ/インアクティブメモリを表示
  • -f, --forks システム起動時からのフォーク数を表示
  • -m, --slabs スラブ情報を表示
  • -s, --stats 全ての統計を表示
  • -d, --disk ディスク情報を表示
  • -D, --disk-sum ディスク統計を表示
  • -p, --partition パーティションごとの統計を表示

例: アクティブ/インアクティブメモリを表示 -wオプションをつけることで表示幅が広がり見やすくなります。


# vmstat -aw
procs ---------------memory-------------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free inact active si so bi bo in cs us sy id wa st
0 0 0 69772 424424 430708 0 0 58 37 62 65 0 1 99 0 0

システム起動時からのフォーク数を表示する

# vmstat -f
         9006 forks

全ての統計を表示

# vmstat -s
      1000552 K total memory
930720 K used memory
430700 K active memory
424456 K inactive memory
69832 K free memory
20960 K buffer memory
774064 K swap cache
0 K total swap
0 K used swap
0 K free swap
2916 non-nice user cpu ticks
96 nice user cpu ticks
5101 system cpu ticks
974484 idle cpu ticks
930 IO-wait cpu ticks
0 IRQ cpu ticks
358 softirq cpu ticks
0 stolen cpu ticks
527238 pages paged in
332484 pages paged out
0 pages swapped in
0 pages swapped out
586753 interrupts
622309 CPU context switches
1410592950 boot time
9034 forks

ディスク統計を1秒毎に表示し続ける(-nでヘッダーを表示しない)

# vmstat -dn 1
:
loop6 0 0 0 0 0 0 0 0 0 0
loop7 0 0 0 0 0 0 0 0 0 0
sdb 345 0 2760 188 0 0 0 0 0 0
sda 6447 7807 1028420 298992 1346 638 665200 81820 0 16


2. netstat


ネットワーク接続やルーティングテーブル、インターフェイス情報などを表示するコマンドです。


書式: netstat [options]


オプション

  • -r, --route ルーティングテーブルを表示
  • -i インターフェイスを指定
  • -s, --statistics ネットワーク統計を表示
  • -t, --tcp TCPのみ表示
  • -u, --udp UDPのみ表示
  • -a, --all 全ての接続中ソケットを表示
  • -l, --listening リスニング中ソケットを表示
  • -n, --numeric 名前解決しない/li>

例: TCPで接続中のホストのIPアドレスを表示

# netstat -tn
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 10.0.1.1:445 10.0.0.1:11655 ESTABLISHED
tcp 0 0 10.0.1.1:22 10.0.0.1:12512 ESTABLISHED

TCPでリスニング中のポートを表示

# netstat -tln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:139 0.0.0.0:* LISTEN
tcp 0 0 10.0.1.1:53 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:9050 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:445 0.0.0.0:* LISTEN
tcp6 0 0 :::139 :::* LISTEN
tcp6 0 0 :::80 :::* LISTEN
tcp6 0 0 :::53 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:953 :::* LISTEN
tcp6 0 0 :::445 :::* LISTEN

UDPの統計が見たい場合は-uまたは--udpオプションを指定します。


ルーティングを表示

# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 10.255.0.1 0.0.0.0 UG 0 0 0 eth1
10.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 eth1

統計情報を表示

# netstat -s
Ip:
54636 total packets received
0 forwarded
0 incoming packets discarded
2132 incoming packets delivered
1632 requests sent out
Icmp:
3 ICMP messages received
1 input ICMP message failed.
ICMP input histogram:
destination unreachable: 3
3 ICMP messages sent
0 ICMP messages failed
ICMP output histogram:
destination unreachable: 3
IcmpMsg:
InType3: 3
OutType3: 3
Tcp:
34 active connections openings
9 passive connection openings
31 failed connection attempts
0 connection resets received
2 connections established
2008 segments received
1538 segments send out
3 segments retransmited
0 bad segments received.
30 resets sent
Udp:
257 packets received
0 packets to unknown port received.
0 packet receive errors
116 packets sent
UdpLite:
TcpExt:
1 resets received for embryonic SYN_RECV sockets
4 TCP sockets finished time wait in fast timer
20 delayed acks sent
1 packets directly queued to recvmsg prequeue.
790 packet headers predicted
348 acknowledgments not containing data payload received
396 predicted acknowledgments
3 other TCP timeouts
1 DSACKs received
TCPDeferAcceptDrop: 8
TCPRcvCoalesce: 123
TCPOFOQueue: 59
TCPSpuriousRtxHostQueues: 1
IpExt:
InBcastPkts: 110
OutBcastPkts: 77
InOctets: 62966317
OutOctets: 294159
InBcastOctets: 16897
OutBcastOctets: 13870
InNoECTPkts: 55740
InECT0Pkts: 29
InCEPkts: 4


3. プロセスの一覧を表示 pstree, ps


ps


現在実行中のプロセスを表示するコマンドです。


構文] ps [options]


オプション

  • -A,-e 全てのプロセスを表示
  • -u ユーザを指定(デフォルトでは自分)
  • -123 PID:123を表示

psコマンドは大文字小文字ハイフン有り無しで挙動が変わったりと複雑です。よく使うオプションは限られているので省略します。


例: 全てのプロセスを表示

# ps -e


PID476のプロセスとユーザを表示

# ps -up 476

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
syslog 476 0.0 0.1 255844 1236 ? Ssl 18:08 0:00 rsyslogd

全てのユーザとコマンドの引数まで表示

# ps aux
:
root 913 0.0 0.3 61364 3076 ? Ss 18:08 0:00 /usr/sbin/sshd -D
root 917 0.0 0.0 4368 676 ? Ss 18:08 0:00 acpid -c /etc/acpi/events -s /var/run/acpid.socket
root 921 0.0 0.1 23656 1064 ? Ss 18:08 0:00 cron
daemon 922 0.0 0.0 19140 168 ? Ss 18:08 0:00 atd
bind 960 0.0 1.6 239712 16332 ? Ssl 18:08 0:00 /usr/sbin/named -u bind
debian-+ 1005 0.0 3.0 59832 30536 ? S 18:08 0:08 /usr/bin/tor --defaults-torrc /usr/share/tor/tor-service-defaults-torrc --hush
root 1067 0.0 0.2 71300 2608 ? Ss 18:08 0:00 /usr/sbin/apache2 -k start
www-data 1069 0.0 0.4 426064 4604 ? Sl 18:08 0:02 /usr/sbin/apache2 -k start
www-data 1070 0.0 0.4 360504 4260 ? Sl 18:08 0:02 /usr/sbin/apache2 -k start
root 1138 0.1 0.1 15160 1216 ? SNs 18:08 0:17 /usr/sbin/preload -s /var/lib/preload/preload.state
root 1239 0.0 0.0 15820 944 tty1 Ss+ 18:08 0:00 /sbin/getty -8 38400 tty1
c 12745 0.0 0.1 15568 1148 pts/0 R+ 21:38 0:00 ps aux
root 30721 0.0 0.4 105632 4344 ? Ss 20:30 0:00 sshd: c [priv]
c 30818 0.0 0.2 105632 2136 ? S 20:30 0:01 sshd: c@pts/0
c 30819 0.0 0.3 19592 3636 pts/0 Ss 20:30 0:00 -bash

pstree


プロセスをツリー上に表示するコマンドです。


例: プロセスの引数も表示


# pstree -a
init
|-acpid -c /etc/acpi/events -s /var/run/acpid.socket
|-apache2 -k start
| |-apache2 -k start
| | `-26*[{apache2}]
| `-apache2 -k start
| `-26*[{apache2}]
|-atd
|-cron
|-dbus-daemon --system --fork
|-getty -8 38400 tty4
|-getty -8 38400 tty5
|-getty -8 38400 tty2
|-getty -8 38400 tty3
|-getty -8 38400 tty6
|-getty -8 38400 tty1
|-named -u bind
| `-4*[{named}]
|-nmbd -D
|-preload -s /var/lib/preload/preload.state
|-rsyslogd
| `-3*[{rsyslogd}]
|-smbd -F
| |-smbd -F
| `-smbd -F
|-sshd -D
| `-sshd
| `-sshd
| `-bash
| `-sudo pstree -a
| `-pstree -a
|-systemd-logind
|-systemd-udevd --daemon
|-tor --defaults-torrc /usr/share/tor/tor-service-defaults-torrc --hush
|-upstart-file-br --daemon
|-upstart-socket- --daemon
`-upstart-udev-br --daemon

ユーザーhogeが実行しているプロセスのツリーを表示

# pstree -u hoge
bash-+-nmap
`-ping


4. 誰が何をしているかを表示 w


決して煽っているわけではありません。そういうコマンドなんです。

# w
 22:24:34 up  4:16,  2 users,  load average: 0.00, 0.01, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
testuser tty1 22:24 2.00s 0.25s 0.00s ping google.com
c pts/0 10.0.0.1 20:30 2.00s 0.52s 0.10s sshd: c [priv]

ユーザーtestuserのログイン時間と実行中のコマンドを表示

# w testuser

一般ユーザー権限で使えるコマンドなのでLinuxサーバーを共有している場合は気をつけたほうが良いですね。
例えば引数にユーザー名パスワードを指定するアプリを使ってる場合とか全ユーザーから丸見えです。



5. プロセスが開いているファイルやポートなどを表示 lsof


ファイルを使用中のプロセスを特定したり、ポートを使用中のアプリを特定したり色々と便利なコマンドです。


/mnt/fileを開いているユーザ,PIDなどを特定

# lsof /mnt/file
COMMAND   PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
less 25786 testuser 4r REG 8,1 4 9172 /mnt/file

testuserが開いているファイルを表示

# lsof -u testuser
COMMAND   PID     USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME
bash 21785 testuser cwd DIR 8,1 4096 103 /mnt
bash 21785 testuser rtd DIR 8,1 4096 2 /
bash 21785 testuser txt REG 8,1 1017016 148070 /bin/bash
bash 21785 testuser mem REG 8,1 47712 161410 /lib/x86_64-linux-gnu/libnss_files-2.19.so
bash 21785 testuser mem REG 8,1 47760 161411 /lib/x86_64-linux-gnu/libnss_nis-2.19.so
bash 21785 testuser mem REG 8,1 97296 130562 /lib/x86_64-linux-gnu/libnsl-2.19.so
bash 21785 testuser mem REG 8,1 39824 130388 /lib/x86_64-linux-gnu/libnss_compat-2.19.so
bash 21785 testuser mem REG 8,1 1845024 161403 /lib/x86_64-linux-gnu/libc-2.19.so
bash 21785 testuser mem REG 8,1 14664 161415 /lib/x86_64-linux-gnu/libdl-2.19.so
bash 21785 testuser mem REG 8,1 167096 130698 /lib/x86_64-linux-gnu/libtinfo.so.5.9
bash 21785 testuser mem REG 8,1 149120 161404 /lib/x86_64-linux-gnu/ld-2.19.so
bash 21785 testuser 0u CHR 4,1 0t0 1067 /dev/tty1
bash 21785 testuser 1u CHR 4,1 0t0 1067 /dev/tty1
bash 21785 testuser 2u CHR 4,1 0t0 1067 /dev/tty1
bash 21785 testuser 255u CHR 4,1 0t0 1067 /dev/tty1

80/TCPを使用しているユーザ,PIDなどを特定

# lsof -i:80
COMMAND  PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
apache2 1067 root 4u IPv6 10409 0t0 TCP *:http (LISTEN)
apache2 1069 www-data 4u IPv6 10409 0t0 TCP *:http (LISTEN)
apache2 1070 www-data 4u IPv6 10409 0t0 TCP *:http (LISTEN)

指定したPIDが開いているファイルを表示

# lsof -p 12983
COMMAND   PID USER   FD   TYPE             DEVICE SIZE/OFF   NODE NAME
sshd 12983 root cwd DIR 8,1 4096 2 /
sshd 12983 root rtd DIR 8,1 4096 2 /
sshd 12983 root txt REG 8,1 766784 11435 /usr/sbin/sshd
sshd 12983 root DEL REG 0,4 15004 /dev/zero
sshd 12983 root mem REG 8,1 14464 130722 /lib/x86_64-linux-gnu/security/pam_env.so
sshd 12983 root mem REG 8,1 22896 130731 /lib/x86_64-linux-gnu/security/pam_limits.so
sshd 12983 root mem REG 8,1 10320 130735 /lib/x86_64-linux-gnu/security/pam_mail.so
sshd 12983 root mem REG 8,1 10344 130737 /lib/x86_64-linux-gnu/security/pam_motd.so
sshd 12983 root mem REG 8,1 14592 130660 /lib/x86_64-linux-gnu/libpam_misc.so.0.82.0
sshd 12983 root mem REG 8,1 38920 130640 /lib/x86_64-linux-gnu/libnih-dbus.so.1.0.0
:


6. リアルタイムにプロセスを表示 top


リアルタイムでCPU使用率が高いプロセスを順(次にPID番号順)に表示するコマンドです。
オプションはいくつかありますがLPIC201ではそれほど重要ではないでしょう。


# top
%Cpu(s):  0.1 us,  0.2 sy,  0.0 ni, 99.6 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem: 1000552 total, 294968 used, 705584 free, 27440 buffers
KiB Swap: 0 total, 0 used, 0 free. 152976 cached Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 33608 2936 1480 S 0.0 0.3 0:04.20 init
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:00.05 ksoftirqd/0
4 root 20 0 0 0 0 S 0.0 0.0 0:00.52 kworker/0:0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
7 root 20 0 0 0 0 S 0.0 0.0 0:00.97 rcu_sched
8 root 20 0 0 0 0 S 0.0 0.0 0:00.44 rcuos/0
9 root 20 0 0 0 0 S 0.0 0.0 0:00.44 rcuos/1
10 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuos/2
11 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuos/3
12 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
13 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/0
14 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/1
15 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/2
16 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/3
17 root rt 0 0 0 0 S 0.0 0.0 0:00.09 migration/0
18 root rt 0 0 0 0 S 0.0 0.0 0:00.83 watchdog/0
19 root rt 0 0 0 0 S 0.0 0.0 0:00.96 watchdog/1
20 root rt 0 0 0 0 S 0.0 0.0 0:00.01 migration/1
21 root 20 0 0 0 0 S 0.0 0.0 0:00.01 ksoftirqd/1
23 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/1:0H
24 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 khelper
25 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kdevtmpfs


7. システム起動時刻と稼働時間を表示 uptime


システム稼動時間を表示

# uptime
 23:00:35 up  4:52,  2 users,  load average: 0.00, 0.01, 0.05

システム起動時刻を表示

# uptime -s
2014-09-13 18:08:33


8. システムのアクティビティを統計を記録・表示 sar


指定した間隔のアクティビティの統計を記録したり表示したりするコマンドです。


1秒毎に10回のアクティビティ統計を取ってtest.sarファイルに保存

# sar -o test.sar 1 10

sarによって生成されるファイルはバイナリ形式なので次のsarコマンドで表示します。

# sar -f test.sar

記録したファイルから指定した時間内の統計を表示

# sar -f test.sar -s 23:22:56 -e 23:25:37
23:22:56        CPU     %user     %nice   %system   %iowait    %steal     %idle
23:25:27 all 0.10 0.02 0.25 0.03 0.00 99.61
23:25:28 all 0.00 0.00 0.50 0.00 0.00 99.50
23:25:29 all 0.00 0.00 0.50 0.00 0.00 99.50
23:25:30 all 0.00 0.00 1.00 0.00 0.00 99.00
23:25:31 all 0.50 0.00 0.50 0.00 0.00 99.00
23:25:32 all 0.50 0.00 0.50 0.00 0.00 99.00
23:25:33 all 0.00 0.00 0.50 1.00 0.00 98.50
23:25:34 all 0.00 0.00 0.50 0.00 0.00 99.50
23:25:35 all 0.00 0.50 3.47 0.00 0.00 96.04
23:25:36 all 0.50 0.00 0.50 0.00 0.00 99.00
23:25:37 all 0.00 0.00 1.00 0.00 0.00 99.00
Average: all 0.10 0.02 0.29 0.03 0.00 99.56
関連記事

コメント

:
:
:
:
:
管理人のみ表示を許可