Linux重要进程负载情况报告,Linux进程与性能监控

系统性能监控相关命令

1.vmstat命令

Report virtual memory statistics,报告虚拟内存的统计数据。

常用选项:# #:vmstat后面直接给出数字第一个数字表示每隔#秒刷新一次,

第二个数字表示一共刷新#次后退出命令

-s:显示内存统计数据;

实例:[root@young ~]# vmstat 1 3

procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----

r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st

2  0      0 265280 365520 1900176    3    3   354    27   34   24  2  2 96  0  0

0  0      0 269016 365520 1900116    0    0     0     0  293  439  8  6 86  0  0

0  0      0 269016 365520 1900116    0    0     0     0   43   94  0  0 100  0  0

[root@young ~]# vmstat -s

3098484 K total memory

563444 K used memory

774264 K active memory

1633428 K inactive memory

269404 K free memory

365520 K buffer memory

1900116 K swap cache

2097148 K total swap

0 K used swap

说明:

procs:r:等待运行的进程的个数;CPU上等待运行的任务的队列长度;

b:处于不可中断睡眠态的进程个数;(被阻塞的进程队列的长度)

memory:swpd: 交换内存使用总量;

free: 空闲的物理内存总量;

buffer:用于buffer的内存总量;

cache: 用于cache的内存总量;

swap:si: 数据进入swap中的速率(kb/s)

so: 数据离开swap中的速率(kb/s)

io:bi: 从块设备读入数据到系统的速率(block/s),默认块大小是1024byte

bo: 保存数据至块设备的速率(block/s),默认块大小是1024byte

system:in: interrupts,中断速率

cs: context switch, 上下文切换速率

cpu:us:Time spent running non-kernel code

sy: Time spent running kernel code

id: Time spent idle. Linux 2.5.41前,包括IO-wait time.

wa: Time spent waiting for IO. 2.5.41前,包括in idle.

st: Time stolen from a virtual machine. 2.6.11前, unknown.

小贴士:

那buffers和cached都是缓存,两者有什么区别呢?

为了提高磁盘存取效率, Linux做了一些精心的设计, 除了对dentry进行缓存(用于VFS,加速文件路径名到inode的转换), 还采取了两种主要Cache方式:Buffer Cache和Page Cache。前者针对磁盘块的读写,后者针对文件inode的读写。这些Cache有效缩短了 I/O系统调用(比如read,write,getdents)的时间。

磁盘的操作有逻辑级(文件系统)和物理级(磁盘块),这两种Cache就是分别缓存逻辑和物理级数据的。

Page cache实际上是针对文件系统的,是文件的缓存,在文件层面上的数据会缓存到page cache。文件的逻辑层需要映射到实际的物理磁盘,这种映射关系由文件系统来完成。当page cache的数据需要刷新时,page cache中的数据交给buffer cache,因为Buffer Cache就是缓存磁盘块的。但是这种处理在2.6版本的内核之后就变的很简单了,没有真正意义上的cache操作。

Buffer cache是针对磁盘块的缓存,也就是在没有文件系统的情况下,直接对磁盘进行操作的数据会缓存到buffer cache中,例如,文件系统的元数据都会缓存到buffer cache中。

简单说来,page cache用来缓存文件数据,buffer cache用来缓存磁盘数据。在有文件系统的情况下,对文件操作,那么数据会缓存到page cache,如果直接采用dd等工具对磁盘进行读写,那么数据会缓存到buffer cache。

2.pmap命令

查看指定进程内存映射关系

命令格式:pmap [OPTIONS] PID

常用选项:-x:显示扩展信息

-d   device         Show the device format.   显示设备格式

-q   quiet          Do not display some header/footer lines. 不显示头尾行

实例:[root@young ~]# pmap 1 -x|head -5

1:   /usr/lib/systemd/systemd --switched-root --system --deserialize 21

Address           Kbytes     RSS   Dirty Mode  Mapping

00007f5154000000     164      12      12 rw---   [ anon ]

00007f5154029000   65372       0       0 -----   [ anon ]

00007f515b443000       4       0       0 -----   [ anon ]

[root@young ~]# pmap -d 1 |head -5

1:   /usr/lib/systemd/systemd --switched-root --system --deserialize 21

