在平常运维环境中,咱们确定会遇到如下这种需求:面试
一、网络流量异常,不知道是哪一个程序的流量爆涨?网络
二、平常须要监控网络实时的流量进去数据运维
面试装逼系列|这篇文章,让运维监控再也不成为你的短板! ssh
学会这 18 个工具,你必定能真正理解如何监控网络带宽! 工具
基于这两点需求,民工哥今天给你们分享两个很强大的命令工具:oop
1.Nethogsui
1.1 Nethogs介绍 this
NetHogs是一个开源的命令行工具(相似于Linux的top命令),用来按进程或程序实时统计网络带宽使用率。.net
NetHogs是一个小型的net top工具,不像大多数工具那样拖慢每一个协议或者是每一个子网的速度而是按照进程进行带宽分组。NetHogs不须要依赖载入某个特殊的内核模块。若是发生了网络阻塞你能够启动NetHogs当即看到哪一个PID形成的这种情况。这样就很容易找出哪一个程序跑飞了而后忽然占用你的带宽。命令行
1.2 Nethogs安装
安装依赖包
[root@rs-server ~]# yum install libpcap libpcap-devel -y
[root@rs-server ~]# yum -y install epel-release
安装nethogs
[root@rs-server ~]# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) [root@rs-server ~]# uname -r 3.10.0-693.el7.x86_64 [root@rs-server ~]# yum install nethogs -y
[root@rs-server ~]# nethogs -help usage: nethogs [-V] [-h] [-b] [-d seconds] [-v mode] [-c count] [-t] [-p] [-s] [device [device [device ...]]] -V : prints version. -h : prints this help. -b : bughunt mode - implies tracemode. -d : delay for update refresh rate in seconds. default is 1. -v : view mode (0 = KB/s, 1 = total KB, 2 = total B, 3 = total MB). default is 0. -c : number of updates. default is 0 (unlimited). -t : tracemode. -p : sniff in promiscious mode (not recommended). -s : sort output by sent column. -a : monitor all devices, even loopback/stopped ones. device : device(s) to monitor. default is all interfaces up and running excluding loopback When nethogs is running, press: q: quit s: sort by SENT traffic r: sort by RECEIVE traffic m: switch between total (KB, B, MB) and KB/s mode
输入命令nethogs -help出现帮助信息,代表安装成功,很是的简单快速。
1.3 Nethogs命令介绍**
如下是NetHogs的一些交互命令(键盘快捷键)
参数介绍:
1.4 Nethogs实践**
[root@rs-server ~]# nethogs Ethernet link detected Ethernet link detectedWaiting for first packet to arrive (see sourceforge.net bug 1019381) NetHogs version 0.8.5 PID USER PROGRAM DEV SENT RECEIVED 1023 root sshd: root@pts/0 ens33 0.166 0.059 KB/sec ? root unknown TCP 0.000 0.000 KB/sec TOTAL 0.166 0.059 KB/sec
直接使用nethogs命令的显示界面如上
[root@rs-server ~]#nethogs -d2 -v3 -c5 -a Ethernetlinkdetected Ethernetlinkdetected Ethernetlinkdetected Waitingforfirstpackettoarrive(seesourceforge.netbug1019381) NetHogsversion0.8.5 PIDUSERPROGRAMDEVSENTRECEIVED 1023 rootsshd:root@pts/0 ens33 0.0010.000MB ? root unknown TCP 0.0000.000MB TOTAL 0.0010.000MB
nethogs命令功能仍是挺强大的,抓紧时间练习一下吧!!
2.Nload
2.1 nload介绍
nload是一个实时监控网络流量和带宽使用状况,展现进出的流量状况,不只有数值,也能够有动态图展现。
2.2 nload 安装
[root@rs-server ~]# yum -y install epel-release
nload安装
[root@rs-server ~]# yum install nload -y
nload若是直接输入这个命令默认只查看第一个网络的流量进出状况,通常是在nload后面指定网络,能够指定多个网络。
2.3 nload操做介绍
nload 默认分为上下两块:
每部分都有当前流量(Curr),
平均流量(Avg),
最小流量(Min),
最大流量(Max),
总和流量(Ttl)这几个部分,看起来仍是蛮直观的。
nload默认的是eth0网卡,若是你想监测eth1网卡的流量 #nload eth1
参数介绍
2.4 nload实践
Device ens33 [192.168.1.100] (1/1): ============================================================================ Incoming: Curr: 936.00 Bit/s Avg: 1.27 kBit/s Min: 840.00 Bit/s Max: 6.26 kBit/s Ttl: 8.78 MByte Outgoing: Curr: 7.70 kBit/s Avg: 7.70 kBit/s Min: 3.97 kBit/s Max: 10.49 kBit/s Ttl: 299.35 kByte
更多相关的参数与操做,你们能够本身练习一下。