iftop 概要
CLI上で利用できるネットワークの接続状況をリアルモニタリングするツールです。
→ ネットワークのボトルネックを特定する為に利用します。
単にネットワークのモニタリングであれば、モニタリングツールで良いですが
具体的にどこ(ドメイン・IP・ポート)にどれくらい(データ転送量)がわかります。
インストール方法
| 1
 | $ sudo apt-get install -y iftop
 | 
| 12
 
 | $ sudo yum -y install epel-release$ sudo yum -y install iftop
 
 | 
使い方
よく利用するのはこんな形です。
※eth0 がない場合は -i eth0 を除いてください。
| 1
 | $ sudo iftop -i eth0 -B -P -n -N
 | 
- -i インターフェース指定
- -B 表示単位を Byte にする
- -P プロトコル or ポート表示
- -n ドメインでなく ip で表示
- -N プロトコルサービス名でなくポート番号で表示
表示項目
=> が送信、
<= が受信です
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 
 |                            24.4kB                      48.8kB                      73.2kB                      97.7kB                 122kB+--------------------------+---------------------------+---------------------------+---------------------------+---------------------------
 ip-10-13-1-101.ap-northeast-1.compute.internal:http      => ip-10-13-100-41.ap-northeast-1.compute.internal:62635     559kB   121kB  67.1kB
 <=                                                          3.60kB  1.90kB  1.05kB
 ip-10-13-1-101.ap-northeast-1.compute.internal:35244     => ip-10-13-102-56.ap-northeast-1.compute.internal:mysql       0B   2.18kB  1.21kB
 <=                                                             0B   23.1kB  12.8kB
 ip-10-13-1-101.ap-northeast-1.compute.internal:35247     => ip-10-13-102-56.ap-northeast-1.compute.internal:mysql       0B   2.13kB  1.18kB
 <=                                                             0B   23.0kB  12.8kB
 ip-10-13-1-101.ap-northeast-1.compute.internal:http      => ip-10-13-0-231.ap-northeast-1.compute.internal:8239         0B   7.73kB  4.29kB
 <=                                                             0B   1.16kB   658B
 ip-10-13-1-101.ap-northeast-1.compute.internal:ssh       => ip-10-13-0-11.ap-northeast-1.compute.internal:56320       612B    576B    522B
 <=                                                            26B     26B     32B
 ip-10-13-1-101.ap-northeast-1.compute.internal:http      => ip-10-13-100-41.ap-northeast-1.compute.internal:62657       0B     49B     27B
 <=                                                             0B     92B     51B
 ip-10-13-1-101.ap-northeast-1.compute.internal:40069     => ip-10-13-103-247.ap-northeast-1.compute.internal:6379       0B     99B     55B
 <=                                                             0B     34B     19B
 ip-10-13-1-101.ap-northeast-1.compute.internal:40072     => ip-10-13-103-247.ap-northeast-1.compute.internal:6379       0B     99B     55B
 <=                                                             0B     34B     19B
 ip-10-13-1-101.ap-northeast-1.compute.internal:http      => ip-10-13-100-73.ap-northeast-1.compute.internal:27698       0B     44B     25B
 <=                                                             0B     33B     18B
 ip-10-13-1-101.ap-northeast-1.compute.internal:53696     => ip-10-13-0-2.ap-northeast-1.compute.internal:domain         0B     21B     12B
 <=                                                             0B     31B     17B
 ip-10-13-1-101.ap-northeast-1.compute.internal:41975     => ip-10-13-0-2.ap-northeast-1.compute.internal:domain         0B     21B     12B
 <=                                                             0B     31B     17B
 -------------------------------------------------------------------------------------------------------------------------------------------
 TX:             cum:   1.31MB   peak:    560kB                                                             rates:    560kB   134kB  74.7kB
 RX:                     505kB            117kB                                                                      3.69kB  49.8kB  28.1kB
 TOTAL:                 1.81MB            564kB                                                                       564kB   184kB   103kB
 
 | 
| Item | Value | 
| TX (Transmitter) | 送信量 | 
| RX (Receiver) | 受信量 | 
| TOTAL | iftop 起動からの総量 | 
| cum | 総量 | 
| peak | 最大 | 
| 右端3列 (各トラフィック, rates含む) | 2秒、10秒、40秒の転送量平均値 | 
※TX,RX の 「X」 は省略しますよという意味
閲覧し続けると気になる処理があった時には
Shift + P で一旦停止させます。
もう一度開始したい場合は Shift + P です。
実際のCLI
以下見ていただくと白い帯グラフが左から伸びているのが見えるかと思います。
この横棒が一番上のバーの目盛りに相応してぱっと見でどの程度かわかるのが便利です。
DB への接続を確かめる
DB (MySQL) のデフォルトポート 3306 への送受信を調べたいとき
| 1
 | $ sudo iftop -B -P -n -N -f "port 3306"
 | 
当然ながら受信の方が大きいです。
補足
実際に負荷が高い時等、特定のインシデントがあった際に追記していこうと思います♪
Reference