Address           Kbytes Mode  Offset           Device    Mapping

00007f5154000000     164 rw--- 0000000000000000 000:00000   [ anon ]

00007f5154029000   65372 ----- 0000000000000000 000:00000   [ anon ]

00007f515b443000       4 ----- 0000000000000000 000:00000   [ anon ]

说明:

扩展格式和设备格式域:Address:  start address of map  映像起始地址

Kbytes:  size of map in kilobytes  映像大小

RSS:  resident set size in kilobytes  驻留集大小

Dirty:  dirty pages (both shared and private) in kilobytes  脏页大小

Mode:  permissions on map 映像权限: r=read, w=write, x=execute, s=shared, p=private (copy on write)

Mapping:  file backing the map , or '[ anon ]' for allocated memory, or '[ stack ]' for the program stack.映像支持文件,[anon]为已分配内存[stack]为程序堆栈

Offset:  offset into the file  文件偏移

Device:  device name (major:minor)  设备名

[root@young ~]# pmap -d 1|tail -3

00007fff69d59000       8 r-x-- 0000000000000000 000:00000   [ anon ]

ffffffffff600000       4 r-x-- 0000000000000000 000:00000   [ anon ]

mapped: 129164K    writeable/private: 23876K    shared: 0K

说明:mapped 表示该进程映射的虚拟地址空间大小,也就是该进程预先分配的虚拟内存大小,即ps出的vsz

writeable/private 表示进程所占用的私有地址空间大小,也就是该进程实际使用的内存大小

shared 表示进程和其他进程共享的内存大小

每隔2秒显示一下最后一行信息:[root@young ~]# while true; do pmap -d  1 | tail -1; sleep 2; done

mapped: 129164K    writeable/private: 23876K    shared: 0K

mapped: 129164K    writeable/private: 23876K    shared: 0K

mapped: 129164K    writeable/private: 23876K    shared: 0K

mapped: 129164K    writeable/private: 23876K    shared: 0K

mapped: 129164K    writeable/private: 23876K    shared: 0K

3.glances命令

A cross-platform curses-based monitoringtool,跨平台的监控工具,可远程监控。

常用选项:-b: 以Byte为单位显示网卡数据速率;

-d: 关闭磁盘I/O模块

-f /path/to/somewhere: 设置输出文件的位置及其格式;

-o {HTML|CSV}

-m: 禁用mount模块

-n: 禁用网络模块

-t #: 指定刷新时间间隔

-1:每个CPU的数据单独显示

交互式命令:有许多交互式命令来定义glances的显示信息,以及排序方式等;a Sort processes automatically  l Show/hide logs

c Sort processes by CPU%        b Bytes or bits for network I/O

m Sort processes by MEM%        w Delete warning logs

p Sort processes by name        x Delete warning and critical logs

i Sort processes by I/O rate    1 Global CPU or per-CPU stats

d Show/hide disk I/O stats      h Show/hide this help screen

f Show/hide file system stats   t View network I/O as combination

n Show/hide network stats       u View cumulative network I/O

s Show/hide sensors stats       q Quit (Esc and Ctrl-C also work)

y Show/hide hddtemp stats       z  Show/hide processes list

h: 显示帮助

C/S模式下运行glances命令:

服务模式:glances -s -B IPADDR

IPADDR:自己监听的本机地址

[root@young ~]# glances -s -B 192.168.1.6

Glances server is running on 192.168.1.6:61209

客户端模式:glances -c IPADDR

IPADDR: 远程服务器监听的地址

[root@CentOS ~]# glances -c 192.168.1.6

young (CentOS Linux 7.2.1511 64bit / Linux 3.10.0-327.el7.x86_64)

CPU      10.0%   Load   1-core   Mem    26.8%  active:    769M   Swap    0.0%

user:     5.3%   1 min:   0.12   total: 2.95G  inactive: 1.55G   total: 2.00G

system:   4.7%   5 min:   0.18   used:   812M  buffers:   346M   used:      0

idle:    90.0%   15 min:  0.12   free:  2.16G  cached:   1.58G   free:  2.00G

...

4.dstat命令

versatile tool for generating systemresource statistics;生成系统资源使用统计数据命令,安装包在epel源中。

命令格式:dstat [-afv] [options..] [delay [count]]

