[root@centos ~]# nethogs
Ethernet link detected Waiting for first packet to arrive (see sourceforge.net bug 1019381)
NetHogs version 0.8.5
PID USER PROGRAM DEV SENT RECEIVED
4308 root sshd: root@pts/0 eno167 0.165 0.088 KB/sec
4508 root wget eno167 0.000 0.000 KB/sec
? root unknown TCP 0.000 0.000 KB/sec
TOTAL 0.165 0.088 KB/sec
vmstat:查看系统整体运行状态
vmstat :命令是最常见的Linux/Unix监控工具,可以展现给定时间间隔的服务器的状态值,包括 服务器的CPU使用率,MEM内存使用,VMSwap虚拟内存交换情况,IO读写情况。
使用vmstat可以看到整个机器的CPU,内存,IO的使用情况,而不是单单看到各个进程的CPU使 用率和内存使用率。 比top命令节省资源
[root@centos ~]# vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 0 3230876 948 469696 0 0 7 5 23 35 0 0 100 0 0
每一列参数作用:
r 运行状态的进程个数 。展示了正在执行和等待cpu资源的任务个数。
b 不可中断睡眠 正在进行i/o等待--阻塞状态的进程个数 进程读取外设上的数据,等待时
free 剩余内存,单位是KB
buffers #内存从磁盘读出的内容
cached #内存需要写入磁盘的内容
si swapin swap换入到内存
so swapout 内存换出到swap 换出的越多,内存越不够用
bi blockin 从硬盘往内存读。 单位是块。 把磁盘中的数据读入内存
bo blockout 从内存拿出到硬盘 (周期性的有值) 写到硬盘 #判断是读多还是写多,是否有i/o瓶颈
in 系统的中断次数,cpu调度的次数多
cs 每秒的上下文切换速度 CPU上下文切换--程序在运行的时候,
CPU对每个程序切换的过程。
sar:记录系统一段时间的运行状态
sysstat 工具包可以把检查到的信息保存下来! 存在/var/log/sa目录下,文件名为sa当 前日期 sar 默认显示每10分钟统计一次状态信息 (从装sysstat 包开始)
sar 命令行的常用格式: sar [options] [-A] [-o file] t [n] 在命令行中,n 和t 两个参数组合起来定义采样间隔和次数,t为采样间隔,是必须有的参数,n为采样 次数,是可选的,默认值是1,-o file表示将命令结果以二进制格式存放在文件中,file 在此处不是关键 字,是文件名。options 为命令行选项,sar命令的选项很多,下面只列出常用选项:
-A:所有报告的总和。
-n:网络接口的情况。
-u:CPU利用率
-v:进程、I节点、文件和锁表状态。
-d:硬盘使用报告。
-r:没有使用的内存页面和硬盘块。
-g:串口I/O的情况。
-b:缓冲区使用情况。
-a:文件读写情况。
-c:系统调用情况。
-R:进程的活动情况。
-y:终端设备活动情况。
-w:系统交换活动。
-o 文件名:打印到屏幕并将采样结果以二进制形式存入当前目录下的文件中。
-f 文件名:查看之前保存的二进制文件。
2秒钟采集一次,采集5次到sar.tar文件
[root@centos ~]# sar -u 2 5 -o sar.tar
Linux 3.10.0-327.el7.x86_64 (centos) 09/05/2019 _x86_64_ (4 CPU)
04:39:03 PM CPU %user %nice %system %iowait %steal %idle
04:39:05 PM all 0.00 0.00 0.12 0.12 0.00 99.75
04:39:07 PM all 0.12 0.00 0.12 0.00 0.00 99.75
04:39:09 PM all 0.00 0.00 0.12 0.00 0.00 99.88
04:39:11 PM all 0.00 0.00 0.13 0.00 0.00 99.87
04:39:13 PM all 0.00 0.00 0.25 0.00 0.00 99.75
Average: all 0.03 0.00 0.15 0.03 0.00 99.80
从文件中读取信息
sar -f 【文件】
[root@centos ~]# sar -f sar.tar
Linux 3.10.0-327.el7.x86_64 (centos) 09/05/2019 _x86_64_ (4 CPU)
04:39:03 PM CPU %user %nice %system %iowait %steal %idle
04:39:05 PM all 0.00 0.00 0.12 0.12 0.00 99.75
04:39:07 PM all 0.12 0.00 0.12 0.00 0.00 99.75
04:39:09 PM all 0.00 0.00 0.12 0.00 0.00 99.88
04:39:11 PM all 0.00 0.00 0.13 0.00 0.00 99.87
04:39:13 PM all 0.00 0.00 0.25 0.00 0.00 99.75
Average: all 0.03 0.00 0.15 0.03 0.00 99.80