linux查看进程在网卡使用率

1.前言

为了定位服务所在服务网络数据传输量,需要查看服务【进程】在网卡的传输数据情况

2.流程

2.1查看服务进程PID

  • ps -ef / ps aux 的到PID 8630
 ps aux | grep Test | grep -v grep
 
root    8630  0.3  0.3 53399460 910268 ?     Sl   06:01   0:55 java -cp .:/data/program/JobDispatchMaven/resources/bin/../:/data/program/JobDispatchMaven/resources/bin/../* com.wacai.stanlee.jobdispatch.restful.TestTaskApplication

2.2 查看在用网卡

  • ifconfig 查看所有网卡
eth4      Link encap:Ethernet  HWaddr 6C:92:BF:5C:DD:AB  
          inet addr:198.169.1.59  Bcast:10.1.170.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:925975732167 errors:1 dropped:12727 overruns:0 frame:1
          TX packets:1418557521419 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1109962622481632 (1009.5 TiB)  TX bytes:1900321284798969 (1.6 PiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:391399642 errors:0 dropped:0 overruns:0 frame:0
          TX packets:391399642 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1165459267577 (1.0 TiB)  TX bytes:1165459267577 (1.0 TiB)
  • watch cat /proc/net/dev 查看当前网卡,变化最大的即为当前使用的网卡
bytes: 网卡传输数量(byte),统计为字节(Byte)时需要除以8 
packets: 传输数据包数量
errs:发生错误的次数

Every 2.0s: cat /proc/net/dev                                                                                                                          Tue Jan 18 10:46:16 2022

Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
    lo: 1165460114440 391403931    0    0    0     0          0         0 1165460114440 391403931    0    0    0     0       0          0
  eth0:       0       0    0    0    0     0          0         0        0	 0    0    0    0     0       0          0
  eth1:       0       0    0    0    0     0          0         0        0	 0    0    0    0     0       0          0
  eth2:       0       0    0    0    0     0          0         0        0	 0    0    0    0     0       0          0
  eth3:       0       0    0    0    0     0          0         0        0	 0    0    0    0     0       0          0
  eth4: 1109962730701313 925975901153    1 12727    0     1          0        10 1900323239931342 1418558844161    0    0    0     0	   0          0

nethogs, 查看服务的运行情况,root启动 nethogs

  • 查看使用方法,无nethogs自行安装,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,查看结果如下
    在这里插入图片描述

  • ethtool eth4 ,查看当前使用网卡配置

 ethtool eth4
 
Settings for eth4:
	Supported ports: [ FIBRE ]
	Supported link modes:   10000baseT/Full        // 10000 兆全双工
	Supported pause frame use: No
	Supports auto-negotiation: No
	Advertised link modes:  10000baseT/Full 
	Advertised pause frame use: No
	Advertised auto-negotiation: No
	Speed: 10000Mb/s
	Duplex: Full
	Port: FIBRE
	PHYAD: 0
	Transceiver: external
	Auto-negotiation: off
	Supports Wake-on: d
	Wake-on: d
	Current message level: 0x00000007 (7)
			       drv probe link
	Link detected: yes.    //eth4已经激活

支持连接模式:10000 兆全双工
网络带宽: 10000兆,统计为Byte为10000/8 = 1250MB

2.3 sar 查看网络传输情况

一秒查看五次: sar  -n  DEV  1  5
IFACE: 设备名称
rxpck/s: 每秒接收数据包数量
txpck/s: 每秒传输数据包数量
rxkB/s: 每秒接收数据量大小[kB]
txkB/s: 每秒传输数据量大小[kB]   

计算实际速度, 取rxkB或txkB,换算成KB,如1000kB,然后转换为存储单位【Byte,字节】1000/8 = 125 MBit
Bytes 字节: 缩写为B【存储最小单位】
bit ,1Byte = 8 bit,【网络传输最小单位】
bps = bit per second 每秒位数
pps = package per secod 每秒数据包数量 Mb,Gb; 如10Gb = 10000Gb [所谓万兆网卡,实际传输数据量最大为 1250MB】

在这里插入图片描述

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值