常用选项:-c:显示cpu相关信息

-C #,#,...,total:显示第几颗CPU,total总共的

-d: 显示disk相关信息

-D total,sda,sdb,...

-g, --page 显示page相关统计数据

-i:显示中断状态

-l:显示cpu 1min,5min,15min的平均负载

-m :显示memory相关统计数据

-p :显示process相关统计数据

-r, --io 显示io请求相关的统计数据

-s, --swap 显示swapped相关的统计数据

-t, --time 显示系统运行时间

-y, --sys 显示内核空间中断与上下文切换

--aio: 显示异步io统计数据

--ipc: ipc相关的信息(进程间通信)

--raw: raw socket

--tcp: tcp socket

--udp: udp socket

--socket: raw, tcp, udp

--unix: unix sock

--top-cpu:显示最占用CPU的进程

--top-bio:显示最占用block IO的进程

--top-mem: 显示最耗费内存的进程

--top-io:最占用IO的进程

--top-latency: 显示延迟最大的进程

实例:

1)cpu相关信息统计[root@CentOS ~]# dstat -c

----total-cpu-usage----

usr sys idl wai hiq siq

0   0 100   0   0   0

0   0 100   0   0   0^C

[root@CentOS ~]# dstat -C 1

-------cpu1-usage------ -dsk/total- -net/total- ---paging-- ---system--

usr sys idl wai hiq siq| read  writ| recv  send|  in   out | int   csw

0   0  99   0   0   0|  15k 5586B|   0     0 |   0     0 | 176   120

0   0 100   0   0   0|   0     0 |  60B  870B|   0     0 |  74    53

[root@CentOS ~]# dstat -C 2

-------cpu2-usage------ -dsk/total- -net/total- ---paging-- ---system--

usr sys idl wai hiq siq| read  writ| recv  send|  in   out | int   csw

0   0 100   0   0   0|  15k 5585B|   0     0 |   0     0 | 176   120

[root@CentOS ~]# dstat -C 1,2

-------cpu1-usage--------------cpu2-usage------ -dsk/total- -net/total- ---paging-- ---system--

usr sys idl wai hiq siq:usr sys idl wai hiq siq| read  writ| recv  send|  in   out | int   csw

0   0  99   0   0   0:  0   0 100   0   0   0|  15k 5584B|   0     0 |   0     0 | 176   120

0   0 100   0   0   0:  0   0 100   0   0   0|   0     0 | 120B 1110B|   0     0 |  75    52

0   0 100   0   0   0:  0   0 100   0   0   0|   0     0 | 120B  470B|   0     0 |  56    38

2)统计磁盘相关信息[root@CentOS ~]# dstat -d

-dsk/total-

read  writ

15k 5565B

0     0

[root@CentOS ~]# dstat -D /dev/sdb

----total-cpu-usage---- --dsk/sdb-- -net/total- ---paging-- ---system--

usr sys idl wai hiq siq| read  writ| recv  send|  in   out | int   csw

0   0 100   0   0   0|  70B    0 |   0     0 |   0     0 | 175   120

0   0 100   0   0   0|   0     0 | 180B  854B|   0     0 |  68    44

0   0 100   0   0   0|   0     0 | 180B  390B|   0     0 |  65    45

[root@CentOS ~]# dstat -D /dev/sda1

----total-cpu-usage---- --dsk/sda1- -net/total- ---paging-- ---system--

usr sys idl wai hiq siq| read  writ| recv  send|  in   out | int   csw

0   0 100   0   0   0| 121B    1B|   0     0 |   0     0 | 175   120

0   0 100   0   0   0|   0     0 |  60B  870B|   0     0 |  72    47

3)统计中断信息[root@CentOS ~]# dstat -i

----interrupts---

17    18    19

1     0   108

4)统计cpu负载信息[root@CentOS ~]# dstat -l

---load-avg---

1m   5m  15m

0 0.01 0.05

5)统计内存page信息[root@CentOS ~]# dstat -g

---paging--

in   out

0     0

6)统计io相关信息[root@CentOS etc]# dstat -r

--io/total-

read  writ

0.81  0.40

7)统计进程相关[root@young ~]# dstat -p

---procs---

run blk new

0.0   0 8.7

0   0 2.0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值