Linux监控基础命令

Linux资源监控

一.资源监控常用命令汇总

内存:top、free、vmstat、pmap

I/O:vmstat、sar

CPU:top、vmstat、mpstat、iostat

二.监控命令

日常检测使用top和free就足够了,如果要对系统进行日常监控可以使用zabbix或者prometheus

top
[root@lyh ~]# top
# 命令行输入top就能查看

参数详解
-b	以处理模式操作
-c	显示完整的命令行而不只是显示命令名。
-d	屏幕刷新间隔时间。
-l	忽略失效过程。
-s	保密模式。
-S	累积模式。
-u【用户名】	指定用户名。
-p【进程号】	指定进程。
-n【次数】	循环显示的次数。
-H	查看进程下面的子线程。

请添加图片描述

%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st

us:用户空间CPU占用率
sy:内核空间CPU占用率
ni :用户进程空间改变过优先级的进程CPU的占用率
id:空闲CPU占有率
wa:等待输入输出的CPU时间百分比。
hi (硬件中断请求)
si (软件中断请求)
st (分配给运行在其它虚拟机上的任务的实际 CPU时间)

KiB Mem :  3861520 total,  3548876 free,   114416 used,   198228 buff/cache

total:内存总量
free:空闲内存
used:已使用的内存
buff/cache:内核缓存使用

KiB Swap:  2097148 total,  2096884 free,      264 used.   415608 avail Mem

total: 交换分区总量
free: 空闲交换分区
used: 已使用的交换分区
avail Mem: 缓冲交换区

系统进程信息

   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND 
     1 root      20   0  191000   3892   2592 S   0.0  0.1   0:01.17 systemd                                                                                               
     2 root      20   0       0      0      0 S   0.0  0.0   0:00.00 kthreadd                                                                                              
     3 root      20   0       0      0      0 S   0.0  0.0   0:00.01 ksoftirqd/0 
     
PID :进程id
USER :进程所有者的用户名
PR :进程优先级
NI :nice值。负值表示高优先级,正值表示低优先级
VIRT :进程使用的虚拟内存总量,单位kb。VIRT=SWAP+RES
RES :进程使用的、未被换出的物理内存大小,单位kb。RES=CODE+DATA
SHR :共享内存大小,单位kb
S :进程状态。D=不可中断的睡眠状态 R=运行 S=睡眠 T=跟踪/停止 Z=僵尸进程
%CPU :上次更新到现在的CPU时间占用百分比
%MEM :进程使用的物理内存百分比
TIME+ :进程使用的CPU时间总计,单位1/100秒
COMMAND :进程名称[命令名/命令行]

top界面按下1会出现cpu的详细信息
请添加图片描述

free
[root@lyh ~]# free
              total        used        free      shared  buff/cache   available
Mem:        3861520      114176     3549116       11844      198228     3506268
Swap:       4063228           0     4063228

可选参数详解
-b	以bytes为单位显示内存使用情况。
-k	以KB为单位显示内存使用情况。
-m	以MB为单位显示内存使用情况。
-o	不显示缓冲区调节列。
-s【间隔秒数】	持续观察内存使用情况。
-t	显示内存总和列。
-V	显示版本信息。

[root@lyh ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           3771         111        3465          11         193        3424
Swap:          3967           0        3967
# 常用,以mb显示当前
Mem:表示物理内存统计。
Swap:表示硬盘上交换分区的使用情况。
total:表示物理内存总数(total=used+free)
used:表示系统分配给缓存使用的数量(这里的缓存包括buffer和cache)
free:表示未分配的物理内存总数。
shared:表示共享内存。
buffers:系统分配但未被使用的buffers数量。
cached:系统分配但未被使用的cache数量。
-/+ buffers/cache:表示物理内存的缓存统计
(-buffers/cache) 内存数: (指的第一部分Mem行中的used – buffers – cached)
(+buffers/cache) 内存数: (指的第一部分Mem行中的free + buffers + cached)
(-buffers/cache)表示真正使用的内存数, (+buffers/cache) 表示真正未使用的内存数
vmstat
[root@lyh ~]# vmstat -h
# 查看帮助命令
Usage:
 vmstat [options] [delay [count]]

Options:
 -a, --active           active/inactive memory
 -f, --forks            number of forks since boot
 -m, --slabs            slabinfo
 -n, --one-header       do not redisplay header
 -s, --stats            event counter statistics
 -d, --disk             disk statistics
 -D, --disk-sum         summarize disk statistics
 -p, --partition <dev>  partition specific statistics
 -S, --unit <char>      define display unit
 -w, --wide             wide output
 -t, --timestamp        show timestamp

 -h, --help     display this help and exit
 -V, --version  output version information and exit

For more details see vmstat(8).

[root@lyh ~]# 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 3548472   2108 196168    0    0     7     1   15   20  0  0 100  0  0
检测参数同以上命令
pmap
[root@lyh ~]# pmap -h

Usage:
 pmap [options] PID [PID ...]

Options:
 -x, --extended              show details # 显示扩展格式
 -X                          show even more details
            WARNING: format changes according to /proc/PID/smaps
 -XX                         show everything the kernel provides
 -c, --read-rc               read the default rc
 -C, --read-rc-from=<file>   read the rc from file
 -n, --create-rc             create new default rc
 -N, --create-rc-to=<file>   create new rc to file
            NOTE: pid arguments are not allowed with -n, -N
 -d, --device                show the device format # 显示设备格式
 -q, --quiet                 do not display header and footer # 不显示头尾行
 -p, --show-path             show path in the mapping
 -A, --range=<low>[,<high>]  limit results to the given range

 -h, --help     display this help and exit
 -V, --version  output version information and exit # 显示当前使用版本

For more details see pmap(1).
# 此命令博主不常用,这里只做简单介绍
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值